3 # Copyright (c) 2005 Amos Waterland
6 test_description
='git rebase assorted tests
8 This test runs git rebase and checks that the author information is not lost
13 GIT_AUTHOR_EMAIL
=bogus_email_address
14 export GIT_AUTHOR_EMAIL
17 'prepare repository with topic branches' \
18 'git config core.logAllRefUpdates true &&
20 git update-index --add A &&
21 git commit -m "Add A." &&
22 git checkout -b my-topic-branch &&
24 git update-index --add B &&
25 git commit -m "Add B." &&
26 git checkout -f master &&
29 git commit -m "Modify A." &&
30 git checkout -b side my-topic-branch &&
33 git commit -m "Add C" &&
34 git checkout -b nonlinear my-topic-branch &&
37 git commit -m "Modify B" &&
39 git checkout -b upstream-merged-nonlinear &&
41 git checkout -f my-topic-branch &&
45 test_expect_success
'rebase on dirty worktree' '
47 test_must_fail git rebase master'
49 test_expect_success
'rebase on dirty cache' '
51 test_must_fail git rebase master'
53 test_expect_success
'rebase against master' '
54 git reset --hard HEAD &&
57 test_expect_success
'rebase against master twice' '
58 git rebase master >out &&
59 grep "Current branch my-topic-branch is up to date" out
62 test_expect_success
'rebase against master twice with --force' '
63 git rebase --force-rebase master >out &&
64 grep "Current branch my-topic-branch is up to date, rebase forced" out
67 test_expect_success
'rebase against master twice from another branch' '
68 git checkout my-topic-branch^ &&
69 git rebase master my-topic-branch >out &&
70 grep "Current branch my-topic-branch is up to date" out
73 test_expect_success
'rebase fast-forward to master' '
74 git checkout my-topic-branch^ &&
75 git rebase my-topic-branch >out &&
76 grep "Fast-forwarded HEAD to my-topic-branch" out
80 'the rebase operation should not have destroyed author information' \
81 '! (git log | grep "Author:" | grep "<>")'
83 test_expect_success
'HEAD was detached during rebase' '
84 test $(git rev-parse HEAD@{1}) != $(git rev-parse my-topic-branch@{1})
87 test_expect_success
'rebase after merge master' '
88 git reset --hard topic &&
91 ! (git show | grep "^Merge:")
94 test_expect_success
'rebase of history with merges is linearized' '
95 git checkout nonlinear &&
96 test 4 = $(git rev-list master.. | wc -l) &&
98 test 3 = $(git rev-list master.. | wc -l)
101 test_expect_success \
102 'rebase of history with merges after upstream merge is linearized' '
103 git checkout upstream-merged-nonlinear &&
104 test 5 = $(git rev-list master.. | wc -l) &&
106 test 3 = $(git rev-list master.. | wc -l)
109 test_expect_success
'rebase a single mode change' '
110 git checkout master &&
114 git commit -m prepare &&
115 git checkout -b modechange HEAD^ &&
120 git commit -m modechange &&
121 GIT_TRACE=1 git rebase master
124 test_expect_success
'Show verbose error when HEAD could not be detached' '
126 test_must_fail git rebase topic 2> output.err > output.out &&
127 grep "Untracked working tree file .B. would be overwritten" output.err
131 test_expect_success
'dump usage when upstream arg is missing' '
132 git checkout -b usage topic &&
133 test_must_fail git rebase 2>error1 &&
134 grep "[Uu]sage" error1 &&
135 test_must_fail git rebase --abort 2>error2 &&
136 grep "No rebase in progress" error2 &&
137 test_must_fail git rebase --onto master 2>error3 &&
138 grep "[Uu]sage" error3 &&
139 ! grep "can.t shift" error3
142 test_expect_success
'rebase -q is quiet' '
143 git checkout -b quiet topic &&
144 git rebase -q master > output.out 2>&1 &&
148 test_expect_success
'Rebase a commit that sprinkles CRs in' '
158 git commit -a -m "A file with a line with CR" &&
159 git tag file-with-cr &&
160 git checkout HEAD^0 &&
161 git rebase --onto HEAD^^ HEAD^ &&
162 git diff --exit-code file-with-cr:CR HEAD:CR
165 test_expect_success
'rebase can copy notes' '
166 git config notes.rewrite.rebase true &&
167 git config notes.rewriteRef "refs/notes/*" &&
171 git notes add -m"a note" n3 &&
172 git rebase --onto n1 n2 &&
173 test "a note" = "$(git notes show HEAD)"
176 test_expect_success
'rebase -m can copy notes' '
177 git reset --hard n3 &&
178 git rebase -m --onto n1 n2 &&
179 test "a note" = "$(git notes show HEAD)"