Sha256: 531f074362525281d4f08572a82d94b881e7a1ae2d63fbae47a22a7efa578d09

Contents?: true

Size: 1.98 KB

Versions: 14

Compression:

Stored size: 1.98 KB

Contents

# frozen_string_literal: true

require 'avm/scms/commit'
require 'eac_ruby_utils/core_ext'

module Avm
  module Git
    module Scms
      class Git < ::Avm::Scms::Base
        class Commit < ::Avm::Scms::Commit
          require_sub __FILE__, include_modules: true
          common_constructor :git_scm, :git_commit do
            git_commit.assert_argument(::EacGit::Local::Commit, 'git_commit')
          end
          delegate :git_repo, to: :git_scm
          delegate :id, to: :git_commit

          FIXUP_SUBJECT_PATTERN = /\Afixup!/.freeze

          # @return [Array<Pathname>]
          def changed_files
            git_commit.changed_files.map { |cf| cf.path.to_pathname }
          end

          # @return [Boolean]
          def fixup?
            FIXUP_SUBJECT_PATTERN.match?(git_commit.subject)
          end

          # @param other [Avm::Git::Scms::Git::Commit]
          # @return [Avm::Git::Scms::Git::Commit]
          def merge_with(other)
            validate_clean_and_head
            raise 'Implemented for only if other is parent' unless
            other.git_commit == git_commit.parent

            git_scm.reset_and_commit(other.git_commit.parent, other.git_commit.raw_body)
          end

          def reword(new_message)
            validate_clean_and_head

            git_repo.command('commit', '--amend', '-m', new_message).execute!
            self.class.new(git_scm, git_repo.head)
          end

          # @param path [Pathname]
          # @return [TrueClass,FalseClass]
          def scm_file?(path)
            %w[.gitrepo .gitmodules].any? { |file| file.include?(path.basename.to_path) }
          end

          # @return [String]
          delegate :subject, to: :git_commit

          private

          def validate_clean_and_head
            raise 'Implemented for only if repository is no dirty' if git_repo.dirty?
            raise 'Implemented for only if self is HEAD' unless
            git_commit == git_repo.head
          end
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
avm-git-0.18.0 lib/avm/git/scms/git/commit.rb
eac_tools-0.94.0 sub/avm-git/lib/avm/git/scms/git/commit.rb
avm-git-0.17.0 lib/avm/git/scms/git/commit.rb
eac_tools-0.86.5 sub/avm-git/lib/avm/git/scms/git/commit.rb
avm-git-0.16.0 lib/avm/git/scms/git/commit.rb
eac_tools-0.86.4 sub/avm-git/lib/avm/git/scms/git/commit.rb
eac_tools-0.86.3 sub/avm-git/lib/avm/git/scms/git/commit.rb
avm-git-0.15.0 lib/avm/git/scms/git/commit.rb
eac_tools-0.86.2 sub/avm-git/lib/avm/git/scms/git/commit.rb
eac_tools-0.84.0 sub/avm-git/lib/avm/git/scms/git/commit.rb
eac_tools-0.83.0 sub/avm-git/lib/avm/git/scms/git/commit.rb
eac_tools-0.82.0 sub/avm-git/lib/avm/git/scms/git/commit.rb
avm-git-0.14.0 lib/avm/git/scms/git/commit.rb
eac_tools-0.81.0 sub/avm-git/lib/avm/git/scms/git/commit.rb