init: remove git_init_db_config() while fixing leaks
[git/debian.git] / t / t6040-tracking-info.sh
bloba313849406ddb4b7f104ee06eabc9068d5551425
1 #!/bin/sh
3 test_description='remote tracking stats'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 . ./test-lib.sh
10 advance () {
11 echo "$1" >"$1" &&
12 git add "$1" &&
13 test_tick &&
14 git commit -m "$1"
17 test_expect_success setup '
18 advance a &&
19 advance b &&
20 advance c &&
21 git clone . test &&
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
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
54 test_expect_success 'branch -v' '
56 cd test &&
57 git branch -v
58 ) |
59 sed -n -e "$t6040_script" >actual &&
60 test_cmp expect actual
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
72 test_expect_success 'branch -vv' '
74 cd test &&
75 git branch -vv
76 ) |
77 sed -n -e "$t6040_script" >actual &&
78 test_cmp expect actual
81 test_expect_success 'checkout (diverged from upstream)' '
83 cd test && git checkout b1
84 ) >actual &&
85 test_i18ngrep "have 1 and 1 different" actual
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
94 test_expect_success 'checkout (upstream is gone)' '
96 cd test &&
97 git checkout b5
98 ) >actual &&
99 test_i18ngrep "is based on .*, but the upstream is gone." actual
102 test_expect_success 'checkout (up-to-date with upstream)' '
104 cd test && git checkout b6
105 ) >actual &&
106 test_i18ngrep "Your branch is up to date with .origin/main" actual
109 test_expect_success 'status (diverged from upstream)' '
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
119 test_expect_success 'status (upstream is gone)' '
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
129 test_expect_success 'status (up-to-date with upstream)' '
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
139 cat >expect <<\EOF
140 ## b1...origin/main [ahead 1, behind 1]
143 test_expect_success 'status -s -b (diverged from upstream)' '
145 cd test &&
146 git checkout b1 >/dev/null &&
147 git status -s -b | head -1
148 ) >actual &&
149 test_cmp expect actual
152 cat >expect <<\EOF
153 ## b1...origin/main [different]
156 test_expect_success 'status -s -b --no-ahead-behind (diverged from upstream)' '
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
165 cat >expect <<\EOF
166 ## b1...origin/main [different]
169 test_expect_success 'status.aheadbehind=false status -s -b (diverged from upstream)' '
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
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.
184 test_expect_success 'status --long --branch' '
186 cd test &&
187 git checkout b1 >/dev/null &&
188 git status --long -b | head -3
189 ) >actual &&
190 test_cmp expect actual
193 test_expect_success 'status --long --branch' '
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
202 cat >expect <<\EOF
203 On branch b1
204 Your branch and 'origin/main' refer to different commits.
207 test_expect_success 'status --long --branch --no-ahead-behind' '
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
216 test_expect_success 'status.aheadbehind=false status --long --branch' '
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
225 cat >expect <<\EOF
226 ## b5...brokenbase [gone]
229 test_expect_success 'status -s -b (upstream is gone)' '
231 cd test &&
232 git checkout b5 >/dev/null &&
233 git status -s -b | head -1
234 ) >actual &&
235 test_cmp expect actual
238 cat >expect <<\EOF
239 ## b6...origin/main
242 test_expect_success 'status -s -b (up-to-date with upstream)' '
244 cd test &&
245 git checkout b6 >/dev/null &&
246 git status -s -b | head -1
247 ) >actual &&
248 test_cmp expect actual
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
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
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
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
295 test_done