Sha256: e0b8661a6eb5997b6edeb070a7a2d7b3353936ab7a0d967491b4acdb906f4014

Contents?: true

Size: 1.88 KB

Versions: 32

Compression:

Stored size: 1.88 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
        module Commits
          # @return [Avm::Git::Scms::Git::Commit,nil]
          def commit(source)
            if source.is_a?(::Avm::Git::Scms::Git::Commit)
              return source if source.git_repo == git_repo

              raise 'Not same Git repository'
            end
            git_repo.commitize(source).if_present do |v|
              ::Avm::Git::Scms::Git::Commit.new(self, v)
            end
          end

          # @param commit_info [Avm::Scms::CommitInfo]
          # @return [Avm::Git::Scms::Git::Commit,nil]
          def commit_dirty(commit_info = nil)
            return nil unless git_repo.dirty?

            commit_info = ::Avm::Scms::CommitInfo.assert(commit_info)
            commit_info = commit_info.message(COMMIT_DIRTY_DEFAULT_MESSAGE) if
              commit_info.message.blank?

            git_repo.command('add', '.').execute!
            run_commit(commit_info)
            head_commit
          end

          # @param commit_info [Avm::Scms::CommitInfo]
          # @return [Avm::Git::Scms::Git::Commit,nil]
          def commit_if_change(commit_info = nil)
            tracker = ::Avm::Git::Scms::Git::ChangeTracker.new(self, commit_info)
            tracker.start
            yield
            tracker.stop
          end

          # @return [Avm::Git::Scms::Git::Commit]
          def head_commit
            commit(git_repo.head)
          end

          # @param commit_info [Avm::Scms::CommitInfo]
          # @return [Avm::Git::Scms::Git::Commit]
          def reset_and_commit(commit_to_reset, commit_info)
            git_repo.command('reset', '--soft', commit(commit_to_reset).git_commit.id).execute!
            commit_dirty(commit_info)
          end
        end
      end
    end
  end
end

Version data entries

32 entries across 32 versions & 2 rubygems

Version Path
eac_tools-0.67.0 sub/avm-git/lib/avm/git/scms/git/commits.rb
eac_tools-0.66.0 sub/avm-git/lib/avm/git/scms/git/commits.rb
eac_tools-0.65.1 sub/avm-git/lib/avm/git/scms/git/commits.rb
eac_tools-0.65.0 sub/avm-git/lib/avm/git/scms/git/commits.rb
eac_tools-0.64.0 sub/avm-git/lib/avm/git/scms/git/commits.rb
eac_tools-0.63.0 sub/avm-git/lib/avm/git/scms/git/commits.rb
eac_tools-0.62.1 sub/avm-git/lib/avm/git/scms/git/commits.rb
eac_tools-0.62.0 sub/avm-git/lib/avm/git/scms/git/commits.rb
avm-git-0.13.2 lib/avm/git/scms/git/commits.rb
eac_tools-0.61.1 sub/avm-git/lib/avm/git/scms/git/commits.rb
eac_tools-0.61.0 sub/avm-git/lib/avm/git/scms/git/commits.rb
eac_tools-0.60.3 sub/avm-git/lib/avm/git/scms/git/commits.rb
eac_tools-0.60.2 sub/avm-git/lib/avm/git/scms/git/commits.rb
eac_tools-0.60.1 sub/avm-git/lib/avm/git/scms/git/commits.rb
eac_tools-0.60.0 sub/avm-git/lib/avm/git/scms/git/commits.rb
eac_tools-0.59.0 sub/avm-git/lib/avm/git/scms/git/commits.rb
eac_tools-0.58.0 sub/avm-git/lib/avm/git/scms/git/commits.rb
eac_tools-0.57.0 sub/avm-git/lib/avm/git/scms/git/commits.rb
eac_tools-0.56.1 sub/avm-git/lib/avm/git/scms/git/commits.rb
eac_tools-0.56.0 sub/avm-git/lib/avm/git/scms/git/commits.rb