Skip to content

Commit bde1a68

Browse files
mhaggergitster
authored andcommitted
rebase -i: Change function make_squash_message into update_squash_message
Alter the file $SQUASH_MSG in place rather than outputting the new message then juggling it around. Change the function name accordingly. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 7756ecf commit bde1a68

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

git-rebase--interactive.sh

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -358,21 +358,26 @@ nth_string () {
358358
esac
359359
}
360360

361-
make_squash_message () {
361+
update_squash_message () {
362362
if test -f "$SQUASH_MSG"; then
363+
mv "$SQUASH_MSG" "$SQUASH_MSG".bak || exit
363364
COUNT=$(($(sed -n \
364365
-e "1s/^# This is a combination of \(.*\) commits\./\1/p" \
365-
-e "q" < "$SQUASH_MSG")+1))
366-
echo "# This is a combination of $COUNT commits."
367-
sed -e 1d -e '2,/^./{
368-
/^$/d
369-
}' <"$SQUASH_MSG"
366+
-e "q" < "$SQUASH_MSG".bak)+1))
367+
{
368+
echo "# This is a combination of $COUNT commits."
369+
sed -e 1d -e '2,/^./{
370+
/^$/d
371+
}' <"$SQUASH_MSG".bak
372+
} >$SQUASH_MSG
370373
else
371374
COUNT=2
372-
echo "# This is a combination of 2 commits."
373-
echo "# The first commit's message is:"
374-
echo
375-
commit_message HEAD
375+
{
376+
echo "# This is a combination of 2 commits."
377+
echo "# The first commit's message is:"
378+
echo
379+
commit_message HEAD
380+
} >$SQUASH_MSG
376381
fi
377382
case $1 in
378383
squash)
@@ -387,7 +392,7 @@ make_squash_message () {
387392
echo
388393
commit_message $2 | sed -e 's/^/# /'
389394
;;
390-
esac
395+
esac >>$SQUASH_MSG
391396
}
392397

393398
peek_next_command () {
@@ -450,7 +455,7 @@ do_next () {
450455
die "Cannot '$squash_style' without a previous commit"
451456

452457
mark_action_done
453-
make_squash_message $squash_style $sha1 > "$MSG"
458+
update_squash_message $squash_style $sha1
454459
failed=f
455460
author_script=$(get_author_ident_from_commit HEAD)
456461
echo "$author_script" > "$AUTHOR_SCRIPT"
@@ -460,16 +465,16 @@ do_next () {
460465
case "$(peek_next_command)" in
461466
squash|s|fixup|f)
462467
USE_OUTPUT=output
468+
cp "$SQUASH_MSG" "$MSG" || exit
463469
MSG_OPT=-F
464470
EDIT_OR_FILE="$MSG"
465-
cp "$MSG" "$SQUASH_MSG"
466471
;;
467472
*)
468473
USE_OUTPUT=
469474
MSG_OPT=
470475
EDIT_OR_FILE=-e
471-
rm -f "$SQUASH_MSG" || exit
472-
cp "$MSG" "$GIT_DIR"/SQUASH_MSG
476+
cp "$SQUASH_MSG" "$MSG" || exit
477+
mv "$SQUASH_MSG" "$GIT_DIR"/SQUASH_MSG || exit
473478
rm -f "$GIT_DIR"/MERGE_MSG || exit
474479
;;
475480
esac

0 commit comments

Comments
 (0)