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