Sha256: 5cd05bc368251b3a3df72c5cd4521076ad76b6bf29859d122d22797003d84992

Contents?: true

Size: 1.39 KB

Versions: 29

Compression:

Stored size: 1.39 KB

Contents

module Overcommit::HookContext
  # Contains helpers for contextual information used by post-rewrite hooks.
  class PostRewrite < Base
    # Returns whether this post-rewrite was triggered by `git commit --amend`.
    #
    # @return [true,false]
    def amend?
      @args[0] == 'amend'
    end

    # Returns whether this post-rewrite was triggered by `git rebase`.
    #
    # @return [true,false]
    def rebase?
      @args[0] == 'rebase'
    end

    # Returns the list of commits rewritten by the action that triggered this
    # hook run.
    #
    # @return [Array<RewrittenCommit>]
    def rewritten_commits
      @rewritten_commits ||= input_lines.map do |line|
        RewrittenCommit.new(*line.split(' '))
      end
    end

    # Get a list of files that have been added or modified as part of a
    # rewritten commit. Renames and deletions are ignored, since there should be
    # nothing to check.
    def modified_files
      @modified_files ||= begin
        @modified_files = []

        rewritten_commits.each do |rewritten_commit|
          refs = "#{rewritten_commit.old_hash} #{rewritten_commit.new_hash}"
          @modified_files |= Overcommit::GitRepo.modified_files(refs: refs)
        end

        filter_modified_files(@modified_files)
      end
    end

    # Struct encapsulating the old and new SHA1 hashes of a rewritten commit
    RewrittenCommit = Struct.new(:old_hash, :new_hash)
  end
end

Version data entries

29 entries across 27 versions & 2 rubygems

Version Path
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/overcommit-0.46.0/lib/overcommit/hook_context/post_rewrite.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/overcommit-0.46.0/lib/overcommit/hook_context/post_rewrite.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/overcommit-0.46.0/lib/overcommit/hook_context/post_rewrite.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/overcommit-0.46.0/lib/overcommit/hook_context/post_rewrite.rb
overcommit-0.46.0 lib/overcommit/hook_context/post_rewrite.rb
overcommit-0.45.0 lib/overcommit/hook_context/post_rewrite.rb
overcommit-0.44.0 lib/overcommit/hook_context/post_rewrite.rb
overcommit-0.43.0 lib/overcommit/hook_context/post_rewrite.rb
overcommit-0.42.0 lib/overcommit/hook_context/post_rewrite.rb
overcommit-0.41.0 lib/overcommit/hook_context/post_rewrite.rb
overcommit-0.40.0 lib/overcommit/hook_context/post_rewrite.rb
overcommit-0.39.1 lib/overcommit/hook_context/post_rewrite.rb
overcommit-0.39.0 lib/overcommit/hook_context/post_rewrite.rb
overcommit-0.38.0 lib/overcommit/hook_context/post_rewrite.rb
overcommit-0.37.0 lib/overcommit/hook_context/post_rewrite.rb
overcommit-0.36.0 lib/overcommit/hook_context/post_rewrite.rb
overcommit-0.35.0 lib/overcommit/hook_context/post_rewrite.rb
overcommit-0.34.2 lib/overcommit/hook_context/post_rewrite.rb
overcommit-0.34.1 lib/overcommit/hook_context/post_rewrite.rb
overcommit-0.34.0 lib/overcommit/hook_context/post_rewrite.rb