Append ticket number using git commit hooks?

前端 未结 6 1617
[愿得一人]
[愿得一人] 2020-12-24 02:21

So my branch is named after bugtracker ticket number, something like \"issue-1234\", and we have a convention to always write down ticket number in commit message. I\'m wond

6条回答
  •  温柔的废话
    2020-12-24 03:12

    This way you can add branch name to the start of commit message. It's prepare-commit-msg hook. Work both for "git commit -m" and "git commit" commands. The option is file .git/hooks/pre-commit.skip which contains a list of branches you don't want to auto-prepend.

    BRANCH="$(git rev-parse --abbrev-ref HEAD)"
    FILE_CONTENT="$(cat $1)"
    skip_list=`git rev-parse --git-dir`"/hooks/pre-commit.skip"
    if grep -E "^$BRANCH$" $skip_list; then
      exit
    fi
    if [ $2 = "message" ]; then
      echo $BRANCH: $FILE_CONTENT > $1
    else
      echo $BRANCH: > $1
      echo $FILE_CONTENT >> $1
    fi
    

提交回复
热议问题