Sha256: 517a01a78d6007e2153cc54a3659cecce859a2a51f42a39d86aec3a5b515b58c

Contents?: true

Size: 1.42 KB

Versions: 28

Compression:

Stored size: 1.42 KB

Contents

# frozen_string_literal: true

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

28 entries across 28 versions & 2 rubygems

Version Path
overcommit-0.64.1 lib/overcommit/hook_context/post_rewrite.rb
overcommit-0.64.0 lib/overcommit/hook_context/post_rewrite.rb
overcommit-0.63.0 lib/overcommit/hook_context/post_rewrite.rb
overcommit-0.62.0 lib/overcommit/hook_context/post_rewrite.rb
overcommit-0.61.0 lib/overcommit/hook_context/post_rewrite.rb
overcommit-0.60.0 lib/overcommit/hook_context/post_rewrite.rb
overcommit-0.59.1 lib/overcommit/hook_context/post_rewrite.rb
overcommit-0.59.0 lib/overcommit/hook_context/post_rewrite.rb
overcommit-jeygeethanmedia-0.58.0 lib/overcommit/hook_context/post_rewrite.rb
overcommit-0.58.0 lib/overcommit/hook_context/post_rewrite.rb
overcommit-0.57.0 lib/overcommit/hook_context/post_rewrite.rb
overcommit-0.56.0 lib/overcommit/hook_context/post_rewrite.rb
overcommit-0.55.0 lib/overcommit/hook_context/post_rewrite.rb
overcommit-0.54.1 lib/overcommit/hook_context/post_rewrite.rb
overcommit-0.54.0 lib/overcommit/hook_context/post_rewrite.rb
overcommit-jeygeethanmedia-0.53.1.2 lib/overcommit/hook_context/post_rewrite.rb
overcommit-jeygeethanmedia-0.53.1.1 lib/overcommit/hook_context/post_rewrite.rb
overcommit-jeygeethanmedia-0.53.1 lib/overcommit/hook_context/post_rewrite.rb
overcommit-0.53.0 lib/overcommit/hook_context/post_rewrite.rb
overcommit-0.52.1 lib/overcommit/hook_context/post_rewrite.rb