diff options
Diffstat (limited to 't/t3404-rebase-interactive.sh')
-rwxr-xr-x | t/t3404-rebase-interactive.sh | 197 |
1 files changed, 125 insertions, 72 deletions
diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh index 4a7d21f898..66bcbbf952 100755 --- a/t/t3404-rebase-interactive.sh +++ b/t/t3404-rebase-interactive.sh @@ -12,7 +12,7 @@ Initial setup: one - two - three - four (conflict-branch) / - A - B - C - D - E (master) + A - B - C - D - E (primary) | \ | F - G - H (branch1) | \ @@ -25,11 +25,15 @@ Initial setup: where A, B, D and G all touch file1, and one, two, three, four all touch file "conflict". ' +GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master +export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME + . ./test-lib.sh . "$TEST_DIRECTORY"/lib-rebase.sh test_expect_success 'setup' ' + git switch -C primary && test_commit A file1 && test_commit B file1 && test_commit C file2 && @@ -65,7 +69,7 @@ SHELL= export SHELL test_expect_success 'rebase --keep-empty' ' - git checkout -b emptybranch master && + git checkout -b emptybranch primary && git commit --allow-empty -m "empty" && git rebase --keep-empty -i HEAD~2 && git log --oneline >actual && @@ -82,11 +86,11 @@ test_expect_success 'rebase -i with empty todo list' ' git rebase -i HEAD^ >output 2>&1 ) && tail -n 1 output >actual && # Ignore output about changing todo list - test_i18ncmp expect actual + test_cmp expect actual ' test_expect_success 'rebase -i with the exec command' ' - git checkout master && + git checkout primary && ( set_fake_editor && FAKE_LINES="1 exec_>touch-one @@ -97,18 +101,19 @@ test_expect_success 'rebase -i with the exec command' ' ) && test_path_is_file touch-one && test_path_is_file touch-two && - test_path_is_missing touch-three " (should have stopped before)" && + # Missing because we should have stopped by now. + test_path_is_missing touch-three && test_cmp_rev C HEAD && git rebase --continue && test_path_is_file touch-three && test_path_is_file "touch-file name with spaces" && test_path_is_file touch-after-semicolon && - test_cmp_rev master HEAD && + test_cmp_rev primary HEAD && rm -f touch-* ' test_expect_success 'rebase -i with the exec command runs from tree root' ' - git checkout master && + git checkout primary && mkdir subdir && (cd subdir && set_fake_editor && FAKE_LINES="1 exec_>touch-subdir" \ @@ -121,7 +126,7 @@ test_expect_success 'rebase -i with the exec command runs from tree root' ' test_expect_success 'rebase -i with exec allows git commands in subdirs' ' test_when_finished "rm -rf subdir" && test_when_finished "git rebase --abort ||:" && - git checkout master && + git checkout primary && mkdir subdir && (cd subdir && set_fake_editor && FAKE_LINES="1 x_cd_subdir_&&_git_rev-parse_--is-inside-work-tree" \ @@ -139,13 +144,13 @@ test_expect_success 'rebase -i sets work tree properly' ' ' test_expect_success 'rebase -i with the exec command checks tree cleanness' ' - git checkout master && + git checkout primary && ( set_fake_editor && test_must_fail env FAKE_LINES="exec_echo_foo_>file1 1" \ git rebase -i HEAD^ ) && - test_cmp_rev master^ HEAD && + test_cmp_rev primary^ HEAD && git reset --hard && git rebase --continue ' @@ -154,9 +159,9 @@ test_expect_success 'rebase -x with empty command fails' ' test_when_finished "git rebase --abort ||:" && test_must_fail env git rebase -x "" @ 2>actual && test_write_lines "error: empty exec command" >expected && - test_i18ncmp expected actual && + test_cmp expected actual && test_must_fail env git rebase -x " " @ 2>actual && - test_i18ncmp expected actual + test_cmp expected actual ' test_expect_success 'rebase -x with newline in command fails' ' @@ -164,11 +169,11 @@ test_expect_success 'rebase -x with newline in command fails' ' test_must_fail env git rebase -x "a${LF}b" @ 2>actual && test_write_lines "error: exec commands cannot contain newlines" \ >expected && - test_i18ncmp expected actual + test_cmp expected actual ' test_expect_success 'rebase -i with exec of inexistent command' ' - git checkout master && + git checkout primary && test_when_finished "git rebase --abort" && ( set_fake_editor && @@ -256,11 +261,11 @@ test_expect_success 'stop on conflicting pick' ' D ======= G - >>>>>>> $commit... G + >>>>>>> $commit (G) EOF git tag new-branch1 && - test_must_fail git rebase -i master && - test "$(git rev-parse HEAD~3)" = "$(git rev-parse master)" && + test_must_fail git rebase -i primary && + test "$(git rev-parse HEAD~3)" = "$(git rev-parse primary)" && test_cmp expect .git/rebase-merge/patch && test_cmp expect2 file1 && test "$(git diff --name-status | @@ -287,7 +292,7 @@ test_expect_success 'abort' ' test_expect_success 'abort with error when new base cannot be checked out' ' git rm --cached file1 && git commit -m "remove file in base" && - test_must_fail git rebase -i master > output 2>&1 && + test_must_fail git rebase -i primary > output 2>&1 && test_i18ngrep "The following untracked working tree files would be overwritten by checkout:" \ output && test_i18ngrep "file1" output && @@ -301,7 +306,7 @@ test_expect_success 'retain authorship' ' test_tick && GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" && git tag twerp && - git rebase -i --onto master HEAD^ && + git rebase -i --onto primary HEAD^ && git show HEAD | grep "^Author: Twerp Snog" ' @@ -336,10 +341,10 @@ test_expect_success 'squash' ' ( set_fake_editor && FAKE_LINES="1 squash 2" EXPECT_HEADER_COUNT=2 \ - git rebase -i --onto master HEAD~2 + git rebase -i --onto primary HEAD~2 ) && test B = $(cat file7) && - test_cmp_rev HEAD^ master + test_cmp_rev HEAD^ primary ' test_expect_success 'retain authorship when squashing' ' @@ -366,12 +371,12 @@ test_expect_failure REBASE_P 'exchange two commits with -p' ' ' test_expect_success REBASE_P 'preserve merges with -p' ' - git checkout -b to-be-preserved master^ && + git checkout -b to-be-preserved primary^ && : > unrelated-file && git add unrelated-file && test_tick && git commit -m "unrelated" && - git checkout -b another-branch master && + git checkout -b another-branch primary && echo B > file1 && test_tick && git commit -m J file1 && @@ -394,7 +399,7 @@ test_expect_success REBASE_P 'preserve merges with -p' ' git commit -m M file1 && git checkout -b to-be-rebased && test_tick && - git rebase -i -p --onto branch1 master && + git rebase -i -p --onto branch1 primary && git update-index --refresh && git diff-files --quiet && git diff-index --quiet --cached HEAD -- && @@ -437,7 +442,7 @@ test_expect_success '--continue tries to commit' ' ' test_expect_success 'verbose flag is heeded, even after --continue' ' - git reset --hard master@{1} && + git reset --hard primary@{1} && test_tick && test_must_fail git rebase -v -i --onto new-branch1 HEAD^ && echo resolved > file1 && @@ -446,7 +451,7 @@ test_expect_success 'verbose flag is heeded, even after --continue' ' grep "^ file1 | 2 +-$" output ' -test_expect_success C_LOCALE_OUTPUT 'multi-squash only fires up editor once' ' +test_expect_success 'multi-squash only fires up editor once' ' base=$(git rev-parse HEAD~4) && ( set_fake_editor && @@ -459,7 +464,7 @@ test_expect_success C_LOCALE_OUTPUT 'multi-squash only fires up editor once' ' test 1 = $(git show | grep ONCE | wc -l) ' -test_expect_success C_LOCALE_OUTPUT 'multi-fixup does not fire up editor' ' +test_expect_success 'multi-fixup does not fire up editor' ' git checkout -b multi-fixup E && base=$(git rev-parse HEAD~4) && ( @@ -510,7 +515,7 @@ test_expect_success 'commit message retained after conflict' ' git branch -D conflict-squash ' -test_expect_success C_LOCALE_OUTPUT 'squash and fixup generate correct log messages' ' +test_expect_success 'squash and fixup generate correct log messages' ' cat >expect-squash-fixup <<-\EOF && B @@ -537,7 +542,7 @@ test_expect_success C_LOCALE_OUTPUT 'squash and fixup generate correct log messa git branch -D squash-fixup ' -test_expect_success C_LOCALE_OUTPUT 'squash ignores comments' ' +test_expect_success 'squash ignores comments' ' git checkout -b skip-comments E && base=$(git rev-parse HEAD~4) && ( @@ -553,7 +558,7 @@ test_expect_success C_LOCALE_OUTPUT 'squash ignores comments' ' git branch -D skip-comments ' -test_expect_success C_LOCALE_OUTPUT 'squash ignores blank lines' ' +test_expect_success 'squash ignores blank lines' ' git checkout -b skip-blank-lines E && base=$(git rev-parse HEAD~4) && ( @@ -802,7 +807,7 @@ test_expect_success 'rebase -i continue with unstaged submodule' ' ' test_expect_success 'avoid unnecessary reset' ' - git checkout master && + git checkout primary && git reset --hard && test-tool chmtime =123456789 file3 && git update-index --refresh && @@ -814,14 +819,14 @@ test_expect_success 'avoid unnecessary reset' ' ' test_expect_success 'reword' ' - git checkout -b reword-branch master && + git checkout -b reword-branch primary && ( set_fake_editor && FAKE_LINES="1 2 3 reword 4" FAKE_COMMIT_MESSAGE="E changed" \ git rebase -i A && git show HEAD | grep "E changed" && - test $(git rev-parse master) != $(git rev-parse HEAD) && - test_cmp_rev master^ HEAD^ && + test $(git rev-parse primary) != $(git rev-parse HEAD) && + test_cmp_rev primary^ HEAD^ && FAKE_LINES="1 2 reword 3 4" FAKE_COMMIT_MESSAGE="D changed" \ git rebase -i A && git show HEAD^ | grep "D changed" && @@ -918,7 +923,7 @@ test_expect_success 'rebase-i history with funny messages' ' ' test_expect_success 'prepare for rebase -i --exec' ' - git checkout master && + git checkout primary && git checkout -b execute && test_commit one_exec main.txt one_exec && test_commit two_exec main.txt two_exec && @@ -991,7 +996,7 @@ test_expect_success 'rebase -ix with several instances of --exec' ' test_cmp expected actual ' -test_expect_success C_LOCALE_OUTPUT 'rebase -ix with --autosquash' ' +test_expect_success 'rebase -ix with --autosquash' ' git reset --hard execute && git checkout -b autosquash && echo second >second.txt && @@ -1027,7 +1032,7 @@ test_expect_success 'rebase -i --exec without <CMD>' ' git reset --hard execute && test_must_fail git rebase -i --exec 2>actual && test_i18ngrep "requires a value" actual && - git checkout master + git checkout primary ' test_expect_success 'rebase -i --root re-order and drop commits' ' @@ -1079,7 +1084,7 @@ test_expect_success 'rebase -i --root fixup root commit' ' test_expect_success 'rebase -i --root reword original root commit' ' test_when_finished "test_might_fail git rebase --abort" && - git checkout -b reword-original-root-branch master && + git checkout -b reword-original-root-branch primary && ( set_fake_editor && FAKE_LINES="reword 1 2" FAKE_COMMIT_MESSAGE="A changed" \ @@ -1091,7 +1096,7 @@ test_expect_success 'rebase -i --root reword original root commit' ' test_expect_success 'rebase -i --root reword new root commit' ' test_when_finished "test_might_fail git rebase --abort" && - git checkout -b reword-now-root-branch master && + git checkout -b reword-now-root-branch primary && ( set_fake_editor && FAKE_LINES="reword 3 1" FAKE_COMMIT_MESSAGE="C changed" \ @@ -1132,7 +1137,7 @@ test_expect_success 'rebase -i --root reword root when root has untracked file c test "$(git rev-list --count HEAD)" = 2 ' -test_expect_success C_LOCALE_OUTPUT 'rebase --edit-todo does not work on non-interactive rebase' ' +test_expect_success 'rebase --edit-todo does not work on non-interactive rebase' ' git checkout reword-original-root-branch && git reset --hard && git checkout conflict-branch && @@ -1250,8 +1255,8 @@ test_expect_success 'rebase -i error on commits with \ in message' ' test_expect_code 1 grep " emp" error ' -test_expect_success SHA1 'short SHA-1 setup' ' - test_when_finished "git checkout master" && +test_expect_success 'short commit ID setup' ' + test_when_finished "git checkout primary" && git checkout --orphan collide && git rm -rf . && ( @@ -1262,23 +1267,54 @@ test_expect_success SHA1 'short SHA-1 setup' ' ) ' -test_expect_success SHA1 'short SHA-1 collide' ' - test_when_finished "reset_rebase && git checkout master" && +if test -n "$GIT_TEST_FIND_COLLIDER" +then + author="$(unset test_tick; test_tick; git var GIT_AUTHOR_IDENT)" + committer="$(unset test_tick; test_tick; git var GIT_COMMITTER_IDENT)" + blob="$(git rev-parse collide2:collide)" + from="$(git rev-parse collide1^0)" + repl="commit refs/heads/collider-&\\n" + repl="${repl}author $author\\ncommitter $committer\\n" + repl="${repl}data <<EOF\\ncollide2 &\\nEOF\\n" + repl="${repl}from $from\\nM 100644 $blob collide\\n" + test_seq 1 32768 | sed "s|.*|$repl|" >script && + git fast-import <script && + git pack-refs && + git for-each-ref >refs && + grep "^$(test_oid t3404_collision)" <refs >matches && + cat matches && + test_line_count -gt 2 matches || { + echo "Could not find a collider" >&2 + exit 1 + } +fi + +test_expect_success 'short commit ID collide' ' + test_oid_cache <<-EOF && + # collision-related constants + t3404_collision sha1:6bcd + t3404_collision sha256:0161 + t3404_collider sha1:ac4f2ee + t3404_collider sha256:16697 + EOF + test_when_finished "reset_rebase && git checkout primary" && git checkout collide && - colliding_sha1=6bcda37 && - test $colliding_sha1 = "$(git rev-parse HEAD | cut -c 1-7)" && + colliding_id=$(test_oid t3404_collision) && + hexsz=$(test_oid hexsz) && + test $colliding_id = "$(git rev-parse HEAD | cut -c 1-4)" && + test_config core.abbrev 4 && ( unset test_tick && test_tick && set_fake_editor && - FAKE_COMMIT_MESSAGE="collide2 ac4f2ee" \ + FAKE_COMMIT_MESSAGE="collide2 $(test_oid t3404_collider)" \ FAKE_LINES="reword 1 break 2" git rebase -i HEAD~2 && - test $colliding_sha1 = "$(git rev-parse HEAD | cut -c 1-7)" && - grep "^pick $colliding_sha1 " \ + test $colliding_id = "$(git rev-parse HEAD | cut -c 1-4)" && + grep "^pick $colliding_id " \ .git/rebase-merge/git-rebase-todo.tmp && - grep "^pick [0-9a-f]\{40\}" \ + grep "^pick [0-9a-f]\{$hexsz\}" \ .git/rebase-merge/git-rebase-todo && - grep "^pick [0-9a-f]\{40\}" \ + grep "^pick [0-9a-f]\{$hexsz\}" \ .git/rebase-merge/git-rebase-todo.backup && git rebase --continue ) && @@ -1385,11 +1421,11 @@ test_expect_success 'rebase --continue removes CHERRY_PICK_HEAD' ' rebase_setup_and_clean () { test_when_finished " - git checkout master && + git checkout primary && test_might_fail git branch -D $1 && test_might_fail git rebase --abort " && - git checkout -b $1 ${2:-master} + git checkout -b $1 ${2:-primary} } test_expect_success 'drop' ' @@ -1420,7 +1456,7 @@ test_expect_success 'rebase -i respects rebase.missingCommitsCheck = warn' ' cat >expect <<-EOF && Warning: some commits may have been dropped accidentally. Dropped commits (newer to older): - - $(git rev-list --pretty=oneline --abbrev-commit -1 master) + - $(git rev-list --pretty=oneline --abbrev-commit -1 primary) To avoid this message, use "drop" to explicitly remove a commit. EOF test_config rebase.missingCommitsCheck warn && @@ -1430,7 +1466,7 @@ test_expect_success 'rebase -i respects rebase.missingCommitsCheck = warn' ' FAKE_LINES="1 2 3 4" git rebase -i --root 2>actual.2 ) && head -n4 actual.2 >actual && - test_i18ncmp expect actual && + test_cmp expect actual && test D = $(git cat-file commit HEAD | sed -ne \$p) ' @@ -1438,8 +1474,8 @@ test_expect_success 'rebase -i respects rebase.missingCommitsCheck = error' ' cat >expect <<-EOF && Warning: some commits may have been dropped accidentally. Dropped commits (newer to older): - - $(git rev-list --pretty=oneline --abbrev-commit -1 master) - - $(git rev-list --pretty=oneline --abbrev-commit -1 master~2) + - $(git rev-list --pretty=oneline --abbrev-commit -1 primary) + - $(git rev-list --pretty=oneline --abbrev-commit -1 primary~2) To avoid this message, use "drop" to explicitly remove a commit. Use '\''git config rebase.missingCommitsCheck'\'' to change the level of warnings. @@ -1454,7 +1490,7 @@ test_expect_success 'rebase -i respects rebase.missingCommitsCheck = error' ' set_fake_editor && test_must_fail env FAKE_LINES="1 2 4" \ git rebase -i --root 2>actual && - test_i18ncmp expect actual && + test_cmp expect actual && cp .git/rebase-merge/git-rebase-todo.backup \ .git/rebase-merge/git-rebase-todo && FAKE_LINES="1 2 drop 3 4 drop 5" git rebase --edit-todo @@ -1481,11 +1517,11 @@ test_expect_success 'rebase --edit-todo respects rebase.missingCommitsCheck = ig test_expect_success 'rebase --edit-todo respects rebase.missingCommitsCheck = warn' ' cat >expect <<-EOF && - error: invalid line 1: badcmd $(git rev-list --pretty=oneline --abbrev-commit -1 master~4) + error: invalid line 1: badcmd $(git rev-list --pretty=oneline --abbrev-commit -1 primary~4) Warning: some commits may have been dropped accidentally. Dropped commits (newer to older): - - $(git rev-list --pretty=oneline --abbrev-commit -1 master) - - $(git rev-list --pretty=oneline --abbrev-commit -1 master~4) + - $(git rev-list --pretty=oneline --abbrev-commit -1 primary) + - $(git rev-list --pretty=oneline --abbrev-commit -1 primary~4) To avoid this message, use "drop" to explicitly remove a commit. EOF head -n4 expect >expect.2 && @@ -1500,11 +1536,11 @@ test_expect_success 'rebase --edit-todo respects rebase.missingCommitsCheck = wa cp .git/rebase-merge/git-rebase-todo.backup orig && FAKE_LINES="2 3 4" git rebase --edit-todo 2>actual.2 && head -n6 actual.2 >actual && - test_i18ncmp expect actual && + test_cmp expect actual && cp orig .git/rebase-merge/git-rebase-todo && FAKE_LINES="1 2 3 4" git rebase --edit-todo 2>actual.2 && head -n4 actual.2 >actual && - test_i18ncmp expect.3 actual && + test_cmp expect.3 actual && git rebase --continue 2>actual ) && test D = $(git cat-file commit HEAD | sed -ne \$p) && @@ -1515,11 +1551,11 @@ test_expect_success 'rebase --edit-todo respects rebase.missingCommitsCheck = wa test_expect_success 'rebase --edit-todo respects rebase.missingCommitsCheck = error' ' cat >expect <<-EOF && - error: invalid line 1: badcmd $(git rev-list --pretty=oneline --abbrev-commit -1 master~4) + error: invalid line 1: badcmd $(git rev-list --pretty=oneline --abbrev-commit -1 primary~4) Warning: some commits may have been dropped accidentally. Dropped commits (newer to older): - - $(git rev-list --pretty=oneline --abbrev-commit -1 master) - - $(git rev-list --pretty=oneline --abbrev-commit -1 master~4) + - $(git rev-list --pretty=oneline --abbrev-commit -1 primary) + - $(git rev-list --pretty=oneline --abbrev-commit -1 primary~4) To avoid this message, use "drop" to explicitly remove a commit. Use '\''git config rebase.missingCommitsCheck'\'' to change the level of warnings. @@ -1540,16 +1576,16 @@ test_expect_success 'rebase --edit-todo respects rebase.missingCommitsCheck = er cp .git/rebase-merge/git-rebase-todo.backup orig && test_must_fail env FAKE_LINES="2 3 4" \ git rebase --edit-todo 2>actual && - test_i18ncmp expect actual && + test_cmp expect actual && test_must_fail git rebase --continue 2>actual && - test_i18ncmp expect.2 actual && + test_cmp expect.2 actual && test_must_fail git rebase --edit-todo && cp orig .git/rebase-merge/git-rebase-todo && test_must_fail env FAKE_LINES="1 2 3 4" \ git rebase --edit-todo 2>actual && - test_i18ncmp expect.3 actual && + test_cmp expect.3 actual && test_must_fail git rebase --continue 2>actual && - test_i18ncmp expect.3 actual && + test_cmp expect.3 actual && cp orig .git/rebase-merge/git-rebase-todo && FAKE_LINES="1 2 3 4 drop 5" git rebase --edit-todo && git rebase --continue 2>actual @@ -1604,7 +1640,7 @@ test_expect_success 'respects rebase.abbreviateCommands with fixup, squash and e ( set_cat_todo_editor && test_must_fail git rebase -i --exec "git show HEAD" \ - --autosquash master >actual + --autosquash primary >actual ) && test_cmp expected actual ' @@ -1615,7 +1651,7 @@ test_expect_success 'static check of bad command' ' set_fake_editor && test_must_fail env FAKE_LINES="1 2 3 bad 4 5" \ git rebase -i --root 2>actual && - test_i18ngrep "badcmd $(git rev-list --oneline -1 master~1)" \ + test_i18ngrep "badcmd $(git rev-list --oneline -1 primary~1)" \ actual && test_i18ngrep "You can fix this with .git rebase --edit-todo.." \ actual && @@ -1760,6 +1796,23 @@ test_expect_success 'correct error message for commit --amend after empty pick' test_i18ngrep "middle of a rebase -- cannot amend." err ' +test_expect_success 'todo has correct onto hash' ' + GIT_SEQUENCE_EDITOR=cat git rebase -i no-conflict-branch~4 no-conflict-branch >actual && + onto=$(git rev-parse --short HEAD~4) && + test_i18ngrep "^# Rebase ..* onto $onto" actual +' + +test_expect_success 'ORIG_HEAD is updated correctly' ' + test_when_finished "git checkout primary && git branch -D test-orig-head" && + git checkout -b test-orig-head A && + git commit --allow-empty -m A1 && + git commit --allow-empty -m A2 && + git commit --allow-empty -m A3 && + git commit --allow-empty -m A4 && + git rebase primary && + test_cmp_rev ORIG_HEAD test-orig-head@{1} +' + # This must be the last test in this file test_expect_success '$EDITOR and friends are unchanged' ' test_editor_unchanged |