Skip to content

Instantly share code, notes, and snippets.

@cgarnier
Forked from airblade/prepare-commit-msg
Last active June 5, 2017 05:36
Show Gist options
  • Select an option

  • Save cgarnier/7847451c0873987e63c31365cfa05a79 to your computer and use it in GitHub Desktop.

Select an option

Save cgarnier/7847451c0873987e63c31365cfa05a79 to your computer and use it in GitHub Desktop.

Revisions

  1. cgarnier revised this gist Jul 27, 2016. 1 changed file with 7 additions and 4 deletions.
    11 changes: 7 additions & 4 deletions prepare-commit-msg
    Original file line number Diff line number Diff line change
    @@ -1,18 +1,21 @@
    #!/bin/bash

    # Adds reference to Jira issue if available in branch name.
    # Adds reference to GitHub issue if available in branch name.
    # The issue number should be at the end of the branch name, following
    # a hyphen.

    # Only proceed if no second parameter is given to the script.
    if [ x = x${2} ]; then
    branch=$(git symbolic-ref --short HEAD)
    if [[ $branch =~ ^[^/]+/([A-Z]+\-[0-9]+) ]]; then
    issue_number=${BASH_REMATCH[1]}
    if [[ $branch =~ ^([^/]+)/([A-Z]+\-[0-9]+) ]]; then
    issue_number=${BASH_REMATCH[2]}
    issue_type=${BASH_REMATCH[1]}
    # sed on osx doesn't treat \n in replacement pattern as a new line.
    # If it did we could do this:
    #
    # sed -i.bak -e "1s/^/\n\nSee #$issue_number./" "$1"
    #
    # Instead we have do lots of weird quoting.
    sed -i.bak -e '1s/^/\'$'\n'"\\"$'\n'"$issue_number/" "$1"
    sed -i.bak -e '1s/^/\'$'\n'"\\"$'\n'"$issue_type\n""$issue_number/" "$1"
    fi
    fi
  2. cgarnier revised this gist Jul 27, 2016. 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
    @@ -13,6 +13,6 @@ if [ x = x${2} ]; then
    # sed -i.bak -e "1s/^/\n\nSee #$issue_number./" "$1"
    #
    # Instead we have do lots of weird quoting.
    sed -i.bak -e '1s/^/\'$'\n'"\\"$'\n'"$issue_number./" "$1"
    sed -i.bak -e '1s/^/\'$'\n'"\\"$'\n'"$issue_number/" "$1"
    fi
    fi
  3. cgarnier revised this gist Jul 27, 2016. 1 changed file with 3 additions and 5 deletions.
    8 changes: 3 additions & 5 deletions prepare-commit-msg
    Original file line number Diff line number Diff line change
    @@ -1,20 +1,18 @@
    #!/bin/bash

    # Adds reference to GitHub issue if available in branch name.
    # The issue number should be at the end of the branch name, following
    # a hyphen.
    # Adds reference to Jira issue if available in branch name.

    # Only proceed if no second parameter is given to the script.
    if [ x = x${2} ]; then
    branch=$(git symbolic-ref --short HEAD)
    if [[ $branch =~ .*-([0-9]+)$ ]]; then
    if [[ $branch =~ ^[^/]+/([A-Z]+\-[0-9]+) ]]; then
    issue_number=${BASH_REMATCH[1]}
    # sed on osx doesn't treat \n in replacement pattern as a new line.
    # If it did we could do this:
    #
    # sed -i.bak -e "1s/^/\n\nSee #$issue_number./" "$1"
    #
    # Instead we have do lots of weird quoting.
    sed -i.bak -e '1s/^/\'$'\n'"\\"$'\n'"See #$issue_number./" "$1"
    sed -i.bak -e '1s/^/\'$'\n'"\\"$'\n'"$issue_number./" "$1"
    fi
    fi
  4. @airblade airblade created this gist Nov 3, 2014.
    20 changes: 20 additions & 0 deletions prepare-commit-msg
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    #!/bin/bash

    # Adds reference to GitHub issue if available in branch name.
    # The issue number should be at the end of the branch name, following
    # a hyphen.

    # Only proceed if no second parameter is given to the script.
    if [ x = x${2} ]; then
    branch=$(git symbolic-ref --short HEAD)
    if [[ $branch =~ .*-([0-9]+)$ ]]; then
    issue_number=${BASH_REMATCH[1]}
    # sed on osx doesn't treat \n in replacement pattern as a new line.
    # If it did we could do this:
    #
    # sed -i.bak -e "1s/^/\n\nSee #$issue_number./" "$1"
    #
    # Instead we have do lots of weird quoting.
    sed -i.bak -e '1s/^/\'$'\n'"\\"$'\n'"See #$issue_number./" "$1"
    fi
    fi