Skip to content

Instantly share code, notes, and snippets.

@dulyanov
Last active October 2, 2015 04:37
Show Gist options
  • Select an option

  • Save dulyanov/2173284 to your computer and use it in GitHub Desktop.

Select an option

Save dulyanov/2173284 to your computer and use it in GitHub Desktop.

Revisions

  1. dulyanov revised this gist Apr 24, 2013. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions prepare-commit-msg
    Original file line number Diff line number Diff line change
    @@ -6,8 +6,10 @@
    #
    # Based on git://gist.github.com/750755.git
    #
    # Place code into .git/hooks/prepare-commit-msg
    # chmod 755 .git/hooks/prepare-commit-msg
    # Place code into .git/hooks/prepare-commit-msg and give it executable permissions
    # cd .git/hooks
    # wget https://gist.github.com/dulyanov/2173284/raw/prepare-commit-msg
    # chmod 755 prepare-commit-msg

    branchname = `git branch --no-color 2> /dev/null`[/^\* (.+)/, 1].strip

  2. dulyanov revised this gist Apr 24, 2013. 1 changed file with 4 additions and 5 deletions.
    9 changes: 4 additions & 5 deletions prepare-commit-msg
    Original file line number Diff line number Diff line change
    @@ -6,10 +6,8 @@
    #
    # Based on git://gist.github.com/750755.git
    #
    # Place code into .git/hooks/prepare-commit-msg and give it executable permissions
    # cd .git/hooks
    # wget https://gist.github.com/dulyanov/2173284/raw/prepare-commit-msg
    # chmod 755 prepare-commit-msg
    # Place code into .git/hooks/prepare-commit-msg
    # chmod 755 .git/hooks/prepare-commit-msg

    branchname = `git branch --no-color 2> /dev/null`[/^\* (.+)/, 1].strip

    @@ -20,7 +18,8 @@ prepend = "[#{branchname}] "

    # When task branch name is numeric and not a merge, use it for task number
    if branchname =~ /\d+/ && (message =~ /Merge branch.*into #{branchname}/).nil?
    prepend += "(Task #{branchname}) "
    task_number = branchname.gsub(/[^\d]/, '')
    prepend += "(Task #{task_number}) "
    end

    # When message is blank and starts with comments, add a line break
  3. dulyanov revised this gist Apr 21, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion prepare-commit-msg
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@
    #
    # Place code into .git/hooks/prepare-commit-msg and give it executable permissions
    # cd .git/hooks
    # wget https://gist.github.com/dulyanov/2173284/raw/b0e9cfacc3773e6d5181ff11ea4d1c255b3952d4/prepare-commit-msg
    # wget https://gist.github.com/dulyanov/2173284/raw/prepare-commit-msg
    # chmod 755 prepare-commit-msg

    branchname = `git branch --no-color 2> /dev/null`[/^\* (.+)/, 1].strip
  4. dulyanov revised this gist Apr 21, 2013. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions prepare-commit-msg
    Original file line number Diff line number Diff line change
    @@ -6,8 +6,10 @@
    #
    # Based on git://gist.github.com/750755.git
    #
    # Place code into .git/hooks/prepare-commit-msg
    # chmod 755 .git/hooks/prepare-commit-msg
    # Place code into .git/hooks/prepare-commit-msg and give it executable permissions
    # cd .git/hooks
    # wget https://gist.github.com/dulyanov/2173284/raw/b0e9cfacc3773e6d5181ff11ea4d1c255b3952d4/prepare-commit-msg
    # chmod 755 prepare-commit-msg

    branchname = `git branch --no-color 2> /dev/null`[/^\* (.+)/, 1].strip

  5. dulyanov created this gist Mar 23, 2012.
    33 changes: 33 additions & 0 deletions prepare-commit-msg
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    #!/usr/bin/env ruby
    #
    # Git commit-msg hook. Prepend branch name to commit tasks.
    # If your branch name is in the numeric form "12345", also prepend "(Task 123)" to commit messages,
    # unless #notask is included in the message (#notask will be stripped).
    #
    # Based on git://gist.github.com/750755.git
    #
    # Place code into .git/hooks/prepare-commit-msg
    # chmod 755 .git/hooks/prepare-commit-msg

    branchname = `git branch --no-color 2> /dev/null`[/^\* (.+)/, 1].strip

    message_file = ARGV[0]
    message = File.read(message_file).strip

    prepend = "[#{branchname}] "

    # When task branch name is numeric and not a merge, use it for task number
    if branchname =~ /\d+/ && (message =~ /Merge branch.*into #{branchname}/).nil?
    prepend += "(Task #{branchname}) "
    end

    # When message is blank and starts with comments, add a line break
    prepend += "\n" if message.chars.first == "#"

    if message.include?("#notask")
    message.sub!(/^\s*#notask\s*|\s*#notask/, '')
    else
    message = prepend + message
    end

    File.open(message_file, 'w') {|f| f.write message }