Skip to content

Commit

Permalink
rebase -i: commit when continuing after "edit"
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Johannes Schindelin authored and Junio C Hamano committed Sep 26, 2007
1 parent df3a02f commit be6ff20
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
17 changes: 11 additions & 6 deletions git-rebase--interactive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,16 @@ mark_action_done () {
}

make_patch () {
parent_sha1=$(git rev-parse --verify "$1"^ 2> /dev/null)
parent_sha1=$(git rev-parse --verify "$1"^) ||
die "Cannot get patch for $1^"
git diff "$parent_sha1".."$1" > "$DOTEST"/patch
test -f "$DOTEST"/message ||
git cat-file commit "$1" | sed "1,/^$/d" > "$DOTEST"/message
test -f "$DOTEST"/author-script ||
get_author_ident_from_commit "$1" > "$DOTEST"/author-script
}

die_with_patch () {
test -f "$DOTEST"/message ||
git cat-file commit $sha1 | sed "1,/^$/d" > "$DOTEST"/message
test -f "$DOTEST"/author-script ||
get_author_ident_from_commit $sha1 > "$DOTEST"/author-script
make_patch "$1"
die "$2"
}
Expand Down Expand Up @@ -214,6 +215,7 @@ peek_next_command () {
do_next () {
test -f "$DOTEST"/message && rm "$DOTEST"/message
test -f "$DOTEST"/author-script && rm "$DOTEST"/author-script
test -f "$DOTEST"/amend && rm "$DOTEST"/amend
read command sha1 rest < "$TODO"
case "$command" in
\#|'')
Expand All @@ -233,6 +235,7 @@ do_next () {
pick_one $sha1 ||
die_with_patch $sha1 "Could not apply $sha1... $rest"
make_patch $sha1
: > "$DOTEST"/amend
warn
warn "You can amend the commit now, with"
warn
Expand Down Expand Up @@ -330,7 +333,9 @@ do
git update-index --refresh &&
git diff-files --quiet &&
! git diff-index --cached --quiet HEAD &&
. "$DOTEST"/author-script &&
. "$DOTEST"/author-script && {
test ! -f "$DOTEST"/amend || git reset --soft HEAD^
} &&
export GIT_AUTHOR_NAME GIT_AUTHOR_NAME GIT_AUTHOR_DATE &&
git commit -F "$DOTEST"/message -e

Expand Down
14 changes: 13 additions & 1 deletion t/t3404-rebase-interactive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ cat "$1".tmp
action=pick
for line in $FAKE_LINES; do
case $line in
squash)
squash|edit)
action="$line";;
*)
echo sed -n "${line}s/^pick/$action/p"
Expand Down Expand Up @@ -297,4 +297,16 @@ test_expect_success 'ignore patch if in upstream' '
test $HEAD = $(git rev-parse HEAD^)
'

test_expect_success '--continue tries to commit, even for "edit"' '
parent=$(git rev-parse HEAD^) &&
test_tick &&
FAKE_LINES="edit 1" git rebase -i HEAD^ &&
echo edited > file7 &&
git add file7 &&
FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue &&
test edited = $(git show HEAD:file7) &&
git show HEAD | grep chouette &&
test $parent = $(git rev-parse HEAD^)
'

test_done

0 comments on commit be6ff20

Please sign in to comment.