Skip to content

Commit be6ff20

Browse files
dschogitster
authored andcommitted
rebase -i: commit when continuing after "edit"
When doing an "edit" on a commit, editing and git-adding some files, "git rebase -i" complained about a missing "author-script". The idea was that the user would call "git commit --amend" herself. But we can be nice and do that for the user. Noticed by Dmitry Potapov. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent df3a02f commit be6ff20

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

git-rebase--interactive.sh

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,16 @@ mark_action_done () {
7777
}
7878

7979
make_patch () {
80-
parent_sha1=$(git rev-parse --verify "$1"^ 2> /dev/null)
80+
parent_sha1=$(git rev-parse --verify "$1"^) ||
81+
die "Cannot get patch for $1^"
8182
git diff "$parent_sha1".."$1" > "$DOTEST"/patch
83+
test -f "$DOTEST"/message ||
84+
git cat-file commit "$1" | sed "1,/^$/d" > "$DOTEST"/message
85+
test -f "$DOTEST"/author-script ||
86+
get_author_ident_from_commit "$1" > "$DOTEST"/author-script
8287
}
8388

8489
die_with_patch () {
85-
test -f "$DOTEST"/message ||
86-
git cat-file commit $sha1 | sed "1,/^$/d" > "$DOTEST"/message
87-
test -f "$DOTEST"/author-script ||
88-
get_author_ident_from_commit $sha1 > "$DOTEST"/author-script
8990
make_patch "$1"
9091
die "$2"
9192
}
@@ -214,6 +215,7 @@ peek_next_command () {
214215
do_next () {
215216
test -f "$DOTEST"/message && rm "$DOTEST"/message
216217
test -f "$DOTEST"/author-script && rm "$DOTEST"/author-script
218+
test -f "$DOTEST"/amend && rm "$DOTEST"/amend
217219
read command sha1 rest < "$TODO"
218220
case "$command" in
219221
\#|'')
@@ -233,6 +235,7 @@ do_next () {
233235
pick_one $sha1 ||
234236
die_with_patch $sha1 "Could not apply $sha1... $rest"
235237
make_patch $sha1
238+
: > "$DOTEST"/amend
236239
warn
237240
warn "You can amend the commit now, with"
238241
warn
@@ -330,7 +333,9 @@ do
330333
git update-index --refresh &&
331334
git diff-files --quiet &&
332335
! git diff-index --cached --quiet HEAD &&
333-
. "$DOTEST"/author-script &&
336+
. "$DOTEST"/author-script && {
337+
test ! -f "$DOTEST"/amend || git reset --soft HEAD^
338+
} &&
334339
export GIT_AUTHOR_NAME GIT_AUTHOR_NAME GIT_AUTHOR_DATE &&
335340
git commit -F "$DOTEST"/message -e
336341

t/t3404-rebase-interactive.sh

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ cat "$1".tmp
8080
action=pick
8181
for line in $FAKE_LINES; do
8282
case $line in
83-
squash)
83+
squash|edit)
8484
action="$line";;
8585
*)
8686
echo sed -n "${line}s/^pick/$action/p"
@@ -297,4 +297,16 @@ test_expect_success 'ignore patch if in upstream' '
297297
test $HEAD = $(git rev-parse HEAD^)
298298
'
299299

300+
test_expect_success '--continue tries to commit, even for "edit"' '
301+
parent=$(git rev-parse HEAD^) &&
302+
test_tick &&
303+
FAKE_LINES="edit 1" git rebase -i HEAD^ &&
304+
echo edited > file7 &&
305+
git add file7 &&
306+
FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue &&
307+
test edited = $(git show HEAD:file7) &&
308+
git show HEAD | grep chouette &&
309+
test $parent = $(git rev-parse HEAD^)
310+
'
311+
300312
test_done

0 commit comments

Comments
 (0)