]> git.ipfire.org Git - thirdparty/git.git/blob - t/t6040-tracking-info.sh
Merge branch 'ma/doc-markup-fix'
[thirdparty/git.git] / t / t6040-tracking-info.sh
1 #!/bin/sh
2
3 test_description='remote tracking stats'
4
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
8 . ./test-lib.sh
9
10 advance () {
11 echo "$1" >"$1" &&
12 git add "$1" &&
13 test_tick &&
14 git commit -m "$1"
15 }
16
17 test_expect_success setup '
18 advance a &&
19 advance b &&
20 advance c &&
21 git clone . test &&
22 (
23 cd test &&
24 git checkout -b b1 origin &&
25 git reset --hard HEAD^ &&
26 advance d &&
27 git checkout -b b2 origin &&
28 git reset --hard b1 &&
29 git checkout -b b3 origin &&
30 git reset --hard HEAD^ &&
31 git checkout -b b4 origin &&
32 advance e &&
33 advance f &&
34 git checkout -b brokenbase origin &&
35 git checkout -b b5 --track brokenbase &&
36 advance g &&
37 git branch -d brokenbase &&
38 git checkout -b b6 origin
39 ) &&
40 git checkout -b follower --track main &&
41 advance h
42 '
43
44 t6040_script='s/^..\(b.\) *[0-9a-f]* \(.*\)$/\1 \2/p'
45 cat >expect <<\EOF
46 b1 [ahead 1, behind 1] d
47 b2 [ahead 1, behind 1] d
48 b3 [behind 1] b
49 b4 [ahead 2] f
50 b5 [gone] g
51 b6 c
52 EOF
53
54 test_expect_success 'branch -v' '
55 (
56 cd test &&
57 git branch -v
58 ) |
59 sed -n -e "$t6040_script" >actual &&
60 test_cmp expect actual
61 '
62
63 cat >expect <<\EOF
64 b1 [origin/main: ahead 1, behind 1] d
65 b2 [origin/main: ahead 1, behind 1] d
66 b3 [origin/main: behind 1] b
67 b4 [origin/main: ahead 2] f
68 b5 [brokenbase: gone] g
69 b6 [origin/main] c
70 EOF
71
72 test_expect_success 'branch -vv' '
73 (
74 cd test &&
75 git branch -vv
76 ) |
77 sed -n -e "$t6040_script" >actual &&
78 test_cmp expect actual
79 '
80
81 test_expect_success 'checkout (diverged from upstream)' '
82 (
83 cd test && git checkout b1
84 ) >actual &&
85 test_i18ngrep "have 1 and 1 different" actual
86 '
87
88 test_expect_success 'checkout with local tracked branch' '
89 git checkout main &&
90 git checkout follower >actual &&
91 test_i18ngrep "is ahead of" actual
92 '
93
94 test_expect_success 'checkout (upstream is gone)' '
95 (
96 cd test &&
97 git checkout b5
98 ) >actual &&
99 test_i18ngrep "is based on .*, but the upstream is gone." actual
100 '
101
102 test_expect_success 'checkout (up-to-date with upstream)' '
103 (
104 cd test && git checkout b6
105 ) >actual &&
106 test_i18ngrep "Your branch is up to date with .origin/main" actual
107 '
108
109 test_expect_success 'status (diverged from upstream)' '
110 (
111 cd test &&
112 git checkout b1 >/dev/null &&
113 # reports nothing to commit
114 test_must_fail git commit --dry-run
115 ) >actual &&
116 test_i18ngrep "have 1 and 1 different" actual
117 '
118
119 test_expect_success 'status (upstream is gone)' '
120 (
121 cd test &&
122 git checkout b5 >/dev/null &&
123 # reports nothing to commit
124 test_must_fail git commit --dry-run
125 ) >actual &&
126 test_i18ngrep "is based on .*, but the upstream is gone." actual
127 '
128
129 test_expect_success 'status (up-to-date with upstream)' '
130 (
131 cd test &&
132 git checkout b6 >/dev/null &&
133 # reports nothing to commit
134 test_must_fail git commit --dry-run
135 ) >actual &&
136 test_i18ngrep "Your branch is up to date with .origin/main" actual
137 '
138
139 cat >expect <<\EOF
140 ## b1...origin/main [ahead 1, behind 1]
141 EOF
142
143 test_expect_success 'status -s -b (diverged from upstream)' '
144 (
145 cd test &&
146 git checkout b1 >/dev/null &&
147 git status -s -b | head -1
148 ) >actual &&
149 test_cmp expect actual
150 '
151
152 cat >expect <<\EOF
153 ## b1...origin/main [different]
154 EOF
155
156 test_expect_success 'status -s -b --no-ahead-behind (diverged from upstream)' '
157 (
158 cd test &&
159 git checkout b1 >/dev/null &&
160 git status -s -b --no-ahead-behind | head -1
161 ) >actual &&
162 test_cmp expect actual
163 '
164
165 cat >expect <<\EOF
166 ## b1...origin/main [different]
167 EOF
168
169 test_expect_success 'status.aheadbehind=false status -s -b (diverged from upstream)' '
170 (
171 cd test &&
172 git checkout b1 >/dev/null &&
173 git -c status.aheadbehind=false status -s -b | head -1
174 ) >actual &&
175 test_cmp expect actual
176 '
177
178 cat >expect <<\EOF
179 On branch b1
180 Your branch and 'origin/main' have diverged,
181 and have 1 and 1 different commits each, respectively.
182 EOF
183
184 test_expect_success 'status --long --branch' '
185 (
186 cd test &&
187 git checkout b1 >/dev/null &&
188 git status --long -b | head -3
189 ) >actual &&
190 test_cmp expect actual
191 '
192
193 test_expect_success 'status --long --branch' '
194 (
195 cd test &&
196 git checkout b1 >/dev/null &&
197 git -c status.aheadbehind=true status --long -b | head -3
198 ) >actual &&
199 test_cmp expect actual
200 '
201
202 cat >expect <<\EOF
203 On branch b1
204 Your branch and 'origin/main' refer to different commits.
205 EOF
206
207 test_expect_success 'status --long --branch --no-ahead-behind' '
208 (
209 cd test &&
210 git checkout b1 >/dev/null &&
211 git status --long -b --no-ahead-behind | head -2
212 ) >actual &&
213 test_cmp expect actual
214 '
215
216 test_expect_success 'status.aheadbehind=false status --long --branch' '
217 (
218 cd test &&
219 git checkout b1 >/dev/null &&
220 git -c status.aheadbehind=false status --long -b | head -2
221 ) >actual &&
222 test_cmp expect actual
223 '
224
225 cat >expect <<\EOF
226 ## b5...brokenbase [gone]
227 EOF
228
229 test_expect_success 'status -s -b (upstream is gone)' '
230 (
231 cd test &&
232 git checkout b5 >/dev/null &&
233 git status -s -b | head -1
234 ) >actual &&
235 test_cmp expect actual
236 '
237
238 cat >expect <<\EOF
239 ## b6...origin/main
240 EOF
241
242 test_expect_success 'status -s -b (up-to-date with upstream)' '
243 (
244 cd test &&
245 git checkout b6 >/dev/null &&
246 git status -s -b | head -1
247 ) >actual &&
248 test_cmp expect actual
249 '
250
251 test_expect_success 'fail to track lightweight tags' '
252 git checkout main &&
253 git tag light &&
254 test_must_fail git branch --track lighttrack light >actual &&
255 test_i18ngrep ! "set up to track" actual &&
256 test_must_fail git checkout lighttrack
257 '
258
259 test_expect_success 'fail to track annotated tags' '
260 git checkout main &&
261 git tag -m heavy heavy &&
262 test_must_fail git branch --track heavytrack heavy >actual &&
263 test_i18ngrep ! "set up to track" actual &&
264 test_must_fail git checkout heavytrack
265 '
266
267 test_expect_success '--set-upstream-to does not change branch' '
268 git branch from-main main &&
269 git branch --set-upstream-to main from-main &&
270 git branch from-topic_2 main &&
271 test_must_fail git config branch.from-topic_2.merge > actual &&
272 git rev-list from-topic_2 &&
273 git update-ref refs/heads/from-topic_2 from-topic_2^ &&
274 git rev-parse from-topic_2 >expect2 &&
275 git branch --set-upstream-to main from-topic_2 &&
276 git config branch.from-main.merge > actual &&
277 git rev-parse from-topic_2 >actual2 &&
278 grep -q "^refs/heads/main$" actual &&
279 cmp expect2 actual2
280 '
281
282 test_expect_success '--set-upstream-to @{-1}' '
283 git checkout follower &&
284 git checkout from-topic_2 &&
285 git config branch.from-topic_2.merge > expect2 &&
286 git branch --set-upstream-to @{-1} from-main &&
287 git config branch.from-main.merge > actual &&
288 git config branch.from-topic_2.merge > actual2 &&
289 git branch --set-upstream-to follower from-main &&
290 git config branch.from-main.merge > expect &&
291 test_cmp expect2 actual2 &&
292 test_cmp expect actual
293 '
294
295 test_done