0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ブランチ名からissue 番号を取得してきてgit commitのメッセージに含める

0
Posted at

githubのissueに関連付けてブランチを切る時、feature/#issue番号_何か文字列 という感じのブランチ名にするようなことがよくあると思う。このブランチ名からコミット時にissue番号をコミットメッセージに含めるのを自動化すると、もしかしたらちょっとだけ便利かもしれない。
🔽

function icommit() {
        if [ -z "$1" ] ; then
                echo "commit commentを入力してください。"
                return 1
        fi

        branchName=`git branch | grep \*`
        branchName=${branchName#*/#}
        issueNumber=`echo $branchName | sed -e "s/[_-].*//g"`

        # 数字判定
        expr $issueNumber + 1 > /dev/null 2>&1
        retNumber=$?
        if [ $retNumber -lt 2 ] ; then
                echo "issue番号:$issueNumber"
                commitCommand="git commit -m \"#${issueNumber} $1\""
        else
                echo "ブランチにissue番号がないので普通にコミットします"
                commitCommand="git commit -m \"$1\""
        fi

        echo -e "実行コマンド:\n"
        echo $commitCommand
        echo -e "\n  実行する場合は y、実行をキャンセルする場合は n と入力して下さい."
        read input
        if [ -z $input ] ; then

                echo "  y または n を入力して下さい."

        elif [ $input = 'yes' ] || [ $input = 'YES' ] || [ $input = 'y' ] ; then

                echo "  コミットを実行します."
                eval ${commitCommand}

        elif [ $input = 'no' ] || [ $input = 'NO' ] || [ $input = 'n' ] ; then

                echo "  処理をキャンセルしました."
                return 1

        else

                echo "  y または n を入力して下さい."

        fi


        return 0
}
使い方
# feature/#9999_hogehoge ブランチにコミットする場合
~/source/testpj(feature/#9999_hogehoge +$)$ icommit "コミットテスト"
issue番号:9999
実行コマンド:

git commit -m "#9999 コミットテスト"

  実行する場合は y、実行をキャンセルする場合は n と入力して下さい.
y
  コミットを実行します.
[feature/#9999_hogehoge 4c4f0d3b] #9999 コミットテスト
 x file changed, y insertions(+)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?