Skip to content

Commit 7c41883

Browse files
szederspearce
authored andcommitted
rebase -i: proper prepare-commit-msg hook argument when squashing
One would expect that the prepare-commit-msg hook gets 'squash' as the second argument when squashing commits with 'rebase -i'. However, that was not the case, as it got 'merge' instead. This patch fixes the problem. Signed-off-by: SZEDER Gábor <[email protected]> Signed-off-by: Shawn O. Pearce <[email protected]>
1 parent 9a1fd65 commit 7c41883

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

git-rebase--interactive.sh

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -304,23 +304,28 @@ do_next () {
304304

305305
mark_action_done
306306
make_squash_message $sha1 > "$MSG"
307+
failed=f
308+
author_script=$(get_author_ident_from_commit HEAD)
309+
output git reset --soft HEAD^
310+
pick_one -n $sha1 || failed=t
307311
case "$(peek_next_command)" in
308312
squash|s)
309313
EDIT_COMMIT=
310314
USE_OUTPUT=output
315+
MSG_OPT=-F
316+
MSG_FILE="$MSG"
311317
cp "$MSG" "$SQUASH_MSG"
312318
;;
313319
*)
314320
EDIT_COMMIT=-e
315321
USE_OUTPUT=
322+
MSG_OPT=
323+
MSG_FILE=
316324
rm -f "$SQUASH_MSG" || exit
325+
cp -v "$MSG" "$GIT_DIR"/SQUASH_MSG
326+
rm -f "$GIT_DIR"/MERGE_MSG || exit
317327
;;
318328
esac
319-
320-
failed=f
321-
author_script=$(get_author_ident_from_commit HEAD)
322-
output git reset --soft HEAD^
323-
pick_one -n $sha1 || failed=t
324329
echo "$author_script" > "$DOTEST"/author-script
325330
if test $failed = f
326331
then
@@ -329,7 +334,7 @@ do_next () {
329334
GIT_AUTHOR_NAME="$GIT_AUTHOR_NAME" \
330335
GIT_AUTHOR_EMAIL="$GIT_AUTHOR_EMAIL" \
331336
GIT_AUTHOR_DATE="$GIT_AUTHOR_DATE" \
332-
$USE_OUTPUT git commit --no-verify -F "$MSG" $EDIT_COMMIT || failed=t
337+
$USE_OUTPUT git commit --no-verify $MSG_OPT "$MSG_FILE" $EDIT_COMMIT || failed=t
333338
fi
334339
if test $failed = t
335340
then

0 commit comments

Comments
 (0)