]>
Commit | Line | Data |
---|---|---|
c0234b2e JH |
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 | |
57dac0bf MG |
32 | ) && |
33 | git checkout -b follower --track master && | |
34 | advance g | |
c0234b2e JH |
35 | ' |
36 | ||
37 | script='s/^..\(b.\)[ 0-9a-f]*\[\([^]]*\)\].*/\1 \2/p' | |
38 | cat >expect <<\EOF | |
39 | b1 ahead 1, behind 1 | |
40 | b2 ahead 1, behind 1 | |
41 | b3 behind 1 | |
42 | b4 ahead 2 | |
43 | EOF | |
44 | ||
b3e1900a | 45 | test_expect_success 'branch -v' ' |
c0234b2e JH |
46 | ( |
47 | cd test && | |
48 | git branch -v | |
49 | ) | | |
50 | sed -n -e "$script" >actual && | |
b3e1900a | 51 | test_i18ncmp expect actual |
c0234b2e JH |
52 | ' |
53 | ||
afc1692f MG |
54 | cat >expect <<\EOF |
55 | b1 origin/master: ahead 1, behind 1 | |
56 | b2 origin/master: ahead 1, behind 1 | |
57 | b3 origin/master: behind 1 | |
58 | b4 origin/master: ahead 2 | |
59 | EOF | |
60 | ||
61 | test_expect_success 'branch -vv' ' | |
62 | ( | |
63 | cd test && | |
64 | git branch -vv | |
65 | ) | | |
66 | sed -n -e "$script" >actual && | |
67 | test_i18ncmp expect actual | |
68 | ' | |
69 | ||
c0234b2e JH |
70 | test_expect_success 'checkout' ' |
71 | ( | |
72 | cd test && git checkout b1 | |
73 | ) >actual && | |
87539416 | 74 | grep "have 1 and 1 different" actual |
c0234b2e JH |
75 | ' |
76 | ||
5e6e2b48 | 77 | test_expect_success 'checkout with local tracked branch' ' |
57dac0bf | 78 | git checkout master && |
a48fcd83 | 79 | git checkout follower >actual && |
57dac0bf MG |
80 | grep "is ahead of" actual |
81 | ' | |
82 | ||
c0234b2e JH |
83 | test_expect_success 'status' ' |
84 | ( | |
85 | cd test && | |
86 | git checkout b1 >/dev/null && | |
87 | # reports nothing to commit | |
9e4b7ab6 | 88 | test_must_fail git commit --dry-run |
c0234b2e | 89 | ) >actual && |
87539416 | 90 | grep "have 1 and 1 different" actual |
c0234b2e JH |
91 | ' |
92 | ||
21b5b1e8 | 93 | test_expect_success 'fail to track lightweight tags' ' |
1be570f4 MG |
94 | git checkout master && |
95 | git tag light && | |
21b5b1e8 JH |
96 | test_must_fail git branch --track lighttrack light >actual && |
97 | test_must_fail grep "set up to track" actual && | |
98 | test_must_fail git checkout lighttrack | |
1be570f4 | 99 | ' |
c0234b2e | 100 | |
21b5b1e8 | 101 | test_expect_success 'fail to track annotated tags' ' |
1be570f4 MG |
102 | git checkout master && |
103 | git tag -m heavy heavy && | |
21b5b1e8 JH |
104 | test_must_fail git branch --track heavytrack heavy >actual && |
105 | test_must_fail grep "set up to track" actual && | |
106 | test_must_fail git checkout heavytrack | |
1be570f4 | 107 | ' |
4fc50066 IL |
108 | |
109 | test_expect_success 'setup tracking with branch --set-upstream on existing branch' ' | |
110 | git branch from-master master && | |
111 | test_must_fail git config branch.from-master.merge > actual && | |
112 | git branch --set-upstream from-master master && | |
113 | git config branch.from-master.merge > actual && | |
114 | grep -q "^refs/heads/master$" actual | |
115 | ' | |
116 | ||
117 | test_expect_success '--set-upstream does not change branch' ' | |
118 | git branch from-master2 master && | |
119 | test_must_fail git config branch.from-master2.merge > actual && | |
120 | git rev-list from-master2 && | |
121 | git update-ref refs/heads/from-master2 from-master2^ && | |
122 | git rev-parse from-master2 >expect2 && | |
123 | git branch --set-upstream from-master2 master && | |
124 | git config branch.from-master.merge > actual && | |
125 | git rev-parse from-master2 >actual2 && | |
126 | grep -q "^refs/heads/master$" actual && | |
127 | cmp expect2 actual2 | |
128 | ' | |
e9d4f740 MG |
129 | |
130 | test_expect_success '--set-upstream @{-1}' ' | |
131 | git checkout from-master && | |
132 | git checkout from-master2 && | |
133 | git config branch.from-master2.merge > expect2 && | |
134 | git branch --set-upstream @{-1} follower && | |
135 | git config branch.from-master.merge > actual && | |
136 | git config branch.from-master2.merge > actual2 && | |
137 | git branch --set-upstream from-master follower && | |
138 | git config branch.from-master.merge > expect && | |
139 | test_cmp expect2 actual2 && | |
140 | test_cmp expect actual | |
141 | ' | |
142 | ||
c0234b2e | 143 | test_done |