Skip to content

Commit b2f3bb1

Browse files
committed
git-gui: Give amend precedence to HEAD over MERGE_MSG
Apparently git-commit.sh (the command line commit user interface in core Git) always gives precedence to the prior commit's message if `commit --amend` is used and a $GIT_DIR/MERGE_MSG file also exists. We actually were doing the same here in git-gui, but the amended message got lost if $GIT_DIR/MERGE_MSG already existed because we started a rescan immediately after loading the prior commit's body into the edit buffer. When that happened the rescan found MERGE_MSG existed and replaced the commit message buffer with the contents of that file. This meant the user never saw us pick up the commit message of the prior commit we are about to replace. Johannes Sixt <[email protected]> found this bug in git-gui by running `git cherry-pick -n $someid` and then trying to amend the prior commit in git-gui, thus combining the contents of $someid with the contents of HEAD, and reusing the commit message of HEAD, not $someid. With the recent changes to make cherry-pick use the $GIT_DIR/MERGE_MSG file Johannes saw git-gui pick up the message of $someid, not HEAD. Now we always use HEAD if we are amending. Signed-off-by: Shawn O. Pearce <[email protected]>
1 parent 615b865 commit b2f3bb1

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

git-gui.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,8 @@ proc rescan {after {honor_trustmtime 1}} {
471471

472472
if {![$ui_comm edit modified]
473473
|| [string trim [$ui_comm get 0.0 end]] eq {}} {
474-
if {[load_message GITGUI_MSG]} {
474+
if {[string match amend* $commit_type]} {
475+
} elseif {[load_message GITGUI_MSG]} {
475476
} elseif {[load_message MERGE_MSG]} {
476477
} elseif {[load_message SQUASH_MSG]} {
477478
}

0 commit comments

Comments
 (0)