test: remove httpd tests that ask for user
[git] / t / t6040-tracking-info.sh
1 #!/bin/sh
2
3 test_description='remote tracking stats'
4
5 . ./test-lib.sh
6
7 advance () {
8         echo "$1" >"$1" &&
9         git add "$1" &&
10         test_tick &&
11         git commit -m "$1"
12 }
13
14 test_expect_success setup '
15         advance a &&
16         advance b &&
17         advance c &&
18         git clone . test &&
19         (
20                 cd test &&
21                 git checkout -b b1 origin &&
22                 git reset --hard HEAD^ &&
23                 advance d &&
24                 git checkout -b b2 origin &&
25                 git reset --hard b1 &&
26                 git checkout -b b3 origin &&
27                 git reset --hard HEAD^ &&
28                 git checkout -b b4 origin &&
29                 advance e &&
30                 advance f &&
31                 git checkout -b brokenbase origin &&
32                 git checkout -b b5 --track brokenbase &&
33                 advance g &&
34                 git branch -d brokenbase &&
35                 git checkout -b b6 origin &&
36                 git branch -p origin/master &&
37                 git checkout -b b7 origin &&
38                 git branch -p origin/master &&
39                 advance h
40         ) &&
41         git checkout -b follower --track master &&
42         advance h
43 '
44
45 script='s/^..\(b.\) *[0-9a-f]* \(.*\)$/\1 \2/p'
46 cat >expect <<\EOF
47 b1 [origin/master] d
48 b2 [origin/master] d
49 b3 [origin/master] b
50 b4 [origin/master] f
51 b5 [brokenbase] g
52 b6 [origin/master, origin/master] c
53 b7 [origin/master, origin/master *] h
54 EOF
55
56 test_expect_success 'branch -v' '
57         (
58                 cd test &&
59                 git branch -v
60         ) |
61         sed -n -e "$script" >actual &&
62         test_i18ncmp expect actual
63 '
64
65 cat >expect <<\EOF
66 b1 [origin/master: ahead 1, behind 1] d
67 b2 [origin/master: ahead 1, behind 1] d
68 b3 [origin/master: behind 1] b
69 b4 [origin/master: ahead 2] f
70 b5 [brokenbase: gone] g
71 b6 [origin/master, origin/master] c
72 b7 [origin/master, origin/master *: ahead 1] h
73 EOF
74
75 test_expect_success 'branch -vv' '
76         (
77                 cd test &&
78                 git branch -vv
79         ) |
80         sed -n -e "$script" >actual &&
81         test_i18ncmp expect actual
82 '
83
84 test_expect_success 'checkout (diverged from upstream)' '
85         (
86                 cd test && git checkout b1
87         ) >actual &&
88         test_i18ngrep "have 1 and 1 different" actual
89 '
90
91 test_expect_success 'checkout with local tracked branch' '
92         git checkout master &&
93         git checkout follower >actual &&
94         test_i18ngrep "is ahead of" actual
95 '
96
97 test_expect_success 'checkout (upstream is gone)' '
98         (
99                 cd test &&
100                 git checkout b5
101         ) >actual &&
102         test_i18ngrep "is based on .*, but the upstream is gone." actual
103 '
104
105 test_expect_success 'checkout (up-to-date with upstream)' '
106         (
107                 cd test && git checkout b6
108         ) >actual &&
109         test_i18ngrep "Your branch is up-to-date with .origin/master" actual
110 '
111
112 test_expect_success 'status (diverged from upstream)' '
113         (
114                 cd test &&
115                 git checkout b1 >/dev/null &&
116                 # reports nothing to commit
117                 test_must_fail git commit --dry-run
118         ) >actual &&
119         test_i18ngrep "have 1 and 1 different" actual
120 '
121
122 test_expect_success 'status (upstream is gone)' '
123         (
124                 cd test &&
125                 git checkout b5 >/dev/null &&
126                 # reports nothing to commit
127                 test_must_fail git commit --dry-run
128         ) >actual &&
129         test_i18ngrep "is based on .*, but the upstream is gone." actual
130 '
131
132 test_expect_success 'status (up-to-date with upstream)' '
133         (
134                 cd test &&
135                 git checkout b6 >/dev/null &&
136                 # reports nothing to commit
137                 test_must_fail git commit --dry-run
138         ) >actual &&
139         test_i18ngrep "Your branch is up-to-date with .origin/master" actual
140 '
141
142 cat >expect <<\EOF
143 ## b1...origin/master [ahead 1, behind 1]
144 EOF
145
146 test_expect_success 'status -s -b (diverged from upstream)' '
147         (
148                 cd test &&
149                 git checkout b1 >/dev/null &&
150                 git status -s -b | head -1
151         ) >actual &&
152         test_i18ncmp expect actual
153 '
154
155 cat >expect <<\EOF
156 ## b5...brokenbase [gone]
157 EOF
158
159 test_expect_success 'status -s -b (upstream is gone)' '
160         (
161                 cd test &&
162                 git checkout b5 >/dev/null &&
163                 git status -s -b | head -1
164         ) >actual &&
165         test_i18ncmp expect actual
166 '
167
168 cat >expect <<\EOF
169 ## b6...origin/master
170 EOF
171
172 test_expect_success 'status -s -b (up-to-date with upstream)' '
173         (
174                 cd test &&
175                 git checkout b6 >/dev/null &&
176                 git status -s -b | head -1
177         ) >actual &&
178         test_i18ncmp expect actual
179 '
180
181 test_expect_success 'fail to track lightweight tags' '
182         git checkout master &&
183         git tag light &&
184         test_must_fail git branch --track lighttrack light >actual &&
185         test_i18ngrep ! "set up to track" actual &&
186         test_must_fail git checkout lighttrack
187 '
188
189 test_expect_success 'fail to track annotated tags' '
190         git checkout master &&
191         git tag -m heavy heavy &&
192         test_must_fail git branch --track heavytrack heavy >actual &&
193         test_i18ngrep ! "set up to track" actual &&
194         test_must_fail git checkout heavytrack
195 '
196
197 test_expect_success 'setup tracking with branch --set-upstream on existing branch' '
198         git branch from-master master &&
199         test_must_fail git config branch.from-master.merge > actual &&
200         git branch --set-upstream from-master master &&
201         git config branch.from-master.merge > actual &&
202         grep -q "^refs/heads/master$" actual
203 '
204
205 test_expect_success '--set-upstream does not change branch' '
206         git branch from-master2 master &&
207         test_must_fail git config branch.from-master2.merge > actual &&
208         git rev-list from-master2 &&
209         git update-ref refs/heads/from-master2 from-master2^ &&
210         git rev-parse from-master2 >expect2 &&
211         git branch --set-upstream from-master2 master &&
212         git config branch.from-master.merge > actual &&
213         git rev-parse from-master2 >actual2 &&
214         grep -q "^refs/heads/master$" actual &&
215         cmp expect2 actual2
216 '
217
218 test_expect_success '--set-upstream @{-1}' '
219         git checkout from-master &&
220         git checkout from-master2 &&
221         git config branch.from-master2.merge > expect2 &&
222         git branch --set-upstream @{-1} follower &&
223         git config branch.from-master.merge > actual &&
224         git config branch.from-master2.merge > actual2 &&
225         git branch --set-upstream from-master follower &&
226         git config branch.from-master.merge > expect &&
227         test_cmp expect2 actual2 &&
228         test_cmp expect actual
229 '
230
231 test_done