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