Junio C Hamano | c0234b2 | 2008-07-03 12:09:48 -0700 | [diff] [blame] | 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 ' |
Jeff King | e6821d0 | 2015-03-25 01:29:52 -0400 | [diff] [blame] | 15 | advance a && |
| 16 | advance b && |
| 17 | advance c && |
Junio C Hamano | c0234b2 | 2008-07-03 12:09:48 -0700 | [diff] [blame] | 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 && |
Jiang Xin | f2e0873 | 2013-08-26 15:02:48 +0800 | [diff] [blame] | 30 | advance f && |
| 31 | git checkout -b brokenbase origin && |
| 32 | git checkout -b b5 --track brokenbase && |
| 33 | advance g && |
Jiang Xin | f223459 | 2013-08-26 15:02:49 +0800 | [diff] [blame] | 34 | git branch -d brokenbase && |
| 35 | git checkout -b b6 origin |
Michael J Gruber | 57dac0b | 2009-03-26 21:53:24 +0100 | [diff] [blame] | 36 | ) && |
| 37 | git checkout -b follower --track master && |
Jiang Xin | f2e0873 | 2013-08-26 15:02:48 +0800 | [diff] [blame] | 38 | advance h |
Junio C Hamano | c0234b2 | 2008-07-03 12:09:48 -0700 | [diff] [blame] | 39 | ' |
| 40 | |
Torstein Hegge | 6b364d4 | 2013-11-14 19:18:01 +0100 | [diff] [blame] | 41 | script='s/^..\(b.\) *[0-9a-f]* \(.*\)$/\1 \2/p' |
Junio C Hamano | c0234b2 | 2008-07-03 12:09:48 -0700 | [diff] [blame] | 42 | cat >expect <<\EOF |
Torstein Hegge | 6b364d4 | 2013-11-14 19:18:01 +0100 | [diff] [blame] | 43 | b1 [ahead 1, behind 1] d |
| 44 | b2 [ahead 1, behind 1] d |
| 45 | b3 [behind 1] b |
| 46 | b4 [ahead 2] f |
| 47 | b5 g |
| 48 | b6 c |
Junio C Hamano | c0234b2 | 2008-07-03 12:09:48 -0700 | [diff] [blame] | 49 | EOF |
| 50 | |
Junio C Hamano | b3e1900 | 2011-04-12 16:33:39 -0700 | [diff] [blame] | 51 | test_expect_success 'branch -v' ' |
Junio C Hamano | c0234b2 | 2008-07-03 12:09:48 -0700 | [diff] [blame] | 52 | ( |
| 53 | cd test && |
| 54 | git branch -v |
| 55 | ) | |
| 56 | sed -n -e "$script" >actual && |
Junio C Hamano | b3e1900 | 2011-04-12 16:33:39 -0700 | [diff] [blame] | 57 | test_i18ncmp expect actual |
Junio C Hamano | c0234b2 | 2008-07-03 12:09:48 -0700 | [diff] [blame] | 58 | ' |
| 59 | |
Michael J Gruber | afc1692 | 2011-08-26 16:05:11 +0200 | [diff] [blame] | 60 | cat >expect <<\EOF |
Torstein Hegge | 6b364d4 | 2013-11-14 19:18:01 +0100 | [diff] [blame] | 61 | b1 [origin/master: ahead 1, behind 1] d |
| 62 | b2 [origin/master: ahead 1, behind 1] d |
| 63 | b3 [origin/master: behind 1] b |
| 64 | b4 [origin/master: ahead 2] f |
| 65 | b5 [brokenbase: gone] g |
| 66 | b6 [origin/master] c |
Michael J Gruber | afc1692 | 2011-08-26 16:05:11 +0200 | [diff] [blame] | 67 | EOF |
| 68 | |
| 69 | test_expect_success 'branch -vv' ' |
| 70 | ( |
| 71 | cd test && |
| 72 | git branch -vv |
| 73 | ) | |
| 74 | sed -n -e "$script" >actual && |
| 75 | test_i18ncmp expect actual |
| 76 | ' |
| 77 | |
Jiang Xin | f2e0873 | 2013-08-26 15:02:48 +0800 | [diff] [blame] | 78 | test_expect_success 'checkout (diverged from upstream)' ' |
Junio C Hamano | c0234b2 | 2008-07-03 12:09:48 -0700 | [diff] [blame] | 79 | ( |
| 80 | cd test && git checkout b1 |
| 81 | ) >actual && |
Jonathan Nieder | 76642cc | 2012-04-13 23:45:31 -0500 | [diff] [blame] | 82 | test_i18ngrep "have 1 and 1 different" actual |
Junio C Hamano | c0234b2 | 2008-07-03 12:09:48 -0700 | [diff] [blame] | 83 | ' |
| 84 | |
Michael J Gruber | 5e6e2b4 | 2009-04-01 23:42:49 +0200 | [diff] [blame] | 85 | test_expect_success 'checkout with local tracked branch' ' |
Michael J Gruber | 57dac0b | 2009-03-26 21:53:24 +0100 | [diff] [blame] | 86 | git checkout master && |
Jonathan Nieder | a48fcd8 | 2010-10-30 20:46:54 -0500 | [diff] [blame] | 87 | git checkout follower >actual && |
Jonathan Nieder | 76642cc | 2012-04-13 23:45:31 -0500 | [diff] [blame] | 88 | test_i18ngrep "is ahead of" actual |
Michael J Gruber | 57dac0b | 2009-03-26 21:53:24 +0100 | [diff] [blame] | 89 | ' |
| 90 | |
Jiang Xin | f2e0873 | 2013-08-26 15:02:48 +0800 | [diff] [blame] | 91 | test_expect_success 'checkout (upstream is gone)' ' |
| 92 | ( |
| 93 | cd test && |
| 94 | git checkout b5 |
| 95 | ) >actual && |
| 96 | test_i18ngrep "is based on .*, but the upstream is gone." actual |
| 97 | ' |
| 98 | |
Jiang Xin | f223459 | 2013-08-26 15:02:49 +0800 | [diff] [blame] | 99 | test_expect_success 'checkout (up-to-date with upstream)' ' |
| 100 | ( |
| 101 | cd test && git checkout b6 |
| 102 | ) >actual && |
| 103 | test_i18ngrep "Your branch is up-to-date with .origin/master" actual |
| 104 | ' |
| 105 | |
Jiang Xin | f2e0873 | 2013-08-26 15:02:48 +0800 | [diff] [blame] | 106 | test_expect_success 'status (diverged from upstream)' ' |
Junio C Hamano | c0234b2 | 2008-07-03 12:09:48 -0700 | [diff] [blame] | 107 | ( |
| 108 | cd test && |
| 109 | git checkout b1 >/dev/null && |
| 110 | # reports nothing to commit |
Junio C Hamano | 9e4b7ab | 2009-08-15 02:27:39 -0700 | [diff] [blame] | 111 | test_must_fail git commit --dry-run |
Junio C Hamano | c0234b2 | 2008-07-03 12:09:48 -0700 | [diff] [blame] | 112 | ) >actual && |
Jonathan Nieder | 76642cc | 2012-04-13 23:45:31 -0500 | [diff] [blame] | 113 | test_i18ngrep "have 1 and 1 different" actual |
Junio C Hamano | c0234b2 | 2008-07-03 12:09:48 -0700 | [diff] [blame] | 114 | ' |
| 115 | |
Jiang Xin | f2e0873 | 2013-08-26 15:02:48 +0800 | [diff] [blame] | 116 | test_expect_success 'status (upstream is gone)' ' |
| 117 | ( |
| 118 | cd test && |
| 119 | git checkout b5 >/dev/null && |
| 120 | # reports nothing to commit |
| 121 | test_must_fail git commit --dry-run |
| 122 | ) >actual && |
| 123 | test_i18ngrep "is based on .*, but the upstream is gone." actual |
| 124 | ' |
| 125 | |
Jiang Xin | f223459 | 2013-08-26 15:02:49 +0800 | [diff] [blame] | 126 | test_expect_success 'status (up-to-date with upstream)' ' |
| 127 | ( |
| 128 | cd test && |
| 129 | git checkout b6 >/dev/null && |
| 130 | # reports nothing to commit |
| 131 | test_must_fail git commit --dry-run |
| 132 | ) >actual && |
| 133 | test_i18ngrep "Your branch is up-to-date with .origin/master" actual |
| 134 | ' |
| 135 | |
Jiang Xin | f2e0873 | 2013-08-26 15:02:48 +0800 | [diff] [blame] | 136 | cat >expect <<\EOF |
| 137 | ## b1...origin/master [ahead 1, behind 1] |
| 138 | EOF |
| 139 | |
| 140 | test_expect_success 'status -s -b (diverged from upstream)' ' |
| 141 | ( |
| 142 | cd test && |
| 143 | git checkout b1 >/dev/null && |
| 144 | git status -s -b | head -1 |
| 145 | ) >actual && |
| 146 | test_i18ncmp expect actual |
| 147 | ' |
| 148 | |
| 149 | cat >expect <<\EOF |
| 150 | ## b5...brokenbase [gone] |
| 151 | EOF |
| 152 | |
| 153 | test_expect_success 'status -s -b (upstream is gone)' ' |
| 154 | ( |
| 155 | cd test && |
| 156 | git checkout b5 >/dev/null && |
| 157 | git status -s -b | head -1 |
| 158 | ) >actual && |
| 159 | test_i18ncmp expect actual |
| 160 | ' |
| 161 | |
Jiang Xin | f223459 | 2013-08-26 15:02:49 +0800 | [diff] [blame] | 162 | cat >expect <<\EOF |
| 163 | ## b6...origin/master |
| 164 | EOF |
| 165 | |
| 166 | test_expect_success 'status -s -b (up-to-date with upstream)' ' |
| 167 | ( |
| 168 | cd test && |
| 169 | git checkout b6 >/dev/null && |
| 170 | git status -s -b | head -1 |
| 171 | ) >actual && |
| 172 | test_i18ncmp expect actual |
| 173 | ' |
| 174 | |
Johan Herland | 21b5b1e | 2011-02-17 00:12:20 +0100 | [diff] [blame] | 175 | test_expect_success 'fail to track lightweight tags' ' |
Michael J Gruber | 1be570f | 2009-05-11 16:42:53 +0200 | [diff] [blame] | 176 | git checkout master && |
| 177 | git tag light && |
Johan Herland | 21b5b1e | 2011-02-17 00:12:20 +0100 | [diff] [blame] | 178 | test_must_fail git branch --track lighttrack light >actual && |
Jonathan Nieder | 76642cc | 2012-04-13 23:45:31 -0500 | [diff] [blame] | 179 | test_i18ngrep ! "set up to track" actual && |
Johan Herland | 21b5b1e | 2011-02-17 00:12:20 +0100 | [diff] [blame] | 180 | test_must_fail git checkout lighttrack |
Michael J Gruber | 1be570f | 2009-05-11 16:42:53 +0200 | [diff] [blame] | 181 | ' |
Junio C Hamano | c0234b2 | 2008-07-03 12:09:48 -0700 | [diff] [blame] | 182 | |
Johan Herland | 21b5b1e | 2011-02-17 00:12:20 +0100 | [diff] [blame] | 183 | test_expect_success 'fail to track annotated tags' ' |
Michael J Gruber | 1be570f | 2009-05-11 16:42:53 +0200 | [diff] [blame] | 184 | git checkout master && |
| 185 | git tag -m heavy heavy && |
Johan Herland | 21b5b1e | 2011-02-17 00:12:20 +0100 | [diff] [blame] | 186 | test_must_fail git branch --track heavytrack heavy >actual && |
Jonathan Nieder | 76642cc | 2012-04-13 23:45:31 -0500 | [diff] [blame] | 187 | test_i18ngrep ! "set up to track" actual && |
Johan Herland | 21b5b1e | 2011-02-17 00:12:20 +0100 | [diff] [blame] | 188 | test_must_fail git checkout heavytrack |
Michael J Gruber | 1be570f | 2009-05-11 16:42:53 +0200 | [diff] [blame] | 189 | ' |
Ilari Liusvaara | 4fc5006 | 2010-01-18 22:44:11 +0200 | [diff] [blame] | 190 | |
| 191 | test_expect_success 'setup tracking with branch --set-upstream on existing branch' ' |
| 192 | git branch from-master master && |
| 193 | test_must_fail git config branch.from-master.merge > actual && |
| 194 | git branch --set-upstream from-master master && |
| 195 | git config branch.from-master.merge > actual && |
| 196 | grep -q "^refs/heads/master$" actual |
| 197 | ' |
| 198 | |
| 199 | test_expect_success '--set-upstream does not change branch' ' |
| 200 | git branch from-master2 master && |
| 201 | test_must_fail git config branch.from-master2.merge > actual && |
| 202 | git rev-list from-master2 && |
| 203 | git update-ref refs/heads/from-master2 from-master2^ && |
| 204 | git rev-parse from-master2 >expect2 && |
| 205 | git branch --set-upstream from-master2 master && |
| 206 | git config branch.from-master.merge > actual && |
| 207 | git rev-parse from-master2 >actual2 && |
| 208 | grep -q "^refs/heads/master$" actual && |
| 209 | cmp expect2 actual2 |
| 210 | ' |
Michael J Gruber | e9d4f74 | 2011-08-19 13:45:43 +0200 | [diff] [blame] | 211 | |
| 212 | test_expect_success '--set-upstream @{-1}' ' |
| 213 | git checkout from-master && |
| 214 | git checkout from-master2 && |
| 215 | git config branch.from-master2.merge > expect2 && |
| 216 | git branch --set-upstream @{-1} follower && |
| 217 | git config branch.from-master.merge > actual && |
| 218 | git config branch.from-master2.merge > actual2 && |
| 219 | git branch --set-upstream from-master follower && |
| 220 | git config branch.from-master.merge > expect && |
| 221 | test_cmp expect2 actual2 && |
| 222 | test_cmp expect actual |
| 223 | ' |
| 224 | |
Junio C Hamano | c0234b2 | 2008-07-03 12:09:48 -0700 | [diff] [blame] | 225 | test_done |