티스토리 뷰

공부

[git] prepare-commit-msg

승가비 2022. 6. 6. 05:31
728x90
#!/bin/bash

if [ -z "${SKIP_BRANCH}" ]; then
  SKIP_BRANCH=(master develop release hotfix)
fi

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


JIRA=`echo ${NAME} | egrep -o '.+-[0-9]+_' | egrep -o '.+-[0-9]+'`
ISSUE=`echo ${NAME} | egrep -o '#[0-9]+_' | egrep -o '#[0-9]+'`

EXCLUDED=$(printf "%s\n" "${SKIP_BRANCH[@]}" | grep -c "^${NAME}$")

PREFIX=""
if [[ -n ${JIRA} ]]; then
  PREFIX="[${JIRA}] "
fi
if [[ -n ${ISSUE} ]]; then
  PREFIX="${PREFIX}(${ISSUE}) "
fi

PREFIX_ESCAPE=`echo ${PREFIX} | sed -e 's/\[/\\\\[/g' | sed -e 's/\]/\\\\]/g'`
DONE=$(grep -c "${PREFIX_ESCAPE}" $1)

if ! [[ ${EXCLUDED} -eq 1 ]] && ! [[ ${DONE} -ge 1 ]]; then
  sed -i.bak -e "1s/^/${PREFIX}/" $1
fi

start

  • repository
cp git/hooks/prepare-commit-msg .git/hooks/prepare-commit-msg
chmod a+x .git/hooks/prepare-commit-msg
  • global
mkdir -p ~/.git-templates/hooks
git config --global init.templatedir '~/.git-templates'
cp git/hooks/prepare-commit-msg ~/.git-templates/hooks/prepare-commit-msg
chmod a+x ~/.git-templates/hooks/prepare-commit-msg

# each repository
rm .git/hooks/prepare-commit-msg
git init

example

branch: feature/DT-1252_#3_prepare-commit-msg
commit: [DT-1252] (#3) feat: add prepare-commit-msg

branch: feature/DT-1252_prepare-commit-msg
commit: [DT-1252] feat: add prepare-commit-msg

branch: feature/#3_prepare-commit-msg
commit: (#3) feat: add prepare-commit-msg

https://coderwall.com/p/jp7d5q/create-a-global-git-commit-hook

 

Create a global git commit hook (Example)

A protip by venables about git.

coderwall.com

https://sujin-park.github.io/web/git-prepare-commit-msg/

 

[Git] Git hooks를 이용하여 commit message 에 특정 문자 넣기

Git Hooks 란 Git은 특정 이벤트가 발생했을 때 특정 스크립트를 실행할 수 있도록 Hook 이라는 기능을 지원한다. 프로젝트에 커밋을 하거나 푸시하기 전에 린트 또는 테스트를 실행할 수 있고, commit

sujin-park.github.io

https://medium.com/prnd/github-%EC%BB%A4%EB%B0%8B-%EB%A9%94%EC%84%B8%EC%A7%80%EC%97%90-jira-%EC%9D%B4%EC%8A%88%EB%B2%88%ED%98%B8-%EC%9E%90%EB%8F%99%EC%9C%BC%EB%A1%9C-%EB%84%A3%EC%96%B4%EC%A3%BC%EA%B8%B0-779048784037

 

GitHub 커밋 메세지에 JIRA 이슈번호 자동으로 넣어주기

항상 앞에 이슈번호를 넣어주어야 하는 귀찮음을 자동으로 넣어주도록 처리하는 방법에 대해 공유합니다.

medium.com

 

728x90

'공부' 카테고리의 다른 글

[JavaScript] const result = await Promise.all([].map(i => async))  (0) 2022.06.06
[git] git commit --signoff  (0) 2022.06.06
[Gradle] getting started  (0) 2022.06.06
[Spring] Redis multiple  (0) 2022.06.06
[Postman] Environments Variables  (0) 2022.06.06
댓글