From: Kevin Ballard Date: Thu, 4 Nov 2010 22:36:31 +0000 (-0700) Subject: rebase: better rearranging of fixup!/squash! lines with --autosquash X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=commitdiff_plain;h=d3d7a421b1439a6f08dfbcd2e3327cbe90c93417;p=git.git rebase: better rearranging of fixup!/squash! lines with --autosquash The current behvaior of --autosquash can duplicate fixup!/squash! lines if they match multiple commits, and it can also apply them to commits that come after them in the todo list. Even more oddly, a commit that looks like "fixup! fixup!" will match itself and be duplicated in the todo list. Change the todo list rearranging to mark all commits as used as soon as they are emitted, and to avoid emitting a fixup/squash commit if the commit has already been marked as used. Signed-off-by: Kevin Ballard Signed-off-by: Junio C Hamano --- diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh index a27952d9f..379bbac5e 100755 --- a/git-rebase--interactive.sh +++ b/git-rebase--interactive.sh @@ -687,8 +687,12 @@ rearrange_squash () { *" $sha1 "*) continue ;; esac printf '%s\n' "$pick $sha1 $message" + used="$used$sha1 " while read -r squash action msg do + case " $used" in + *" $squash "*) continue ;; + esac case "$message" in "$msg"*) printf '%s\n' "$action $squash $action! $msg" diff --git a/t/t3415-rebase-autosquash.sh b/t/t3415-rebase-autosquash.sh index fd2184ce7..712bbe86b 100755 --- a/t/t3415-rebase-autosquash.sh +++ b/t/t3415-rebase-autosquash.sh @@ -94,4 +94,47 @@ test_expect_success 'misspelled auto squash' ' test 0 = $(git rev-list final-missquash...HEAD | wc -l) ' +test_expect_success 'auto squash that matches 2 commits' ' + git reset --hard base && + echo 4 >file4 && + git add file4 && + test_tick && + git commit -m "first new commit" && + echo 1 >file1 && + git add -u && + test_tick && + git commit -m "squash! first" && + git tag final-multisquash && + test_tick && + git rebase --autosquash -i HEAD~4 && + git log --oneline >actual && + test 4 = $(wc -l file1 && + git add -u && + test_tick && + git commit -m "squash! third" && + echo 4 >file4 && + git add file4 && + test_tick && + git commit -m "third commit" && + git tag final-presquash && + test_tick && + git rebase --autosquash -i HEAD~4 && + git log --oneline >actual && + test 5 = $(wc -l