LoginSignup
1
6

More than 5 years have passed since last update.

マージ漏れをチェックする

Last updated at Posted at 2017-09-02

環境

Mac:10.12.5
bash:3.2.57

はじめに

やりたいこと

アプリの申請前に開発チームでデバッグを行うのですが、それを定時までに終わらせたいと考えています。
(ジョインして5ヶ月経ちますが、未だ1度も定時内には終わっていないという...)

大きなタイムロスの原因の1つがマージ漏れがあることです。
デバッグ→バグ報告→調査→マージ→再ビルド、をしている間に2時間ほどロスしています。
これを事前に防ぐために、developブランチにマージされたブランチの一覧を共有して再確認してもらいたいと考えました。

ブランチの運用方法について

今のチームでは以下のようにブランチ運用をしています。
bugfix,featureなど:修正や施策のブランチです。開発が終わったらdevelopブランチにマージします。このマージ漏れを防ぎたいです。
develop_1_0_0:バージョン毎の開発中ブランチです。デバッグが終わったらreleaseブランチにマージします。
release:リリースされるブランチです。このブランチで申請用のアプリをビルドします。

先にまとめ

# 引数チェック
if [ "$1" == "" ]; then
        echo "対象のブランチを指定してください\n例)sh checkMergedBranch.sh develop_1_0_0"
        exit 1
fi
TARGET_BRANCH="$1"

# 最新にする
git fetch

# releaseブランチ以降からターゲットのブランチまでのマージコミット一覧を取得する
LOG=$(git log --merges --oneline origin/release.."origin/$TARGET_BRANCH")

# 不要なコミット除外する コンフリクト解消コミット
LOG=$(echo "$LOG" | grep -v "$(git config remote.origin.url)")

# 不要な文字列を削除する マージ周りのメッセージ
LOG=$(echo "$LOG" | sed "s/Merge branch '//" | sed "s/' into $TARGET_BRANCH//" | sed "s/Merge remote-tracking branch '//" )

# フィールド数が2のものだけ出力する
# into ~~ が残っているもの(対象ブランチ以外のマージコミット)を弾くため
echo "$LOG" | awk '{if(NF==2){print}}'

# リポジトリがのディレクトリへ移動
# sh ~/checkMergedBranch.sh develop_1_0_10 を実行した結果

2d1f0e02fd3 bugfix/ブランチ名
6d4b0e73a9b origin/ブランチ名
17ee36d00f1 origin/ブランチ名
d9e60412e8b origin/ブランチ名
980eaa8aa23 bugfix/ブランチ名
b8d79f04ada featureブランチ名
1401c6362ef bugfix/ブランチ名
1996bea9515 結果画面回収マージ
60f3975eca2 refactor/ブランチ名
fd343cc51ae feature/ブランチ名
8c9430281d2 feature/ブランチ名
2348ac1353f feature/ブランチ名
9f26ce1fbd5 bugfix/ブランチ名

※ブランチ名は適当に伏せています。

解説

マージコミットを洗い出す

# releaseブランチ以降からターゲットのブランチまでのマージコミット一覧を取得する
LOG=$(git log --merges --oneline origin/release.."origin/$TARGET_BRANCH")

基本的にはこの部分で全て出せるのですが以下のように不要なものもかなり出ます。
施策ブランチへのマージコミットやdevelop内でのコンフリクト解消マージなどが含まれるため、欲しい13コミットに対して24コミットも表示され、かつパッと見でブランチ名がどこにあるのか分かりません。

2d1f0e02fd3 Merge branch 'ブランチ名' into develop_1_0_10
c5605e0e2e8 Merge branch 'develop_1_0_10' of リポジトリurl into develop_1_0_10
6d4b0e73a9b Merge remote-tracking branch 'ブランチ名' into develop_1_0_10
17ee36d00f1 Merge remote-tracking branch 'ブランチ名' into develop_1_0_10
d9e60412e8b Merge remote-tracking branch 'ブランチ名' into develop_1_0_10
980eaa8aa23 Merge branch 'ブランチ名' into develop_1_0_10
2273c3fc702 Merge branch 'develop_1_0_10' of リポジトリurl into develop_1_0_10
b8d79f04ada Merge branch 'ブランチ名' into develop_1_0_10
1401c6362ef Merge branch 'ブランチ名' into develop_1_0_10
1996bea9515 結果画面回収マージ
60f3975eca2 (develop_1_0_10) Merge branch 'ブランチ名' into develop_1_0_10
fd343cc51ae Merge branch 'ブランチ名' into develop_1_0_10
8c9430281d2 Merge branch 'ブランチ名' into develop_1_0_10
fcb95289395 Merge branch 'develop_1_0_10' into ブランチ名
654667a17c9 Merge branch 'ブランチ名' into ブランチ名
2348ac1353f Merge branch 'ブランチ名' into develop_1_0_10
b0d4c3a3640 Merge branch 'develop_1_0_10' into ブランチ名
3800da140df Merge remote-tracking branch 'origin/develop_1_0_10' into ブランチ名
9f26ce1fbd5 Merge branch 'ブランチ名' into develop_1_0_10
6e96ae6d8cb (tag: RELEASE_V1.0.09) Merge remote-tracking branch 'origin/develop_1_0_09' into release
4808ae0d0b2 Merge remote-tracking branch 'origin/develop_1_0_09' into ブランチ名
cb6883d4920 Merge branch 'develop_1_0_09' into ブランチ名
71a9575e728 Merge remote-tracking branch 'origin/develop_1_0_08' into ブランチ名
32d406e6366 Merge remote-tracking branch 'origin/develop_1_0_07' into ブランチ名

後の処理ははこれを見やすいように加工しているだけです。

マージコミットのメッセージが編集されている場合

1996bea9515 結果画面回収マージ
というコミットがそれに該当します。マージコミットのメッセージを編集する人がいるとは想定外!
もしコミットメッセージに空白が入っていたら最後のフィールド数チェックで弾いてしまいます。
自由記述のコミットメッセージでこれを解決しようとすると工数がかかりすぎるので諦めました:cry:

さいごに

書いてて思ったんですが、各自に以下を実行してもらった方が早いのでは?
リーダーと相談ですね:sweat:

git log --merges --oneline --author="$(git config user.name)" origin/release..origin/develop_1_0_10
1
6
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
1
6