git-mailinfo documentation: clarify -u/--encoding
[git/git.git] / t / t3400-rebase.sh
CommitLineData
294c695d
AW
1#!/bin/sh
2#
3# Copyright (c) 2005 Amos Waterland
4#
5
c2ca1d79 6test_description='git rebase assorted tests
294c695d 7
c2ca1d79
JH
8This test runs git rebase and checks that the author information is not lost
9among other things.
294c695d
AW
10'
11. ./test-lib.sh
12
0e46e704
BD
13GIT_AUTHOR_EMAIL=bogus_email_address
14export GIT_AUTHOR_EMAIL
294c695d
AW
15
16test_expect_success \
1308c17b 17 'prepare repository with topic branches' \
3ec7371f
JS
18 'git config core.logAllRefUpdates true &&
19 echo First > A &&
5be60078 20 git update-index --add A &&
0cb0e143 21 git commit -m "Add A." &&
294c695d
AW
22 git checkout -b my-topic-branch &&
23 echo Second > B &&
5be60078 24 git update-index --add B &&
0cb0e143 25 git commit -m "Add B." &&
294c695d
AW
26 git checkout -f master &&
27 echo Third >> A &&
5be60078 28 git update-index A &&
0cb0e143 29 git commit -m "Modify A." &&
1308c17b
JS
30 git checkout -b side my-topic-branch &&
31 echo Side >> C &&
32 git add C &&
33 git commit -m "Add C" &&
34 git checkout -b nonlinear my-topic-branch &&
35 echo Edit >> B &&
36 git add B &&
37 git commit -m "Modify B" &&
38 git merge side &&
39 git checkout -b upstream-merged-nonlinear &&
40 git merge master &&
294c695d 41 git checkout -f my-topic-branch &&
1308c17b
JS
42 git tag topic
43'
44
7a7eb517
NTND
45test_expect_success 'rebase on dirty worktree' '
46 echo dirty >> A &&
47 test_must_fail git rebase master'
48
49test_expect_success 'rebase on dirty cache' '
50 git add A &&
51 test_must_fail git rebase master'
52
1308c17b 53test_expect_success 'rebase against master' '
7a7eb517 54 git reset --hard HEAD &&
294c695d
AW
55 git rebase master'
56
7a7eb517 57test_expect_success 'rebase against master twice' '
0e987a12
SB
58 git rebase master >out &&
59 grep "Current branch my-topic-branch is up to date" out
7a7eb517
NTND
60'
61
62test_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
65'
66
67test_expect_success 'rebase against master twice from another branch' '
68 git checkout my-topic-branch^ &&
0e987a12
SB
69 git rebase master my-topic-branch >out &&
70 grep "Current branch my-topic-branch is up to date" out
7a7eb517
NTND
71'
72
73test_expect_success 'rebase fast-forward to master' '
74 git checkout my-topic-branch^ &&
0e987a12
SB
75 git rebase my-topic-branch >out &&
76 grep "Fast-forwarded HEAD to my-topic-branch" out
7a7eb517
NTND
77'
78
41ac414e 79test_expect_success \
294c695d 80 'the rebase operation should not have destroyed author information' \
bbf08124 81 '! (git log | grep "Author:" | grep "<>")'
294c695d 82
2559bff3
JS
83test_expect_success 'HEAD was detached during rebase' '
84 test $(git rev-parse HEAD@{1}) != $(git rev-parse my-topic-branch@{1})
85'
86
1308c17b
JS
87test_expect_success 'rebase after merge master' '
88 git reset --hard topic &&
89 git merge master &&
90 git rebase master &&
bbf08124 91 ! (git show | grep "^Merge:")
1308c17b
JS
92'
93
94test_expect_success 'rebase of history with merges is linearized' '
95 git checkout nonlinear &&
96 test 4 = $(git rev-list master.. | wc -l) &&
97 git rebase master &&
98 test 3 = $(git rev-list master.. | wc -l)
99'
100
101test_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) &&
105 git rebase master &&
106 test 3 = $(git rev-list master.. | wc -l)
107'
108
ece7b749
JS
109test_expect_success 'rebase a single mode change' '
110 git checkout master &&
111 echo 1 > X &&
112 git add X &&
113 test_tick &&
114 git commit -m prepare &&
115 git checkout -b modechange HEAD^ &&
116 echo 1 > X &&
117 git add X &&
1f553918 118 test_chmod +x A &&
ece7b749 119 test_tick &&
1f553918 120 git commit -m modechange &&
ece7b749
JS
121 GIT_TRACE=1 git rebase master
122'
123
3ec7371f
JS
124test_expect_success 'Show verbose error when HEAD could not be detached' '
125 : > B &&
126 test_must_fail git rebase topic 2> output.err > output.out &&
127 grep "Untracked working tree file .B. would be overwritten" output.err
128'
129
0e987a12
SB
130test_expect_success 'rebase -q is quiet' '
131 rm B &&
132 git checkout -b quiet topic &&
133 git rebase -q master > output.out 2>&1 &&
134 test ! -s output.out
135'
136
c2ca1d79
JH
137test_expect_success 'Rebase a commit that sprinkles CRs in' '
138 (
139 echo "One"
140 echo "TwoQ"
141 echo "Three"
142 echo "FQur"
143 echo "Five"
144 ) | q_to_cr >CR &&
145 git add CR &&
146 test_tick &&
147 git commit -a -m "A file with a line with CR" &&
148 git tag file-with-cr &&
149 git checkout HEAD^0 &&
150 git rebase --onto HEAD^^ HEAD^ &&
151 git diff --exit-code file-with-cr:CR HEAD:CR
152'
153
eb2151bb
TR
154test_expect_success 'rebase can copy notes' '
155 git config notes.rewrite.rebase true &&
156 git config notes.rewriteRef "refs/notes/*" &&
157 test_commit n1 &&
158 test_commit n2 &&
159 test_commit n3 &&
160 git notes add -m"a note" n3 &&
161 git rebase --onto n1 n2 &&
162 test "a note" = "$(git notes show HEAD)"
163'
164
165test_expect_success 'rebase -m can copy notes' '
166 git reset --hard n3 &&
167 git rebase -m --onto n1 n2 &&
168 test "a note" = "$(git notes show HEAD)"
169'
170
294c695d 171test_done