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
overcommit-0.33.0 lib/overcommit/hook_context/post_rewrite.rb
overcommit-0.32.0 lib/overcommit/hook_context/post_rewrite.rb
overcommit-0.32.0.rc1 lib/overcommit/hook_context/post_rewrite.rb
overcommit-0.31.0 lib/overcommit/hook_context/post_rewrite.rb
overcommit-0.30.0 lib/overcommit/hook_context/post_rewrite.rb
overcommit-0.29.1 lib/overcommit/hook_context/post_rewrite.rb
overcommit-0.29.0 lib/overcommit/hook_context/post_rewrite.rb
overcommit-0.28.0 lib/overcommit/hook_context/post_rewrite.rb
overcommit-0.27.0 lib/overcommit/hook_context/post_rewrite.rb