From: Kevin Ballard <hidden> Date: 2016-06-15 22:49:58
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 <redacted>
---
git-rebase--interactive.sh | 4 +++
t/t3415-rebase-autosquash.sh | 43 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 47 insertions(+), 0 deletions(-)
@@ -94,4 +94,47 @@ test_expect_success 'misspelled auto squash' 'test0=$(gitrev-listfinal-missquash...HEAD|wc-l)'+test_expect_success'auto squash that matches 2 commits''+gitreset--hardbase&&+echo4>file4&&+gitaddfile4&&+test_tick&&+gitcommit-m"first new commit"&&+echo1>file1&&+gitadd-u&&+test_tick&&+gitcommit-m"squash! first"&&+gittagfinal-multisquash&&+test_tick&&+gitrebase--autosquash-iHEAD~4&&+gitlog--oneline>actual&&+test4=$(wc-l<actual)&&+gitdiff--exit-codefinal-multisquash&&+test1="$(gitcat-fileblobHEAD^^:file1)"&&+test2=$(gitcat-filecommitHEAD^^|grepfirst|wc-l)&&+test1=$(gitcat-filecommitHEAD|grepfirst|wc-l)+'++test_expect_success'auto squash that matches a commit after the squash''+gitreset--hardbase&&+echo1>file1&&+gitadd-u&&+test_tick&&+gitcommit-m"squash! third"&&+echo4>file4&&+gitaddfile4&&+test_tick&&+gitcommit-m"third commit"&&+gittagfinal-presquash&&+test_tick&&+gitrebase--autosquash-iHEAD~4&&+gitlog--oneline>actual&&+test5=$(wc-l<actual)&&+gitdiff--exit-codefinal-presquash&&+test0="$(gitcat-fileblobHEAD^^:file1)"&&+test1="$(gitcat-fileblobHEAD^:file1)"&&+test1=$(gitcat-filecommitHEAD|grepthird|wc-l)&&+test1=$(gitcat-filecommitHEAD^|grepthird|wc-l)+'+ test_done
From: Kevin Ballard <hidden> Date: 2016-06-15 22:49:58
Support lines of the form "fixup! 7a235b" that specify an exact commit
in addition to the normal "squash! Old commit message" form.
Signed-off-by: Kevin Ballard <redacted>
---
I chose 4 characters as the restriction because that's the minimum number
that `git rev-parse --short=<n>` will emit.
git-rebase--interactive.sh | 13 +++++++++----
t/t3415-rebase-autosquash.sh | 33 +++++++++++++++++++++++++++++++++
2 files changed, 42 insertions(+), 4 deletions(-)
@@ -136,5 +136,38 @@ test_expect_success 'auto squash that matches a commit after the squash' 'test1=$(gitcat-filecommitHEAD|grepthird|wc-l)&&test1=$(gitcat-filecommitHEAD^|grepthird|wc-l)'+test_expect_success'auto squash that matches a sha1''+gitreset--hardbase&&+echo1>file1&&+gitadd-u&&+test_tick&&+gitcommit-m"squash! $(gitrev-parse--shortHEAD^)"&&+gittagfinal-shasquash&&+test_tick&&+gitrebase--autosquash-iHEAD^^^&&+gitlog--oneline>actual&&+test3=$(wc-l<actual)&&+gitdiff--exit-codefinal-shasquash&&+test1="$(gitcat-fileblobHEAD^:file1)"&&+test1=$(gitcat-filecommitHEAD^|grepsquash|wc-l)+'++# this test just ensures that < 4 characters can't match a sha1+test_expect_success'auto squash that accidentally matches a sha1''+gitreset--hardbase&&+echo1>file1&&+gitadd-u&&+test_tick&&+gitcommit-m"squash! $(gitrev-parseHEAD^|cut-c1-3)"&&+gittagfinal-badshasquash&&+test_tick&&+gitrebase--autosquash-iHEAD^^^&&+gitlog--oneline>actual&&+test4=$(wc-l<actual)&&+gitdiff--exit-codefinal-badshasquash&&+test0="$(gitcat-fileblobHEAD^^:file1)"&&+test0=$(gitcat-filecommitHEAD^^|grepsquash|wc-l)&&+test1=$(gitcat-filecommitHEAD|grepsquash|wc-l)+' test_done
From: Kevin Ballard <hidden> Date: 2016-06-15 22:49:58
On Nov 3, 2010, at 7:41 PM, Kevin Ballard wrote:
Support lines of the form "fixup! 7a235b" that specify an exact commit
in addition to the normal "squash! Old commit message" form.
I just realized that this only works for sha1's of up to 7 characters.
If you provide more it won't match, as it's comparing against the sha1
given in the todo list. I wonder if it's worth resolving all sha1s to
their full length if the provided string is longer than 7 characters?
-Kevin Ballard
Heya,
On Thu, Nov 4, 2010 at 05:49, Kevin Ballard [off-list ref] wrote:
I just realized that this only works for sha1's of up to 7 characters.
If you provide more it won't match, as it's comparing against the sha1
given in the todo list. I wonder if it's worth resolving all sha1s to
their full length if the provided string is longer than 7 characters?
Well, not if you're resolving them based on the 7-character string
from the rebase todo list. If you run in to ambiguity with those
7-length hash we should instead increase the length of the hashes in
the todo list.
So I'd say, solve this by doing a prefix match?
--
Cheers,
Sverre Rabbelier
From: Kevin Ballard <hidden> Date: 2016-06-15 22:49:58
On Nov 4, 2010, at 3:44 AM, Sverre Rabbelier wrote:
On Thu, Nov 4, 2010 at 05:49, Kevin Ballard [off-list ref] wrote:
quoted
I just realized that this only works for sha1's of up to 7 characters.
If you provide more it won't match, as it's comparing against the sha1
given in the todo list. I wonder if it's worth resolving all sha1s to
their full length if the provided string is longer than 7 characters?
Well, not if you're resolving them based on the 7-character string
from the rebase todo list. If you run in to ambiguity with those
7-length hash we should instead increase the length of the hashes in
the todo list.
So I'd say, solve this by doing a prefix match?
Prefix match of what against what? If the 7-character string used in the
TODO list is already ambiguous, then the rebase itself would be expected
to fail. I'm inclined to just try to resolve the message in the fixup!
line itself to a full SHA1, and if that works, then try to match the
7-character sha1 with a prefix comparison.
-Kevin Ballard
From: Kevin Ballard <hidden> Date: 2016-06-15 22:49:59
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 <redacted>
---
This patch is unchanged from v2.
git-rebase--interactive.sh | 4 +++
t/t3415-rebase-autosquash.sh | 43 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 47 insertions(+), 0 deletions(-)
@@ -94,4 +94,47 @@ test_expect_success 'misspelled auto squash' 'test0=$(gitrev-listfinal-missquash...HEAD|wc-l)'+test_expect_success'auto squash that matches 2 commits''+gitreset--hardbase&&+echo4>file4&&+gitaddfile4&&+test_tick&&+gitcommit-m"first new commit"&&+echo1>file1&&+gitadd-u&&+test_tick&&+gitcommit-m"squash! first"&&+gittagfinal-multisquash&&+test_tick&&+gitrebase--autosquash-iHEAD~4&&+gitlog--oneline>actual&&+test4=$(wc-l<actual)&&+gitdiff--exit-codefinal-multisquash&&+test1="$(gitcat-fileblobHEAD^^:file1)"&&+test2=$(gitcat-filecommitHEAD^^|grepfirst|wc-l)&&+test1=$(gitcat-filecommitHEAD|grepfirst|wc-l)+'++test_expect_success'auto squash that matches a commit after the squash''+gitreset--hardbase&&+echo1>file1&&+gitadd-u&&+test_tick&&+gitcommit-m"squash! third"&&+echo4>file4&&+gitaddfile4&&+test_tick&&+gitcommit-m"third commit"&&+gittagfinal-presquash&&+test_tick&&+gitrebase--autosquash-iHEAD~4&&+gitlog--oneline>actual&&+test5=$(wc-l<actual)&&+gitdiff--exit-codefinal-presquash&&+test0="$(gitcat-fileblobHEAD^^:file1)"&&+test1="$(gitcat-fileblobHEAD^:file1)"&&+test1=$(gitcat-filecommitHEAD|grepthird|wc-l)&&+test1=$(gitcat-filecommitHEAD^|grepthird|wc-l)+'+ test_done
From: Kevin Ballard <hidden> Date: 2016-06-15 22:49:59
Support lines of the form "fixup! 7a235b" that specify an exact commit
in addition to the normal "squash! Old commit message" form.
Signed-off-by: Kevin Ballard <redacted>
---
The only change from v2 is I've added the manpage change from Peter Krefting's
previous patch on this subject (http://www.spinics.net/lists/git/msg133571.html),
as referenced in message id [off-list ref].
Documentation/git-rebase.txt | 8 ++++----
git-rebase--interactive.sh | 40 +++++++++++++++++++++++++++++++++-------
t/t3415-rebase-autosquash.sh | 31 +++++++++++++++++++++++++++++++
3 files changed, 68 insertions(+), 11 deletions(-)
@@ -339,10 +339,10 @@ idea unless you know what you are doing (see BUGS below). --no-autosquash:: When the commit log message begins with "squash! ..." (or "fixup! ..."), and there is a commit whose title begins with- the same ..., automatically modify the todo list of rebase -i- so that the commit marked for squashing comes right after the- commit to be modified, and change the action of the moved- commit from `pick` to `squash` (or `fixup`).+ the same ..., or whose hash is ..., automatically modify the+ todo list of rebase -i so that the commit marked for squashing+ comes right after the commit to be modified, and change the+ action of the moved commit from `pick` to `squash` (or `fixup`). + This option is only valid when the '--interactive' option is used. +
@@ -695,9 +695,27 @@ get_saved_options () {# comes immediately after the former, and change "pick" to# "fixup"/"squash". rearrange_squash(){-sed-n-e's/^pick \([0-9a-f]*\) \(squash\)! /\1 \2 /p'\--e's/^pick \([0-9a-f]*\) \(fixup\)! /\1 \2 /p'\-"$1">"$1.sq"+# extract fixup!/squash! lines and resolve any referenced sha1's+whileread-rpicksha1message+do+case"$message"in+"squash! "*|"fixup! "*)+action="${message%%!*}"+rest="${message#*! }"+echo"$sha1$action$rest"+# if it's a single word, try to resolve to a full sha1 and+# emit a second copy. This allows us to match on both message+# and on sha1 prefix+iftest"${rest#* }"="$rest";then+fullsha="$(gitrev-parse-q--verify"$rest"2>/dev/null)"+iftest-n"$fullsha";then+# prefix the action to uniquely identify this line as+# intended for full sha1 match+echo"$sha1 +$action$fullsha"+fi+fi+esac+done>"$1.sq"<"$1"test-s"$1.sq"||returnused=
@@ -136,5 +136,36 @@ test_expect_success 'auto squash that matches a commit after the squash' 'test1=$(gitcat-filecommitHEAD|grepthird|wc-l)&&test1=$(gitcat-filecommitHEAD^|grepthird|wc-l)'+test_expect_success'auto squash that matches a sha1''+gitreset--hardbase&&+echo1>file1&&+gitadd-u&&+test_tick&&+gitcommit-m"squash! $(gitrev-parse--shortHEAD^)"&&+gittagfinal-shasquash&&+test_tick&&+gitrebase--autosquash-iHEAD^^^&&+gitlog--oneline>actual&&+test3=$(wc-l<actual)&&+gitdiff--exit-codefinal-shasquash&&+test1="$(gitcat-fileblobHEAD^:file1)"&&+test1=$(gitcat-filecommitHEAD^|grepsquash|wc-l)+'++test_expect_success'auto squash that matches longer sha1''+gitreset--hardbase&&+echo1>file1&&+gitadd-u&&+test_tick&&+gitcommit-m"squash! $(gitrev-parse--short=11HEAD^)"&&+gittagfinal-longshasquash&&+test_tick&&+gitrebase--autosquash-iHEAD^^^&&+gitlog--oneline>actual&&+test3=$(wc-l<actual)&&+gitdiff--exit-codefinal-longshasquash&&+test1="$(gitcat-fileblobHEAD^:file1)"&&+test1=$(gitcat-filecommitHEAD^|grepsquash|wc-l)+' test_done
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.
That last part of the sentence does not match my experience - it looks
like you describe as a bug a nonexistent feature I miss :)
See http://marc.info/?l=git&m=128784082701920 for a testcase that
exhibits what I think is a problem.
--
Yann Dirson - Bertin Technologies
From: Kevin Ballard <hidden> Date: 2016-06-15 22:49:59
On Nov 8, 2010, at 2:52 AM, Yann Dirson wrote:
Kevin wrote:
quoted
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.
That last part of the sentence does not match my experience - it looks
like you describe as a bug a nonexistent feature I miss :)
See http://marc.info/?l=git&m=128784082701920 for a testcase that
exhibits what I think is a problem.
The bug is definitely present. It seems what you're describing is that you
want it to continue to place that fixup! there, but you want it to skip the
pick line that occurs earlier in the TODO list. My feeling is that this is
purely a bug, and should be fixed to not place the fixup! line after the
later commit.
If you do want the behavior where it skips the pick and places the fixup!
line after the later commit, I would encourage you to file a separate patch
for that.
-Kevin Ballard