Skip to content

Commit 6a74642

Browse files
author
Junio C Hamano
committed
git-commit --amend: two fixes.
When running "git commit --amend" only to fix the commit log message without any content change, we mistakenly showed the git-status output that says "nothing to commit" without commenting it out. If you have already run update-index but you want to amend the top commit, "git commit --amend --only" without any paths should have worked, because --only means "starting from the base commit, update-index these paths only to prepare the index to commit, and perform the commit". However, we refused -o without paths. Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent 61c2bcb commit 6a74642

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

git-commit.sh

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,13 @@ run_status () {
167167
fi
168168
case "$committable" in
169169
0)
170-
echo "nothing to commit"
171-
exit 1
170+
case "$amend" in
171+
t)
172+
echo "# No changes" ;;
173+
*)
174+
echo "nothing to commit" ;;
175+
esac
176+
exit 1 ;;
172177
esac
173178
exit 0
174179
)
@@ -365,14 +370,16 @@ tt*)
365370
die "Only one of -c/-C/-F/-m can be used." ;;
366371
esac
367372

368-
case "$#,$also$only" in
369-
*,tt)
373+
case "$#,$also,$only,$amend" in
374+
*,t,t,*)
370375
die "Only one of --include/--only can be used." ;;
371-
0,t)
376+
0,t,,* | 0,,t,)
372377
die "No paths with --include/--only does not make sense." ;;
373-
0,)
378+
0,,t,t)
379+
only_include_assumed="# Clever... amending the last one with dirty index." ;;
380+
0,,,*)
374381
;;
375-
*,)
382+
*,,,*)
376383
only_include_assumed="# Explicit paths specified without -i nor -o; assuming --only paths..."
377384
also=
378385
;;

t/t1200-tutorial.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ EOF
114114

115115
git commit -m 'Merged "mybranch" changes.' -i hello
116116

117+
test_done
118+
117119
cat > show-branch.expect << EOF
118120
* [master] Merged "mybranch" changes.
119121
! [mybranch] Some work.

0 commit comments

Comments
 (0)