branch: report invalid tracking branch as gone
[git/gitweb.git] / t / t6040-tracking-info.sh
blob6f678a4dc27f2983d8613411c3de00068370ddd6
1 #!/bin/sh
3 test_description='remote tracking stats'
5 . ./test-lib.sh
7 advance () {
8 echo "$1" >"$1" &&
9 git add "$1" &&
10 test_tick &&
11 git commit -m "$1"
14 test_expect_success setup '
15 for i in a b c;
17 advance $i || break
18 done &&
19 git clone . test &&
21 cd test &&
22 git checkout -b b1 origin &&
23 git reset --hard HEAD^ &&
24 advance d &&
25 git checkout -b b2 origin &&
26 git reset --hard b1 &&
27 git checkout -b b3 origin &&
28 git reset --hard HEAD^ &&
29 git checkout -b b4 origin &&
30 advance e &&
31 advance f &&
32 git checkout -b brokenbase origin &&
33 git checkout -b b5 --track brokenbase &&
34 advance g &&
35 git branch -d brokenbase
36 ) &&
37 git checkout -b follower --track master &&
38 advance h
41 script='s/^..\(b.\)[ 0-9a-f]*\[\([^]]*\)\].*/\1 \2/p'
42 cat >expect <<\EOF
43 b1 ahead 1, behind 1
44 b2 ahead 1, behind 1
45 b3 behind 1
46 b4 ahead 2
47 EOF
49 test_expect_success 'branch -v' '
51 cd test &&
52 git branch -v
53 ) |
54 sed -n -e "$script" >actual &&
55 test_i18ncmp expect actual
58 cat >expect <<\EOF
59 b1 origin/master: ahead 1, behind 1
60 b2 origin/master: ahead 1, behind 1
61 b3 origin/master: behind 1
62 b4 origin/master: ahead 2
63 b5 brokenbase: gone
64 EOF
66 test_expect_success 'branch -vv' '
68 cd test &&
69 git branch -vv
70 ) |
71 sed -n -e "$script" >actual &&
72 test_i18ncmp expect actual
75 test_expect_success 'checkout (diverged from upstream)' '
77 cd test && git checkout b1
78 ) >actual &&
79 test_i18ngrep "have 1 and 1 different" actual
82 test_expect_success 'checkout with local tracked branch' '
83 git checkout master &&
84 git checkout follower >actual &&
85 test_i18ngrep "is ahead of" actual
88 test_expect_success 'checkout (upstream is gone)' '
90 cd test &&
91 git checkout b5
92 ) >actual &&
93 test_i18ngrep "is based on .*, but the upstream is gone." actual
96 test_expect_success 'status (diverged from upstream)' '
98 cd test &&
99 git checkout b1 >/dev/null &&
100 # reports nothing to commit
101 test_must_fail git commit --dry-run
102 ) >actual &&
103 test_i18ngrep "have 1 and 1 different" actual
106 test_expect_success 'status (upstream is gone)' '
108 cd test &&
109 git checkout b5 >/dev/null &&
110 # reports nothing to commit
111 test_must_fail git commit --dry-run
112 ) >actual &&
113 test_i18ngrep "is based on .*, but the upstream is gone." actual
116 cat >expect <<\EOF
117 ## b1...origin/master [ahead 1, behind 1]
120 test_expect_success 'status -s -b (diverged from upstream)' '
122 cd test &&
123 git checkout b1 >/dev/null &&
124 git status -s -b | head -1
125 ) >actual &&
126 test_i18ncmp expect actual
129 cat >expect <<\EOF
130 ## b5...brokenbase [gone]
133 test_expect_success 'status -s -b (upstream is gone)' '
135 cd test &&
136 git checkout b5 >/dev/null &&
137 git status -s -b | head -1
138 ) >actual &&
139 test_i18ncmp expect actual
142 test_expect_success 'fail to track lightweight tags' '
143 git checkout master &&
144 git tag light &&
145 test_must_fail git branch --track lighttrack light >actual &&
146 test_i18ngrep ! "set up to track" actual &&
147 test_must_fail git checkout lighttrack
150 test_expect_success 'fail to track annotated tags' '
151 git checkout master &&
152 git tag -m heavy heavy &&
153 test_must_fail git branch --track heavytrack heavy >actual &&
154 test_i18ngrep ! "set up to track" actual &&
155 test_must_fail git checkout heavytrack
158 test_expect_success 'setup tracking with branch --set-upstream on existing branch' '
159 git branch from-master master &&
160 test_must_fail git config branch.from-master.merge > actual &&
161 git branch --set-upstream from-master master &&
162 git config branch.from-master.merge > actual &&
163 grep -q "^refs/heads/master$" actual
166 test_expect_success '--set-upstream does not change branch' '
167 git branch from-master2 master &&
168 test_must_fail git config branch.from-master2.merge > actual &&
169 git rev-list from-master2 &&
170 git update-ref refs/heads/from-master2 from-master2^ &&
171 git rev-parse from-master2 >expect2 &&
172 git branch --set-upstream from-master2 master &&
173 git config branch.from-master.merge > actual &&
174 git rev-parse from-master2 >actual2 &&
175 grep -q "^refs/heads/master$" actual &&
176 cmp expect2 actual2
179 test_expect_success '--set-upstream @{-1}' '
180 git checkout from-master &&
181 git checkout from-master2 &&
182 git config branch.from-master2.merge > expect2 &&
183 git branch --set-upstream @{-1} follower &&
184 git config branch.from-master.merge > actual &&
185 git config branch.from-master2.merge > actual2 &&
186 git branch --set-upstream from-master follower &&
187 git config branch.from-master.merge > expect &&
188 test_cmp expect2 actual2 &&
189 test_cmp expect actual
192 test_done