Skip to content

Instantly share code, notes, and snippets.

@imarcelolz
Forked from bartoszmajsak/prepare-commit-msg.sh
Created February 28, 2020 12:12
Show Gist options
  • Select an option

  • Save imarcelolz/52ff09bd72f566f7f88f1fd64339f7b5 to your computer and use it in GitHub Desktop.

Select an option

Save imarcelolz/52ff09bd72f566f7f88f1fd64339f7b5 to your computer and use it in GitHub Desktop.

Revisions

  1. @bartoszmajsak bartoszmajsak revised this gist Oct 15, 2014. 1 changed file with 6 additions and 4 deletions.
    10 changes: 6 additions & 4 deletions prepare-commit-msg.sh
    Original file line number Diff line number Diff line change
    @@ -2,14 +2,16 @@

    # This way you can customize which branches should be skipped when
    # prepending commit message.
    DEFAULT_BRANCHES_TO_SKIP=(master develop test)
    if [ -z "$BRANCHES_TO_SKIP" ]; then
    BRANCHES_TO_SKIP=$DEFAULT_BRANCHES_TO_SKIP
    BRANCHES_TO_SKIP=(master develop test)
    fi

    BRANCH_NAME=$(git symbolic-ref --short HEAD)
    BRANCH_NAME="${BRANCH_NAME##*/}"

    if [ -n "$BRANCH_NAME" ] && ! [[ ${BRANCHES_TO_SKIP[*]} =~ $BRANCH_NAME ]]; then
    BRANCH_NAME=${BRANCH_NAME##*/}
    BRANCH_EXCLUDED=$(printf "%s\n" "${BRANCHES_TO_SKIP[@]}" | grep -c "^$BRANCH_NAME$")
    BRANCH_IN_COMMIT=$(grep -c "\[$BRANCH_NAME\]" $1)

    if [ -n "$BRANCH_NAME" ] && ! [[ $BRANCH_EXCLUDED -eq 1 ]] && ! [[ $BRANCH_IN_COMMIT -ge 1 ]]; then
    sed -i.bak -e "1s/^/[$BRANCH_NAME] /" $1
    fi
  2. @bartoszmajsak bartoszmajsak revised this gist Sep 22, 2014. 1 changed file with 5 additions and 4 deletions.
    9 changes: 5 additions & 4 deletions prepare-commit-msg.sh
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,15 @@
    #!/bin/sh
    #!/bin/bash

    # This way you can customize which branches should be skipped when
    # prepending commit message.
    DEFAULT_BRANCHES_TO_SKIP=(master develop test)
    if [ -z "$BRANCHES_TO_SKIP" ]; then
    BRANCHES_TO_SKIP=("master" "develop" "test")
    fi
    BRANCHES_TO_SKIP=$DEFAULT_BRANCHES_TO_SKIP
    fi

    BRANCH_NAME=$(git symbolic-ref --short HEAD)

    if [ -n "$BRANCH_NAME" ] && ! [[ ${BRANCHES_TO_SKIP[*]} =~ $BRANCH_NAME ]]; then
    BRANCH_NAME=${BRANCH_NAME##*/}
    sed -i.bak -e "1s/^/[$BRANCH_NAME] /" $1
    fi
    fi
  3. @bartoszmajsak bartoszmajsak renamed this gist Sep 19, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. @bartoszmajsak bartoszmajsak renamed this gist Sep 19, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion prepare-commit-msg.sh → prepare-commit-msg
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    # This way you can customize which branches should be skipped when
    # prepending commit message.
    if [ -z "$BRANCHES_TO_SKIP" ]; then
    BRANCHES_TO_SKIP=("master" "develop" "test")
    BRANCHES_TO_SKIP=("master" "develop" "test")
    fi

    BRANCH_NAME=$(git symbolic-ref --short HEAD)
  5. @bartoszmajsak bartoszmajsak revised this gist Sep 19, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion prepare-commit-msg.sh
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    #!/bin/sh

    # This way you can customize which branches should be skipped when
    # preperending commit message.
    # prepending commit message.
    if [ -z "$BRANCHES_TO_SKIP" ]; then
    BRANCHES_TO_SKIP=("master" "develop" "test")
    fi
  6. @bartoszmajsak bartoszmajsak revised this gist Sep 19, 2014. 1 changed file with 9 additions and 2 deletions.
    11 changes: 9 additions & 2 deletions prepare-commit-msg.sh
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,14 @@
    #!/bin/sh

    BRANCH_NAME=$(git symbolic-ref --short HEAD)
    if [ -n "$BRANCH_NAME" ] && [ "$BRANCH_NAME" != "master" ]; then
    # This way you can customize which branches should be skipped when
    # preperending commit message.
    if [ -z "$BRANCHES_TO_SKIP" ]; then
    BRANCHES_TO_SKIP=("master" "develop" "test")
    fi

    BRANCH_NAME=$(git symbolic-ref --short HEAD)

    if [ -n "$BRANCH_NAME" ] && ! [[ ${BRANCHES_TO_SKIP[*]} =~ $BRANCH_NAME ]]; then
    BRANCH_NAME=${BRANCH_NAME##*/}
    sed -i.bak -e "1s/^/[$BRANCH_NAME] /" $1
    fi
  7. @bartoszmajsak bartoszmajsak revised this gist Sep 18, 2014. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions prepare-commit-msg.sh
    Original file line number Diff line number Diff line change
    @@ -2,5 +2,6 @@

    BRANCH_NAME=$(git symbolic-ref --short HEAD)
    if [ -n "$BRANCH_NAME" ] && [ "$BRANCH_NAME" != "master" ]; then
    sed -i.bak -e "1s/^/[$BRANCH_NAME] /" $1
    fi
    BRANCH_NAME=${BRANCH_NAME##*/}
    sed -i.bak -e "1s/^/[$BRANCH_NAME] /" $1
    fi
  8. @bartoszmajsak bartoszmajsak revised this gist Nov 25, 2013. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions prepare-commit-msg.sh
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #!/bin/sh

    BRANCH_NAME=$(git branch 2>/dev/null | grep -e ^* | tr -d ' *')
    BRANCH_NAME=$(git symbolic-ref --short HEAD)
    if [ -n "$BRANCH_NAME" ] && [ "$BRANCH_NAME" != "master" ]; then
    echo "[$BRANCH_NAME] $(cat $1)" > $1
    sed -i.bak -e "1s/^/[$BRANCH_NAME] /" $1
    fi
  9. @bartoszmajsak bartoszmajsak renamed this gist Nov 7, 2012. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  10. @bartoszmajsak bartoszmajsak revised this gist Dec 13, 2011. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions prepare-commit-msg
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #!/bin/sh

    BRANCH_NAME=$(git branch 2>/dev/null | grep -e ^* | tr -d ' *')
    if [ -n "$BRANCH_NAME" ]; then
    if [ -n "$BRANCH_NAME" ] && [ "$BRANCH_NAME" != "master" ]; then
    echo "[$BRANCH_NAME] $(cat $1)" > $1
    fi
    fi
  11. @bartoszmajsak bartoszmajsak created this gist Nov 26, 2011.
    6 changes: 6 additions & 0 deletions prepare-commit-msg
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    #!/bin/sh

    BRANCH_NAME=$(git branch 2>/dev/null | grep -e ^* | tr -d ' *')
    if [ -n "$BRANCH_NAME" ]; then
    echo "[$BRANCH_NAME] $(cat $1)" > $1
    fi