Sha256: 87f9f38d9f081a543e325259d5a398f5ef691faaa9f560838a8b6e63600b72a5

Contents?: true

Size: 1.07 KB

Versions: 8

Compression:

Stored size: 1.07 KB

Contents

module Overcommit::HookContext
  # Contains helpers related to contextual information used by commit-msg hooks.
  class CommitMsg < Base
    def empty_message?
      commit_message.strip.empty?
    end

    # User commit message stripped of comments and diff (from verbose output).
    def commit_message
      commit_message_lines.join
    end

    # Updates the commit message to the specified text.
    def update_commit_message(message)
      ::File.open(commit_message_file, 'w') do |file|
        file.write(message)
      end
    end

    def commit_message_lines
      raw_commit_message_lines.
        take_while { |line| !line.start_with?('diff --git') }.
        reject     { |line| line.start_with?(comment_character) }
    end

    def comment_character
      @comment_character ||= Overcommit::GitConfig.comment_character
    end

    def commit_message_file
      @args[0]
    end

    def post_fail_message
      "Failed commit message:\n" + commit_message_lines.join
    end

    private

    def raw_commit_message_lines
      ::IO.readlines(commit_message_file)
    end
  end
end

Version data entries

8 entries across 6 versions & 2 rubygems

Version Path
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/commit_msg.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/overcommit-0.46.0/lib/overcommit/hook_context/commit_msg.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/commit_msg.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/overcommit-0.46.0/lib/overcommit/hook_context/commit_msg.rb
overcommit-0.46.0 lib/overcommit/hook_context/commit_msg.rb
overcommit-0.45.0 lib/overcommit/hook_context/commit_msg.rb
overcommit-0.44.0 lib/overcommit/hook_context/commit_msg.rb
overcommit-0.43.0 lib/overcommit/hook_context/commit_msg.rb