@matheusbsbs / matheus-bagliano / commits / be6ff208d8
Fork 0

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>

Johannes Schindelin committed Sep 25, 2007 at 16:42 UTC be6ff208d8248c3f282df14fdf3c08db57e92007
2 files changed +24 -7
git-rebase--interactive.sh
+11 -6
@@ -77,15 +77,16 @@ mark_action_done () {
77 }
78
79 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^"
82 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
87 }
88
89 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
90 make_patch "$1"
91 die "$2"
92 }
@@ -214,6 +215,7 @@ peek_next_command () {
215 do_next () {
216 test -f "$DOTEST"/message && rm "$DOTEST"/message
217 test -f "$DOTEST"/author-script && rm "$DOTEST"/author-script
218 + test -f "$DOTEST"/amend && rm "$DOTEST"/amend
219 read command sha1 rest < "$TODO"
220 case "$command" in
221 \#|'')
@@ -233,6 +235,7 @@ do_next () {
235 pick_one $sha1 ||
236 die_with_patch $sha1 "Could not apply $sha1... $rest"
237 make_patch $sha1
238 + : > "$DOTEST"/amend
239 warn
240 warn "You can amend the commit now, with"
241 warn
@@ -330,7 +333,9 @@ do
333 git update-index --refresh &&
334 git diff-files --quiet &&
335 ! git diff-index --cached --quiet HEAD &&
333 - . "$DOTEST"/author-script &&
336 + . "$DOTEST"/author-script && {
337 + test ! -f "$DOTEST"/amend || git reset --soft HEAD^
338 + } &&
339 export GIT_AUTHOR_NAME GIT_AUTHOR_NAME GIT_AUTHOR_DATE &&
340 git commit -F "$DOTEST"/message -e
341
t/t3404-rebase-interactive.sh
+13 -1
@@ -80,7 +80,7 @@ cat "$1".tmp
80 action=pick
81 for line in $FAKE_LINES; do
82 case $line in
83 - squash)
83 + squash|edit)
84 action="$line";;
85 *)
86 echo sed -n "${line}s/^pick/$action/p"
@@ -297,4 +297,16 @@ test_expect_success 'ignore patch if in upstream' '
297 test $HEAD = $(git rev-parse HEAD^)
298 '
299
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 +
312 test_done