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

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 <kevin@sb.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Kevin Ballard committed Nov 4, 2010 at 15:36 UTC d3d7a421b1439a6f08dfbcd2e3327cbe90c93417
2 files changed +47
git-rebase--interactive.sh
+4
@@ -687,8 +687,12 @@ rearrange_squash () {
687 *" $sha1 "*) continue ;;
688 esac
689 printf '%s\n' "$pick $sha1 $message"
690 + used="$used$sha1 "
691 while read -r squash action msg
692 do
693 + case " $used" in
694 + *" $squash "*) continue ;;
695 + esac
696 case "$message" in
697 "$msg"*)
698 printf '%s\n' "$action $squash $action! $msg"
t/t3415-rebase-autosquash.sh
+43
@@ -94,4 +94,47 @@ test_expect_success 'misspelled auto squash' '
94 test 0 = $(git rev-list final-missquash...HEAD | wc -l)
95 '
96
97 +test_expect_success 'auto squash that matches 2 commits' '
98 + git reset --hard base &&
99 + echo 4 >file4 &&
100 + git add file4 &&
101 + test_tick &&
102 + git commit -m "first new commit" &&
103 + echo 1 >file1 &&
104 + git add -u &&
105 + test_tick &&
106 + git commit -m "squash! first" &&
107 + git tag final-multisquash &&
108 + test_tick &&
109 + git rebase --autosquash -i HEAD~4 &&
110 + git log --oneline >actual &&
111 + test 4 = $(wc -l <actual) &&
112 + git diff --exit-code final-multisquash &&
113 + test 1 = "$(git cat-file blob HEAD^^:file1)" &&
114 + test 2 = $(git cat-file commit HEAD^^ | grep first | wc -l) &&
115 + test 1 = $(git cat-file commit HEAD | grep first | wc -l)
116 +'
117 +
118 +test_expect_success 'auto squash that matches a commit after the squash' '
119 + git reset --hard base &&
120 + echo 1 >file1 &&
121 + git add -u &&
122 + test_tick &&
123 + git commit -m "squash! third" &&
124 + echo 4 >file4 &&
125 + git add file4 &&
126 + test_tick &&
127 + git commit -m "third commit" &&
128 + git tag final-presquash &&
129 + test_tick &&
130 + git rebase --autosquash -i HEAD~4 &&
131 + git log --oneline >actual &&
132 + test 5 = $(wc -l <actual) &&
133 + git diff --exit-code final-presquash &&
134 + test 0 = "$(git cat-file blob HEAD^^:file1)" &&
135 + test 1 = "$(git cat-file blob HEAD^:file1)" &&
136 + test 1 = $(git cat-file commit HEAD | grep third | wc -l) &&
137 + test 1 = $(git cat-file commit HEAD^ | grep third | wc -l)
138 +'
139 +
140 test_done