From 163f3925902446735b2f631dc44ab67882a93024 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 7 Dec 2009 05:22:58 +0100 Subject: t3404: Use test_commit to set up test repository Also adjust "expected" text to reflect the file contents generated by test_commit, which are slightly different than those generated by the old code. Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- t/t3404-rebase-interactive.sh | 66 +++++++++++++------------------------------ 1 file changed, 20 insertions(+), 46 deletions(-) (limited to 't/t3404-rebase-interactive.sh') diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh index 3a37793c0d..778daf419c 100755 --- a/t/t3404-rebase-interactive.sh +++ b/t/t3404-rebase-interactive.sh @@ -16,53 +16,26 @@ set_fake_editor # set up two branches like this: # -# A - B - C - D - E +# A - B - C - D - E (master) # \ -# F - G - H +# F - G - H (branch1) # \ -# I +# I (branch2) # -# where B, D and G touch the same file. +# where A, B, D and G touch the same file. test_expect_success 'setup' ' - : > file1 && - git add file1 && - test_tick && - git commit -m A && - git tag A && - echo 1 > file1 && - test_tick && - git commit -m B file1 && - : > file2 && - git add file2 && - test_tick && - git commit -m C && - echo 2 > file1 && - test_tick && - git commit -m D file1 && - : > file3 && - git add file3 && - test_tick && - git commit -m E && + test_commit A file1 && + test_commit B file1 && + test_commit C file2 && + test_commit D file1 && + test_commit E file3 && git checkout -b branch1 A && - : > file4 && - git add file4 && - test_tick && - git commit -m F && - git tag F && - echo 3 > file1 && - test_tick && - git commit -m G file1 && - : > file5 && - git add file5 && - test_tick && - git commit -m H && + test_commit F file4 && + test_commit G file1 && + test_commit H file5 && git checkout -b branch2 F && - : > file6 && - git add file6 && - test_tick && - git commit -m I && - git tag I + test_commit I file6 ' test_expect_success 'no changes are a nop' ' @@ -111,19 +84,20 @@ test_expect_success 'exchange two commits' ' cat > expect << EOF diff --git a/file1 b/file1 -index e69de29..00750ed 100644 +index f70f10e..fd79235 100644 --- a/file1 +++ b/file1 -@@ -0,0 +1 @@ -+3 +@@ -1 +1 @@ +-A ++G EOF cat > expect2 << EOF <<<<<<< HEAD -2 +D ======= -3 ->>>>>>> b7ca976... G +G +>>>>>>> 91201e5... G EOF test_expect_success 'stop on conflicting pick' ' -- cgit v1.2.3 From 0205e72f088322a70a77643a7cd2d8b23ee07e14 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 7 Dec 2009 10:20:59 +0100 Subject: Add a command "fixup" to rebase --interactive The command is like "squash", except that it discards the commit message of the corresponding commit. Signed-off-by: Michael Haggerty Acked-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- t/t3404-rebase-interactive.sh | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 't/t3404-rebase-interactive.sh') diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh index 778daf419c..ea26115133 100755 --- a/t/t3404-rebase-interactive.sh +++ b/t/t3404-rebase-interactive.sh @@ -235,6 +235,36 @@ test_expect_success 'multi-squash only fires up editor once' ' test 1 = $(git show | grep ONCE | wc -l) ' +test_expect_success 'multi-fixup only fires up editor once' ' + git checkout -b multi-fixup E && + base=$(git rev-parse HEAD~4) && + FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="1 fixup 2 fixup 3 fixup 4" \ + git rebase -i $base && + test $base = $(git rev-parse HEAD^) && + test 1 = $(git show | grep ONCE | wc -l) && + git checkout to-be-rebased && + git branch -D multi-fixup +' + +cat > expect-squash-fixup << EOF +B + +D + +ONCE +EOF + +test_expect_success 'squash and fixup generate correct log messages' ' + git checkout -b squash-fixup E && + base=$(git rev-parse HEAD~4) && + FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="1 fixup 2 squash 3 fixup 4" \ + git rebase -i $base && + git cat-file commit HEAD | sed -e 1,/^\$/d > actual-squash-fixup && + test_cmp expect-squash-fixup actual-squash-fixup && + git checkout to-be-rebased && + git branch -D squash-fixup +' + test_expect_success 'squash works as expected' ' for n in one two three four do -- cgit v1.2.3 From 234b3dae2fe83ae7df2c82194cd5f5eb01fd166d Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Tue, 12 Jan 2010 16:38:36 +0100 Subject: rebase-i: Ignore comments and blank lines in peek_next_command Previously, blank lines and/or comments within a series of squash/fixup commands would confuse "git rebase -i" into thinking that the series was finished. It would therefore require the user to edit the commit message for the squash/fixup commits seen so far. Then, after continuing, it would ask the user to edit the commit message again. Ignore comments and blank lines within a group of squash/fixup commands, allowing them to be processed in one go. Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- t/t3404-rebase-interactive.sh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 't/t3404-rebase-interactive.sh') diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh index ea26115133..d9382e41d3 100755 --- a/t/t3404-rebase-interactive.sh +++ b/t/t3404-rebase-interactive.sh @@ -265,6 +265,30 @@ test_expect_success 'squash and fixup generate correct log messages' ' git branch -D squash-fixup ' +test_expect_success 'squash ignores comments' ' + git checkout -b skip-comments E && + base=$(git rev-parse HEAD~4) && + FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="# 1 # squash 2 # squash 3 # squash 4 #" \ + EXPECT_HEADER_COUNT=4 \ + git rebase -i $base && + test $base = $(git rev-parse HEAD^) && + test 1 = $(git show | grep ONCE | wc -l) && + git checkout to-be-rebased && + git branch -D skip-comments +' + +test_expect_success 'squash ignores blank lines' ' + git checkout -b skip-blank-lines E && + base=$(git rev-parse HEAD~4) && + FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="> 1 > squash 2 > squash 3 > squash 4 >" \ + EXPECT_HEADER_COUNT=4 \ + git rebase -i $base && + test $base = $(git rev-parse HEAD^) && + test 1 = $(git show | grep ONCE | wc -l) && + git checkout to-be-rebased && + git branch -D skip-blank-lines +' + test_expect_success 'squash works as expected' ' for n in one two three four do -- cgit v1.2.3 From 959c0d06eafd7723517c953e80ee1a60881c373b Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Thu, 14 Jan 2010 06:54:48 +0100 Subject: t3404: Test the commit count in commit messages generated by "rebase -i" The first line of commit messages generated for "rebase -i" squash/fixup commits includes a count of the number of commits that are being combined. Add machinery to check that this count is correct, and add such a check to some test cases. Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- t/t3404-rebase-interactive.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 't/t3404-rebase-interactive.sh') diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh index d9382e41d3..0335b781a0 100755 --- a/t/t3404-rebase-interactive.sh +++ b/t/t3404-rebase-interactive.sh @@ -135,7 +135,8 @@ test_expect_success 'squash' ' test_tick && GIT_AUTHOR_NAME="Nitfol" git commit -m "nitfol" file7 && echo "******************************" && - FAKE_LINES="1 squash 2" git rebase -i --onto master HEAD~2 && + FAKE_LINES="1 squash 2" EXPECT_HEADER_COUNT=two \ + git rebase -i --onto master HEAD~2 && test B = $(cat file7) && test $(git rev-parse HEAD^) = $(git rev-parse master) ' @@ -230,6 +231,7 @@ test_expect_success 'verbose flag is heeded, even after --continue' ' test_expect_success 'multi-squash only fires up editor once' ' base=$(git rev-parse HEAD~4) && FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="1 squash 2 squash 3 squash 4" \ + EXPECT_HEADER_COUNT=4 \ git rebase -i $base && test $base = $(git rev-parse HEAD^) && test 1 = $(git show | grep ONCE | wc -l) @@ -239,6 +241,7 @@ test_expect_success 'multi-fixup only fires up editor once' ' git checkout -b multi-fixup E && base=$(git rev-parse HEAD~4) && FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="1 fixup 2 fixup 3 fixup 4" \ + EXPECT_HEADER_COUNT=4 \ git rebase -i $base && test $base = $(git rev-parse HEAD^) && test 1 = $(git show | grep ONCE | wc -l) && @@ -258,6 +261,7 @@ test_expect_success 'squash and fixup generate correct log messages' ' git checkout -b squash-fixup E && base=$(git rev-parse HEAD~4) && FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="1 fixup 2 squash 3 fixup 4" \ + EXPECT_HEADER_COUNT=4 \ git rebase -i $base && git cat-file commit HEAD | sed -e 1,/^\$/d > actual-squash-fixup && test_cmp expect-squash-fixup actual-squash-fixup && @@ -297,7 +301,8 @@ test_expect_success 'squash works as expected' ' git commit -m $n done && one=$(git rev-parse HEAD~3) && - FAKE_LINES="1 squash 3 2" git rebase -i HEAD~3 && + FAKE_LINES="1 squash 3 2" EXPECT_HEADER_COUNT=two \ + git rebase -i HEAD~3 && test $one = $(git rev-parse HEAD~2) ' -- cgit v1.2.3 From 5065ed296abc1c0b66ad7c5e963e048cb90b6ee6 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Thu, 14 Jan 2010 06:54:49 +0100 Subject: rebase -i: Improve consistency of commit count in generated commit messages Use the numeral "2" instead of the word "two" when two commits are being interactively squashed. This makes the treatment consistent with that for higher numbers of commits. Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- t/t3404-rebase-interactive.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 't/t3404-rebase-interactive.sh') diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh index 0335b781a0..05117091eb 100755 --- a/t/t3404-rebase-interactive.sh +++ b/t/t3404-rebase-interactive.sh @@ -135,7 +135,7 @@ test_expect_success 'squash' ' test_tick && GIT_AUTHOR_NAME="Nitfol" git commit -m "nitfol" file7 && echo "******************************" && - FAKE_LINES="1 squash 2" EXPECT_HEADER_COUNT=two \ + FAKE_LINES="1 squash 2" EXPECT_HEADER_COUNT=2 \ git rebase -i --onto master HEAD~2 && test B = $(cat file7) && test $(git rev-parse HEAD^) = $(git rev-parse master) @@ -301,7 +301,7 @@ test_expect_success 'squash works as expected' ' git commit -m $n done && one=$(git rev-parse HEAD~3) && - FAKE_LINES="1 squash 3 2" EXPECT_HEADER_COUNT=two \ + FAKE_LINES="1 squash 3 2" EXPECT_HEADER_COUNT=2 \ git rebase -i HEAD~3 && test $one = $(git rev-parse HEAD~2) ' -- cgit v1.2.3 From a25eb13909088f04f87acec26c522cc555f6b4a9 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Thu, 14 Jan 2010 06:54:55 +0100 Subject: rebase -i: For fixup commands without squashes, do not start editor If the "rebase -i" commands include a series of fixup commands without any squash commands, then commit the combined commit using the commit message of the corresponding "pick" without starting up the commit-message editor. Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- t/t3404-rebase-interactive.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 't/t3404-rebase-interactive.sh') diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh index 05117091eb..175a86c2cb 100755 --- a/t/t3404-rebase-interactive.sh +++ b/t/t3404-rebase-interactive.sh @@ -237,14 +237,13 @@ test_expect_success 'multi-squash only fires up editor once' ' test 1 = $(git show | grep ONCE | wc -l) ' -test_expect_success 'multi-fixup only fires up editor once' ' +test_expect_success 'multi-fixup does not fire up editor' ' git checkout -b multi-fixup E && base=$(git rev-parse HEAD~4) && - FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="1 fixup 2 fixup 3 fixup 4" \ - EXPECT_HEADER_COUNT=4 \ + FAKE_COMMIT_AMEND="NEVER" FAKE_LINES="1 fixup 2 fixup 3 fixup 4" \ git rebase -i $base && test $base = $(git rev-parse HEAD^) && - test 1 = $(git show | grep ONCE | wc -l) && + test 0 = $(git show | grep NEVER | wc -l) && git checkout to-be-rebased && git branch -D multi-fixup ' -- cgit v1.2.3 From 6c4c44c45881260877d7d9fd113fd75b74d7777c Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Thu, 14 Jan 2010 06:54:56 +0100 Subject: t3404: Set up more of the test repo in the "setup" step ...and reuse these pre-created branches in tests rather than creating duplicates. Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- t/t3404-rebase-interactive.sh | 51 ++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 25 deletions(-) (limited to 't/t3404-rebase-interactive.sh') diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh index 175a86c2cb..a119ce0d37 100755 --- a/t/t3404-rebase-interactive.sh +++ b/t/t3404-rebase-interactive.sh @@ -14,15 +14,20 @@ that the result still makes sense. set_fake_editor -# set up two branches like this: +# Set up the repository like this: # -# A - B - C - D - E (master) +# one - two - three - four (conflict-branch) +# / +# A - B - C - D - E (master) +# | \ +# | F - G - H (branch1) +# | \ +# \ I (branch2) # \ -# F - G - H (branch1) -# \ -# I (branch2) +# J - K - L - M (no-conflict-branch) # -# where A, B, D and G touch the same file. +# where A, B, D and G all touch file1, and one, two, three, four all +# touch file "conflict". test_expect_success 'setup' ' test_commit A file1 && @@ -36,9 +41,20 @@ test_expect_success 'setup' ' test_commit H file5 && git checkout -b branch2 F && test_commit I file6 + git checkout -b conflict-branch A && + for n in one two three four + do + test_commit $n conflict + done && + git checkout -b no-conflict-branch A && + for n in J K L M + do + test_commit $n file$n + done ' test_expect_success 'no changes are a nop' ' + git checkout branch2 && git rebase -i F && test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch2" && test $(git rev-parse I) = $(git rev-parse HEAD) @@ -97,7 +113,7 @@ cat > expect2 << EOF D ======= G ->>>>>>> 91201e5... G +>>>>>>> 51047de... G EOF test_expect_success 'stop on conflicting pick' ' @@ -293,12 +309,7 @@ test_expect_success 'squash ignores blank lines' ' ' test_expect_success 'squash works as expected' ' - for n in one two three four - do - echo $n >> file$n && - git add file$n && - git commit -m $n - done && + git checkout -b squash-works no-conflict-branch && one=$(git rev-parse HEAD~3) && FAKE_LINES="1 squash 3 2" EXPECT_HEADER_COUNT=2 \ git rebase -i HEAD~3 && @@ -306,12 +317,7 @@ test_expect_success 'squash works as expected' ' ' test_expect_success 'interrupted squash works as expected' ' - for n in one two three four - do - echo $n >> conflict && - git add conflict && - git commit -m $n - done && + git checkout -b interrupted-squash conflict-branch && one=$(git rev-parse HEAD~3) && ( FAKE_LINES="1 squash 3 2" && @@ -328,12 +334,7 @@ test_expect_success 'interrupted squash works as expected' ' ' test_expect_success 'interrupted squash works as expected (case 2)' ' - for n in one two three four - do - echo $n >> conflict && - git add conflict && - git commit -m $n - done && + git checkout -b interrupted-squash2 conflict-branch && one=$(git rev-parse HEAD~3) && ( FAKE_LINES="3 squash 1 2" && -- cgit v1.2.3 From 6bdcd0d2fcca7c3985a078c8d343a863136fb675 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Thu, 14 Jan 2010 06:54:57 +0100 Subject: rebase -i: Retain user-edited commit messages after squash/fixup conflicts When a squash/fixup fails due to a conflict, the user is required to edit the commit message. Previously, if further squash/fixup commands followed the conflicting squash/fixup, this user-edited message was discarded and a new automatically-generated commit message was suggested. Change the handling of conflicts within squash/fixup command series: Whenever the user is required to intervene, consider the resulting commit to be a new basis for the following squash/fixups and use its commit message in later suggested combined commit messages. Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- t/t3404-rebase-interactive.sh | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 't/t3404-rebase-interactive.sh') diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh index a119ce0d37..4e3513709e 100755 --- a/t/t3404-rebase-interactive.sh +++ b/t/t3404-rebase-interactive.sh @@ -264,6 +264,42 @@ test_expect_success 'multi-fixup does not fire up editor' ' git branch -D multi-fixup ' +test_expect_success 'commit message used after conflict' ' + git checkout -b conflict-fixup conflict-branch && + base=$(git rev-parse HEAD~4) && + ( + FAKE_LINES="1 fixup 3 fixup 4" && + export FAKE_LINES && + test_must_fail git rebase -i $base + ) && + echo three > conflict && + git add conflict && + FAKE_COMMIT_AMEND="ONCE" EXPECT_HEADER_COUNT=2 \ + git rebase --continue && + test $base = $(git rev-parse HEAD^) && + test 1 = $(git show | grep ONCE | wc -l) && + git checkout to-be-rebased && + git branch -D conflict-fixup +' + +test_expect_success 'commit message retained after conflict' ' + git checkout -b conflict-squash conflict-branch && + base=$(git rev-parse HEAD~4) && + ( + FAKE_LINES="1 fixup 3 squash 4" && + export FAKE_LINES && + test_must_fail git rebase -i $base + ) && + echo three > conflict && + git add conflict && + FAKE_COMMIT_AMEND="TWICE" EXPECT_HEADER_COUNT=2 \ + git rebase --continue && + test $base = $(git rev-parse HEAD^) && + test 2 = $(git show | grep TWICE | wc -l) && + git checkout to-be-rebased && + git branch -D conflict-squash +' + cat > expect-squash-fixup << EOF B -- cgit v1.2.3