Junio C Hamano | bcdb34f | 2007-06-08 00:43:22 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
Ramkumar Ramachandra | 2ead7a6 | 2013-04-02 13:10:30 +0530 | [diff] [blame] | 3 | test_description='Basic fetch/push functionality. |
| 4 | |
| 5 | This test checks the following functionality: |
| 6 | |
| 7 | * command-line syntax |
| 8 | * refspecs |
| 9 | * fast-forward detection, and overriding it |
| 10 | * configuration |
| 11 | * hooks |
| 12 | * --porcelain output format |
| 13 | * hiderefs |
| 14 | ' |
Junio C Hamano | bcdb34f | 2007-06-08 00:43:22 -0700 | [diff] [blame] | 15 | |
| 16 | . ./test-lib.sh |
| 17 | |
| 18 | D=`pwd` |
| 19 | |
| 20 | mk_empty () { |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 21 | repo_name="$1" |
| 22 | rm -fr "$repo_name" && |
| 23 | mkdir "$repo_name" && |
Junio C Hamano | bcdb34f | 2007-06-08 00:43:22 -0700 | [diff] [blame] | 24 | ( |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 25 | cd "$repo_name" && |
Alex Riesen | 586e4ce | 2007-07-04 14:06:04 +0200 | [diff] [blame] | 26 | git init && |
Junio C Hamano | acd2a45 | 2009-02-11 02:28:03 -0800 | [diff] [blame] | 27 | git config receive.denyCurrentBranch warn && |
Alex Riesen | 586e4ce | 2007-07-04 14:06:04 +0200 | [diff] [blame] | 28 | mv .git/hooks .git/hooks-disabled |
Junio C Hamano | bcdb34f | 2007-06-08 00:43:22 -0700 | [diff] [blame] | 29 | ) |
| 30 | } |
| 31 | |
Junio C Hamano | 6125796 | 2007-06-09 01:23:53 -0700 | [diff] [blame] | 32 | mk_test () { |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 33 | repo_name="$1" |
| 34 | shift |
| 35 | |
| 36 | mk_empty "$repo_name" && |
Junio C Hamano | 6125796 | 2007-06-09 01:23:53 -0700 | [diff] [blame] | 37 | ( |
| 38 | for ref in "$@" |
| 39 | do |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 40 | git push "$repo_name" $the_first_commit:refs/$ref || |
Jonathan Nieder | 5bd81c7 | 2013-03-18 16:14:26 -0700 | [diff] [blame] | 41 | exit |
Junio C Hamano | 6125796 | 2007-06-09 01:23:53 -0700 | [diff] [blame] | 42 | done && |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 43 | cd "$repo_name" && |
Junio C Hamano | 6125796 | 2007-06-09 01:23:53 -0700 | [diff] [blame] | 44 | for ref in "$@" |
| 45 | do |
Jonathan Nieder | 848575d | 2013-03-18 16:13:41 -0700 | [diff] [blame] | 46 | echo "$the_first_commit" >expect && |
| 47 | git show-ref -s --verify refs/$ref >actual && |
| 48 | test_cmp expect actual || |
| 49 | exit |
Junio C Hamano | 6125796 | 2007-06-09 01:23:53 -0700 | [diff] [blame] | 50 | done && |
| 51 | git fsck --full |
| 52 | ) |
| 53 | } |
| 54 | |
Pang Yan Han | 160b81e | 2011-09-28 23:39:35 +0800 | [diff] [blame] | 55 | mk_test_with_hooks() { |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 56 | repo_name=$1 |
Pang Yan Han | 160b81e | 2011-09-28 23:39:35 +0800 | [diff] [blame] | 57 | mk_test "$@" && |
| 58 | ( |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 59 | cd "$repo_name" && |
Pang Yan Han | 160b81e | 2011-09-28 23:39:35 +0800 | [diff] [blame] | 60 | mkdir .git/hooks && |
| 61 | cd .git/hooks && |
| 62 | |
| 63 | cat >pre-receive <<-'EOF' && |
| 64 | #!/bin/sh |
| 65 | cat - >>pre-receive.actual |
| 66 | EOF |
| 67 | |
| 68 | cat >update <<-'EOF' && |
| 69 | #!/bin/sh |
| 70 | printf "%s %s %s\n" "$@" >>update.actual |
| 71 | EOF |
| 72 | |
| 73 | cat >post-receive <<-'EOF' && |
| 74 | #!/bin/sh |
| 75 | cat - >>post-receive.actual |
| 76 | EOF |
| 77 | |
| 78 | cat >post-update <<-'EOF' && |
| 79 | #!/bin/sh |
| 80 | for ref in "$@" |
| 81 | do |
| 82 | printf "%s\n" "$ref" >>post-update.actual |
| 83 | done |
| 84 | EOF |
| 85 | |
| 86 | chmod +x pre-receive update post-receive post-update |
| 87 | ) |
| 88 | } |
| 89 | |
Jeff King | b2dc968 | 2008-11-07 17:20:33 -0500 | [diff] [blame] | 90 | mk_child() { |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 91 | rm -rf "$2" && |
| 92 | git clone "$1" "$2" |
Jeff King | b2dc968 | 2008-11-07 17:20:33 -0500 | [diff] [blame] | 93 | } |
| 94 | |
Junio C Hamano | 6125796 | 2007-06-09 01:23:53 -0700 | [diff] [blame] | 95 | check_push_result () { |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 96 | repo_name="$1" |
| 97 | shift |
| 98 | |
Junio C Hamano | 6125796 | 2007-06-09 01:23:53 -0700 | [diff] [blame] | 99 | ( |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 100 | cd "$repo_name" && |
Jonathan Nieder | 848575d | 2013-03-18 16:13:41 -0700 | [diff] [blame] | 101 | echo "$1" >expect && |
| 102 | shift && |
Junio C Hamano | 6125796 | 2007-06-09 01:23:53 -0700 | [diff] [blame] | 103 | for ref in "$@" |
| 104 | do |
Jonathan Nieder | 848575d | 2013-03-18 16:13:41 -0700 | [diff] [blame] | 105 | git show-ref -s --verify refs/$ref >actual && |
| 106 | test_cmp expect actual || |
| 107 | exit |
Junio C Hamano | 6125796 | 2007-06-09 01:23:53 -0700 | [diff] [blame] | 108 | done && |
| 109 | git fsck --full |
| 110 | ) |
| 111 | } |
| 112 | |
Junio C Hamano | bcdb34f | 2007-06-08 00:43:22 -0700 | [diff] [blame] | 113 | test_expect_success setup ' |
| 114 | |
Jay Soffian | d4785cd | 2010-04-19 18:08:31 -0400 | [diff] [blame] | 115 | >path1 && |
Junio C Hamano | bcdb34f | 2007-06-08 00:43:22 -0700 | [diff] [blame] | 116 | git add path1 && |
| 117 | test_tick && |
| 118 | git commit -a -m repo && |
Junio C Hamano | 6125796 | 2007-06-09 01:23:53 -0700 | [diff] [blame] | 119 | the_first_commit=$(git show-ref -s --verify refs/heads/master) && |
| 120 | |
Jay Soffian | d4785cd | 2010-04-19 18:08:31 -0400 | [diff] [blame] | 121 | >path2 && |
Junio C Hamano | 6125796 | 2007-06-09 01:23:53 -0700 | [diff] [blame] | 122 | git add path2 && |
| 123 | test_tick && |
| 124 | git commit -a -m second && |
Junio C Hamano | bcdb34f | 2007-06-08 00:43:22 -0700 | [diff] [blame] | 125 | the_commit=$(git show-ref -s --verify refs/heads/master) |
| 126 | |
| 127 | ' |
| 128 | |
| 129 | test_expect_success 'fetch without wildcard' ' |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 130 | mk_empty testrepo && |
Junio C Hamano | bcdb34f | 2007-06-08 00:43:22 -0700 | [diff] [blame] | 131 | ( |
| 132 | cd testrepo && |
| 133 | git fetch .. refs/heads/master:refs/remotes/origin/master && |
| 134 | |
Jonathan Nieder | 848575d | 2013-03-18 16:13:41 -0700 | [diff] [blame] | 135 | echo "$the_commit commit refs/remotes/origin/master" >expect && |
| 136 | git for-each-ref refs/remotes/origin >actual && |
| 137 | test_cmp expect actual |
Junio C Hamano | bcdb34f | 2007-06-08 00:43:22 -0700 | [diff] [blame] | 138 | ) |
| 139 | ' |
| 140 | |
| 141 | test_expect_success 'fetch with wildcard' ' |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 142 | mk_empty testrepo && |
Junio C Hamano | bcdb34f | 2007-06-08 00:43:22 -0700 | [diff] [blame] | 143 | ( |
| 144 | cd testrepo && |
| 145 | git config remote.up.url .. && |
| 146 | git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" && |
| 147 | git fetch up && |
| 148 | |
Jonathan Nieder | 848575d | 2013-03-18 16:13:41 -0700 | [diff] [blame] | 149 | echo "$the_commit commit refs/remotes/origin/master" >expect && |
| 150 | git for-each-ref refs/remotes/origin >actual && |
| 151 | test_cmp expect actual |
Junio C Hamano | bcdb34f | 2007-06-08 00:43:22 -0700 | [diff] [blame] | 152 | ) |
| 153 | ' |
| 154 | |
Daniel Barkalow | 55029ae | 2008-02-20 13:43:53 -0500 | [diff] [blame] | 155 | test_expect_success 'fetch with insteadOf' ' |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 156 | mk_empty testrepo && |
Daniel Barkalow | 55029ae | 2008-02-20 13:43:53 -0500 | [diff] [blame] | 157 | ( |
Daniel Barkalow | 60e3aba | 2008-04-12 15:32:00 -0400 | [diff] [blame] | 158 | TRASH=$(pwd)/ && |
Daniel Barkalow | 55029ae | 2008-02-20 13:43:53 -0500 | [diff] [blame] | 159 | cd testrepo && |
Bryan Donlan | f69e836 | 2008-05-04 01:37:59 -0400 | [diff] [blame] | 160 | git config "url.$TRASH.insteadOf" trash/ && |
Daniel Barkalow | 55029ae | 2008-02-20 13:43:53 -0500 | [diff] [blame] | 161 | git config remote.up.url trash/. && |
| 162 | git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" && |
| 163 | git fetch up && |
| 164 | |
Jonathan Nieder | 848575d | 2013-03-18 16:13:41 -0700 | [diff] [blame] | 165 | echo "$the_commit commit refs/remotes/origin/master" >expect && |
| 166 | git for-each-ref refs/remotes/origin >actual && |
| 167 | test_cmp expect actual |
Daniel Barkalow | 55029ae | 2008-02-20 13:43:53 -0500 | [diff] [blame] | 168 | ) |
| 169 | ' |
| 170 | |
Josh Triplett | 1c2eafb | 2009-09-07 01:56:33 -0700 | [diff] [blame] | 171 | test_expect_success 'fetch with pushInsteadOf (should not rewrite)' ' |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 172 | mk_empty testrepo && |
Josh Triplett | 1c2eafb | 2009-09-07 01:56:33 -0700 | [diff] [blame] | 173 | ( |
| 174 | TRASH=$(pwd)/ && |
| 175 | cd testrepo && |
| 176 | git config "url.trash/.pushInsteadOf" "$TRASH" && |
| 177 | git config remote.up.url "$TRASH." && |
| 178 | git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" && |
| 179 | git fetch up && |
| 180 | |
Jonathan Nieder | 848575d | 2013-03-18 16:13:41 -0700 | [diff] [blame] | 181 | echo "$the_commit commit refs/remotes/origin/master" >expect && |
| 182 | git for-each-ref refs/remotes/origin >actual && |
| 183 | test_cmp expect actual |
Josh Triplett | 1c2eafb | 2009-09-07 01:56:33 -0700 | [diff] [blame] | 184 | ) |
| 185 | ' |
| 186 | |
Junio C Hamano | bcdb34f | 2007-06-08 00:43:22 -0700 | [diff] [blame] | 187 | test_expect_success 'push without wildcard' ' |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 188 | mk_empty testrepo && |
Junio C Hamano | bcdb34f | 2007-06-08 00:43:22 -0700 | [diff] [blame] | 189 | |
| 190 | git push testrepo refs/heads/master:refs/remotes/origin/master && |
| 191 | ( |
| 192 | cd testrepo && |
Jonathan Nieder | 848575d | 2013-03-18 16:13:41 -0700 | [diff] [blame] | 193 | echo "$the_commit commit refs/remotes/origin/master" >expect && |
| 194 | git for-each-ref refs/remotes/origin >actual && |
| 195 | test_cmp expect actual |
Junio C Hamano | bcdb34f | 2007-06-08 00:43:22 -0700 | [diff] [blame] | 196 | ) |
| 197 | ' |
| 198 | |
| 199 | test_expect_success 'push with wildcard' ' |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 200 | mk_empty testrepo && |
Junio C Hamano | bcdb34f | 2007-06-08 00:43:22 -0700 | [diff] [blame] | 201 | |
| 202 | git push testrepo "refs/heads/*:refs/remotes/origin/*" && |
| 203 | ( |
| 204 | cd testrepo && |
Jonathan Nieder | 848575d | 2013-03-18 16:13:41 -0700 | [diff] [blame] | 205 | echo "$the_commit commit refs/remotes/origin/master" >expect && |
| 206 | git for-each-ref refs/remotes/origin >actual && |
| 207 | test_cmp expect actual |
Junio C Hamano | bcdb34f | 2007-06-08 00:43:22 -0700 | [diff] [blame] | 208 | ) |
| 209 | ' |
| 210 | |
Daniel Barkalow | 55029ae | 2008-02-20 13:43:53 -0500 | [diff] [blame] | 211 | test_expect_success 'push with insteadOf' ' |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 212 | mk_empty testrepo && |
Bryan Donlan | f69e836 | 2008-05-04 01:37:59 -0400 | [diff] [blame] | 213 | TRASH="$(pwd)/" && |
Jonathan Nieder | 3c69552 | 2013-03-18 16:12:11 -0700 | [diff] [blame] | 214 | test_config "url.$TRASH.insteadOf" trash/ && |
Daniel Barkalow | 55029ae | 2008-02-20 13:43:53 -0500 | [diff] [blame] | 215 | git push trash/testrepo refs/heads/master:refs/remotes/origin/master && |
| 216 | ( |
| 217 | cd testrepo && |
Jonathan Nieder | 848575d | 2013-03-18 16:13:41 -0700 | [diff] [blame] | 218 | echo "$the_commit commit refs/remotes/origin/master" >expect && |
| 219 | git for-each-ref refs/remotes/origin >actual && |
| 220 | test_cmp expect actual |
Daniel Barkalow | 55029ae | 2008-02-20 13:43:53 -0500 | [diff] [blame] | 221 | ) |
| 222 | ' |
| 223 | |
Josh Triplett | 1c2eafb | 2009-09-07 01:56:33 -0700 | [diff] [blame] | 224 | test_expect_success 'push with pushInsteadOf' ' |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 225 | mk_empty testrepo && |
Josh Triplett | 1c2eafb | 2009-09-07 01:56:33 -0700 | [diff] [blame] | 226 | TRASH="$(pwd)/" && |
Jonathan Nieder | 3c69552 | 2013-03-18 16:12:11 -0700 | [diff] [blame] | 227 | test_config "url.$TRASH.pushInsteadOf" trash/ && |
Josh Triplett | 1c2eafb | 2009-09-07 01:56:33 -0700 | [diff] [blame] | 228 | git push trash/testrepo refs/heads/master:refs/remotes/origin/master && |
| 229 | ( |
| 230 | cd testrepo && |
Jonathan Nieder | 848575d | 2013-03-18 16:13:41 -0700 | [diff] [blame] | 231 | echo "$the_commit commit refs/remotes/origin/master" >expect && |
| 232 | git for-each-ref refs/remotes/origin >actual && |
| 233 | test_cmp expect actual |
Josh Triplett | 1c2eafb | 2009-09-07 01:56:33 -0700 | [diff] [blame] | 234 | ) |
| 235 | ' |
| 236 | |
| 237 | test_expect_success 'push with pushInsteadOf and explicit pushurl (pushInsteadOf should not rewrite)' ' |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 238 | mk_empty testrepo && |
Junio C Hamano | 41ae34d | 2013-04-03 09:34:48 -0700 | [diff] [blame] | 239 | test_config "url.trash2/.pushInsteadOf" testrepo/ && |
| 240 | test_config "url.trash3/.pusnInsteadOf" trash/wrong && |
Jonathan Nieder | 3c69552 | 2013-03-18 16:12:11 -0700 | [diff] [blame] | 241 | test_config remote.r.url trash/wrong && |
Junio C Hamano | 41ae34d | 2013-04-03 09:34:48 -0700 | [diff] [blame] | 242 | test_config remote.r.pushurl "testrepo/" && |
Josh Triplett | 1c2eafb | 2009-09-07 01:56:33 -0700 | [diff] [blame] | 243 | git push r refs/heads/master:refs/remotes/origin/master && |
| 244 | ( |
| 245 | cd testrepo && |
Jonathan Nieder | 848575d | 2013-03-18 16:13:41 -0700 | [diff] [blame] | 246 | echo "$the_commit commit refs/remotes/origin/master" >expect && |
| 247 | git for-each-ref refs/remotes/origin >actual && |
| 248 | test_cmp expect actual |
Josh Triplett | 1c2eafb | 2009-09-07 01:56:33 -0700 | [diff] [blame] | 249 | ) |
| 250 | ' |
| 251 | |
Junio C Hamano | 6125796 | 2007-06-09 01:23:53 -0700 | [diff] [blame] | 252 | test_expect_success 'push with matching heads' ' |
| 253 | |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 254 | mk_test testrepo heads/master && |
Junio C Hamano | 0a42ac0 | 2013-01-04 16:08:26 -0800 | [diff] [blame] | 255 | git push testrepo : && |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 256 | check_push_result testrepo $the_commit heads/master |
Junio C Hamano | 6125796 | 2007-06-09 01:23:53 -0700 | [diff] [blame] | 257 | |
| 258 | ' |
| 259 | |
Paolo Bonzini | a83619d | 2008-04-28 11:32:12 -0400 | [diff] [blame] | 260 | test_expect_success 'push with matching heads on the command line' ' |
| 261 | |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 262 | mk_test testrepo heads/master && |
Paolo Bonzini | a83619d | 2008-04-28 11:32:12 -0400 | [diff] [blame] | 263 | git push testrepo : && |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 264 | check_push_result testrepo $the_commit heads/master |
Paolo Bonzini | a83619d | 2008-04-28 11:32:12 -0400 | [diff] [blame] | 265 | |
| 266 | ' |
| 267 | |
| 268 | test_expect_success 'failed (non-fast-forward) push with matching heads' ' |
| 269 | |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 270 | mk_test testrepo heads/master && |
Paolo Bonzini | a83619d | 2008-04-28 11:32:12 -0400 | [diff] [blame] | 271 | git push testrepo : && |
| 272 | git commit --amend -massaged && |
Stephan Beyer | d492b31 | 2008-07-12 17:47:52 +0200 | [diff] [blame] | 273 | test_must_fail git push testrepo && |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 274 | check_push_result testrepo $the_commit heads/master && |
Paolo Bonzini | a83619d | 2008-04-28 11:32:12 -0400 | [diff] [blame] | 275 | git reset --hard $the_commit |
| 276 | |
| 277 | ' |
| 278 | |
| 279 | test_expect_success 'push --force with matching heads' ' |
| 280 | |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 281 | mk_test testrepo heads/master && |
Paolo Bonzini | a83619d | 2008-04-28 11:32:12 -0400 | [diff] [blame] | 282 | git push testrepo : && |
| 283 | git commit --amend -massaged && |
Junio C Hamano | 0a42ac0 | 2013-01-04 16:08:26 -0800 | [diff] [blame] | 284 | git push --force testrepo : && |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 285 | ! check_push_result testrepo $the_commit heads/master && |
Paolo Bonzini | a83619d | 2008-04-28 11:32:12 -0400 | [diff] [blame] | 286 | git reset --hard $the_commit |
| 287 | |
| 288 | ' |
| 289 | |
| 290 | test_expect_success 'push with matching heads and forced update' ' |
| 291 | |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 292 | mk_test testrepo heads/master && |
Paolo Bonzini | a83619d | 2008-04-28 11:32:12 -0400 | [diff] [blame] | 293 | git push testrepo : && |
| 294 | git commit --amend -massaged && |
| 295 | git push testrepo +: && |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 296 | ! check_push_result testrepo $the_commit heads/master && |
Paolo Bonzini | a83619d | 2008-04-28 11:32:12 -0400 | [diff] [blame] | 297 | git reset --hard $the_commit |
| 298 | |
| 299 | ' |
| 300 | |
Junio C Hamano | 6125796 | 2007-06-09 01:23:53 -0700 | [diff] [blame] | 301 | test_expect_success 'push with no ambiguity (1)' ' |
| 302 | |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 303 | mk_test testrepo heads/master && |
Junio C Hamano | 6125796 | 2007-06-09 01:23:53 -0700 | [diff] [blame] | 304 | git push testrepo master:master && |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 305 | check_push_result testrepo $the_commit heads/master |
Junio C Hamano | 6125796 | 2007-06-09 01:23:53 -0700 | [diff] [blame] | 306 | |
| 307 | ' |
| 308 | |
| 309 | test_expect_success 'push with no ambiguity (2)' ' |
| 310 | |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 311 | mk_test testrepo remotes/origin/master && |
Steffen Prohaska | ae36bdc | 2007-11-11 15:01:47 +0100 | [diff] [blame] | 312 | git push testrepo master:origin/master && |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 313 | check_push_result testrepo $the_commit remotes/origin/master |
Junio C Hamano | 6125796 | 2007-06-09 01:23:53 -0700 | [diff] [blame] | 314 | |
| 315 | ' |
| 316 | |
Steffen Prohaska | ae36bdc | 2007-11-11 15:01:47 +0100 | [diff] [blame] | 317 | test_expect_success 'push with colon-less refspec, no ambiguity' ' |
| 318 | |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 319 | mk_test testrepo heads/master heads/t/master && |
Steffen Prohaska | ae36bdc | 2007-11-11 15:01:47 +0100 | [diff] [blame] | 320 | git branch -f t/master master && |
| 321 | git push testrepo master && |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 322 | check_push_result testrepo $the_commit heads/master && |
| 323 | check_push_result testrepo $the_first_commit heads/t/master |
Steffen Prohaska | ae36bdc | 2007-11-11 15:01:47 +0100 | [diff] [blame] | 324 | |
| 325 | ' |
| 326 | |
Junio C Hamano | 6125796 | 2007-06-09 01:23:53 -0700 | [diff] [blame] | 327 | test_expect_success 'push with weak ambiguity (1)' ' |
| 328 | |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 329 | mk_test testrepo heads/master remotes/origin/master && |
Junio C Hamano | 6125796 | 2007-06-09 01:23:53 -0700 | [diff] [blame] | 330 | git push testrepo master:master && |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 331 | check_push_result testrepo $the_commit heads/master && |
| 332 | check_push_result testrepo $the_first_commit remotes/origin/master |
Junio C Hamano | 6125796 | 2007-06-09 01:23:53 -0700 | [diff] [blame] | 333 | |
| 334 | ' |
| 335 | |
| 336 | test_expect_success 'push with weak ambiguity (2)' ' |
| 337 | |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 338 | mk_test testrepo heads/master remotes/origin/master remotes/another/master && |
Junio C Hamano | 6125796 | 2007-06-09 01:23:53 -0700 | [diff] [blame] | 339 | git push testrepo master:master && |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 340 | check_push_result testrepo $the_commit heads/master && |
| 341 | check_push_result testrepo $the_first_commit remotes/origin/master remotes/another/master |
Junio C Hamano | 6125796 | 2007-06-09 01:23:53 -0700 | [diff] [blame] | 342 | |
| 343 | ' |
| 344 | |
Jeff King | 3ef6a1f | 2008-04-23 05:21:45 -0400 | [diff] [blame] | 345 | test_expect_success 'push with ambiguity' ' |
Junio C Hamano | 6125796 | 2007-06-09 01:23:53 -0700 | [diff] [blame] | 346 | |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 347 | mk_test testrepo heads/frotz tags/frotz && |
Jonathan Nieder | 5bd81c7 | 2013-03-18 16:14:26 -0700 | [diff] [blame] | 348 | test_must_fail git push testrepo master:frotz && |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 349 | check_push_result testrepo $the_first_commit heads/frotz tags/frotz |
Junio C Hamano | 1ed10b8 | 2007-06-09 01:37:14 -0700 | [diff] [blame] | 350 | |
| 351 | ' |
| 352 | |
| 353 | test_expect_success 'push with colon-less refspec (1)' ' |
| 354 | |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 355 | mk_test testrepo heads/frotz tags/frotz && |
Junio C Hamano | 1ed10b8 | 2007-06-09 01:37:14 -0700 | [diff] [blame] | 356 | git branch -f frotz master && |
| 357 | git push testrepo frotz && |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 358 | check_push_result testrepo $the_commit heads/frotz && |
| 359 | check_push_result testrepo $the_first_commit tags/frotz |
Junio C Hamano | 1ed10b8 | 2007-06-09 01:37:14 -0700 | [diff] [blame] | 360 | |
| 361 | ' |
| 362 | |
| 363 | test_expect_success 'push with colon-less refspec (2)' ' |
| 364 | |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 365 | mk_test testrepo heads/frotz tags/frotz && |
Junio C Hamano | 1ed10b8 | 2007-06-09 01:37:14 -0700 | [diff] [blame] | 366 | if git show-ref --verify -q refs/heads/frotz |
| 367 | then |
| 368 | git branch -D frotz |
| 369 | fi && |
| 370 | git tag -f frotz && |
Chris Rorvick | dbfeddb | 2012-11-29 19:41:37 -0600 | [diff] [blame] | 371 | git push -f testrepo frotz && |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 372 | check_push_result testrepo $the_commit tags/frotz && |
| 373 | check_push_result testrepo $the_first_commit heads/frotz |
Junio C Hamano | 1ed10b8 | 2007-06-09 01:37:14 -0700 | [diff] [blame] | 374 | |
| 375 | ' |
| 376 | |
| 377 | test_expect_success 'push with colon-less refspec (3)' ' |
| 378 | |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 379 | mk_test testrepo && |
Junio C Hamano | 1ed10b8 | 2007-06-09 01:37:14 -0700 | [diff] [blame] | 380 | if git show-ref --verify -q refs/tags/frotz |
| 381 | then |
| 382 | git tag -d frotz |
| 383 | fi && |
| 384 | git branch -f frotz master && |
| 385 | git push testrepo frotz && |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 386 | check_push_result testrepo $the_commit heads/frotz && |
Brian Gernhardt | 9a3c6f7 | 2007-07-01 11:48:54 -0400 | [diff] [blame] | 387 | test 1 = $( cd testrepo && git show-ref | wc -l ) |
Junio C Hamano | 1ed10b8 | 2007-06-09 01:37:14 -0700 | [diff] [blame] | 388 | ' |
| 389 | |
| 390 | test_expect_success 'push with colon-less refspec (4)' ' |
| 391 | |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 392 | mk_test testrepo && |
Junio C Hamano | 1ed10b8 | 2007-06-09 01:37:14 -0700 | [diff] [blame] | 393 | if git show-ref --verify -q refs/heads/frotz |
| 394 | then |
| 395 | git branch -D frotz |
| 396 | fi && |
| 397 | git tag -f frotz && |
| 398 | git push testrepo frotz && |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 399 | check_push_result testrepo $the_commit tags/frotz && |
Brian Gernhardt | 9a3c6f7 | 2007-07-01 11:48:54 -0400 | [diff] [blame] | 400 | test 1 = $( cd testrepo && git show-ref | wc -l ) |
Junio C Hamano | 1ed10b8 | 2007-06-09 01:37:14 -0700 | [diff] [blame] | 401 | |
Junio C Hamano | 6125796 | 2007-06-09 01:23:53 -0700 | [diff] [blame] | 402 | ' |
| 403 | |
Dmitry Ivankov | 7be8b3b | 2011-06-16 19:42:48 +0600 | [diff] [blame] | 404 | test_expect_success 'push head with non-existent, incomplete dest' ' |
Jeff King | f8aae12 | 2008-04-23 05:16:06 -0400 | [diff] [blame] | 405 | |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 406 | mk_test testrepo && |
Jeff King | f8aae12 | 2008-04-23 05:16:06 -0400 | [diff] [blame] | 407 | git push testrepo master:branch && |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 408 | check_push_result testrepo $the_commit heads/branch |
Jeff King | f8aae12 | 2008-04-23 05:16:06 -0400 | [diff] [blame] | 409 | |
| 410 | ' |
| 411 | |
Dmitry Ivankov | 7be8b3b | 2011-06-16 19:42:48 +0600 | [diff] [blame] | 412 | test_expect_success 'push tag with non-existent, incomplete dest' ' |
Jeff King | f8aae12 | 2008-04-23 05:16:06 -0400 | [diff] [blame] | 413 | |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 414 | mk_test testrepo && |
Jeff King | f8aae12 | 2008-04-23 05:16:06 -0400 | [diff] [blame] | 415 | git tag -f v1.0 && |
| 416 | git push testrepo v1.0:tag && |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 417 | check_push_result testrepo $the_commit tags/tag |
Jeff King | f8aae12 | 2008-04-23 05:16:06 -0400 | [diff] [blame] | 418 | |
| 419 | ' |
| 420 | |
Dmitry Ivankov | 7be8b3b | 2011-06-16 19:42:48 +0600 | [diff] [blame] | 421 | test_expect_success 'push sha1 with non-existent, incomplete dest' ' |
Jeff King | f8aae12 | 2008-04-23 05:16:06 -0400 | [diff] [blame] | 422 | |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 423 | mk_test testrepo && |
Jeff King | f8aae12 | 2008-04-23 05:16:06 -0400 | [diff] [blame] | 424 | test_must_fail git push testrepo `git rev-parse master`:foo |
| 425 | |
| 426 | ' |
| 427 | |
Dmitry Ivankov | 7be8b3b | 2011-06-16 19:42:48 +0600 | [diff] [blame] | 428 | test_expect_success 'push ref expression with non-existent, incomplete dest' ' |
Jeff King | f8aae12 | 2008-04-23 05:16:06 -0400 | [diff] [blame] | 429 | |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 430 | mk_test testrepo && |
Jeff King | f8aae12 | 2008-04-23 05:16:06 -0400 | [diff] [blame] | 431 | test_must_fail git push testrepo master^:branch |
| 432 | |
| 433 | ' |
| 434 | |
Steffen Prohaska | 47d996a | 2007-11-11 15:35:07 +0100 | [diff] [blame] | 435 | test_expect_success 'push with HEAD' ' |
| 436 | |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 437 | mk_test testrepo heads/master && |
Steffen Prohaska | 47d996a | 2007-11-11 15:35:07 +0100 | [diff] [blame] | 438 | git checkout master && |
| 439 | git push testrepo HEAD && |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 440 | check_push_result testrepo $the_commit heads/master |
Steffen Prohaska | 47d996a | 2007-11-11 15:35:07 +0100 | [diff] [blame] | 441 | |
| 442 | ' |
| 443 | |
| 444 | test_expect_success 'push with HEAD nonexisting at remote' ' |
| 445 | |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 446 | mk_test testrepo heads/master && |
Steffen Prohaska | 47d996a | 2007-11-11 15:35:07 +0100 | [diff] [blame] | 447 | git checkout -b local master && |
| 448 | git push testrepo HEAD && |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 449 | check_push_result testrepo $the_commit heads/local |
Steffen Prohaska | 47d996a | 2007-11-11 15:35:07 +0100 | [diff] [blame] | 450 | ' |
| 451 | |
Daniel Barkalow | 9f0ea7e | 2008-02-20 12:54:05 -0500 | [diff] [blame] | 452 | test_expect_success 'push with +HEAD' ' |
| 453 | |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 454 | mk_test testrepo heads/master && |
Daniel Barkalow | 9f0ea7e | 2008-02-20 12:54:05 -0500 | [diff] [blame] | 455 | git checkout master && |
| 456 | git branch -D local && |
| 457 | git checkout -b local && |
| 458 | git push testrepo master local && |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 459 | check_push_result testrepo $the_commit heads/master && |
| 460 | check_push_result testrepo $the_commit heads/local && |
Daniel Barkalow | 9f0ea7e | 2008-02-20 12:54:05 -0500 | [diff] [blame] | 461 | |
| 462 | # Without force rewinding should fail |
| 463 | git reset --hard HEAD^ && |
Stephan Beyer | d492b31 | 2008-07-12 17:47:52 +0200 | [diff] [blame] | 464 | test_must_fail git push testrepo HEAD && |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 465 | check_push_result testrepo $the_commit heads/local && |
Daniel Barkalow | 9f0ea7e | 2008-02-20 12:54:05 -0500 | [diff] [blame] | 466 | |
| 467 | # With force rewinding should succeed |
| 468 | git push testrepo +HEAD && |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 469 | check_push_result testrepo $the_first_commit heads/local |
Daniel Barkalow | 9f0ea7e | 2008-02-20 12:54:05 -0500 | [diff] [blame] | 470 | |
| 471 | ' |
| 472 | |
Dmitry Ivankov | 7be8b3b | 2011-06-16 19:42:48 +0600 | [diff] [blame] | 473 | test_expect_success 'push HEAD with non-existent, incomplete dest' ' |
Jeff King | f8aae12 | 2008-04-23 05:16:06 -0400 | [diff] [blame] | 474 | |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 475 | mk_test testrepo && |
Jeff King | f8aae12 | 2008-04-23 05:16:06 -0400 | [diff] [blame] | 476 | git checkout master && |
| 477 | git push testrepo HEAD:branch && |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 478 | check_push_result testrepo $the_commit heads/branch |
Jeff King | f8aae12 | 2008-04-23 05:16:06 -0400 | [diff] [blame] | 479 | |
| 480 | ' |
| 481 | |
Daniel Barkalow | 9f0ea7e | 2008-02-20 12:54:05 -0500 | [diff] [blame] | 482 | test_expect_success 'push with config remote.*.push = HEAD' ' |
| 483 | |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 484 | mk_test testrepo heads/local && |
Daniel Barkalow | 9f0ea7e | 2008-02-20 12:54:05 -0500 | [diff] [blame] | 485 | git checkout master && |
| 486 | git branch -f local $the_commit && |
| 487 | ( |
| 488 | cd testrepo && |
| 489 | git checkout local && |
| 490 | git reset --hard $the_first_commit |
| 491 | ) && |
Jonathan Nieder | 3c69552 | 2013-03-18 16:12:11 -0700 | [diff] [blame] | 492 | test_config remote.there.url testrepo && |
| 493 | test_config remote.there.push HEAD && |
| 494 | test_config branch.master.remote there && |
Daniel Barkalow | 9f0ea7e | 2008-02-20 12:54:05 -0500 | [diff] [blame] | 495 | git push && |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 496 | check_push_result testrepo $the_commit heads/master && |
| 497 | check_push_result testrepo $the_first_commit heads/local |
Daniel Barkalow | 9f0ea7e | 2008-02-20 12:54:05 -0500 | [diff] [blame] | 498 | ' |
| 499 | |
Ramkumar Ramachandra | 224c217 | 2013-04-02 13:10:33 +0530 | [diff] [blame] | 500 | test_expect_success 'push with remote.pushdefault' ' |
| 501 | mk_test up_repo heads/master && |
| 502 | mk_test down_repo heads/master && |
| 503 | test_config remote.up.url up_repo && |
| 504 | test_config remote.down.url down_repo && |
| 505 | test_config branch.master.remote up && |
| 506 | test_config remote.pushdefault down && |
Junio C Hamano | 54a3c67 | 2013-04-18 11:47:59 -0700 | [diff] [blame] | 507 | test_config push.default matching && |
Ramkumar Ramachandra | 224c217 | 2013-04-02 13:10:33 +0530 | [diff] [blame] | 508 | git push && |
| 509 | check_push_result up_repo $the_first_commit heads/master && |
| 510 | check_push_result down_repo $the_commit heads/master |
Daniel Barkalow | 9f0ea7e | 2008-02-20 12:54:05 -0500 | [diff] [blame] | 511 | ' |
| 512 | |
Michael J Gruber | e1ca424 | 2009-06-09 18:01:35 +0200 | [diff] [blame] | 513 | test_expect_success 'push with config remote.*.pushurl' ' |
| 514 | |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 515 | mk_test testrepo heads/master && |
Michael J Gruber | e1ca424 | 2009-06-09 18:01:35 +0200 | [diff] [blame] | 516 | git checkout master && |
Jonathan Nieder | 3c69552 | 2013-03-18 16:12:11 -0700 | [diff] [blame] | 517 | test_config remote.there.url test2repo && |
| 518 | test_config remote.there.pushurl testrepo && |
Junio C Hamano | 0a42ac0 | 2013-01-04 16:08:26 -0800 | [diff] [blame] | 519 | git push there : && |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 520 | check_push_result testrepo $the_commit heads/master |
Michael J Gruber | e1ca424 | 2009-06-09 18:01:35 +0200 | [diff] [blame] | 521 | ' |
| 522 | |
Ramkumar Ramachandra | 9f765ce | 2013-04-02 13:10:34 +0530 | [diff] [blame] | 523 | test_expect_success 'push with config branch.*.pushremote' ' |
| 524 | mk_test up_repo heads/master && |
| 525 | mk_test side_repo heads/master && |
| 526 | mk_test down_repo heads/master && |
| 527 | test_config remote.up.url up_repo && |
| 528 | test_config remote.pushdefault side_repo && |
| 529 | test_config remote.down.url down_repo && |
| 530 | test_config branch.master.remote up && |
| 531 | test_config branch.master.pushremote down && |
Junio C Hamano | 54a3c67 | 2013-04-18 11:47:59 -0700 | [diff] [blame] | 532 | test_config push.default matching && |
Ramkumar Ramachandra | 9f765ce | 2013-04-02 13:10:34 +0530 | [diff] [blame] | 533 | git push && |
| 534 | check_push_result up_repo $the_first_commit heads/master && |
| 535 | check_push_result side_repo $the_first_commit heads/master && |
| 536 | check_push_result down_repo $the_commit heads/master |
Michael J Gruber | e1ca424 | 2009-06-09 18:01:35 +0200 | [diff] [blame] | 537 | ' |
| 538 | |
Jeff King | 98b406f | 2014-02-24 03:59:03 -0500 | [diff] [blame] | 539 | test_expect_success 'branch.*.pushremote config order is irrelevant' ' |
| 540 | mk_test one_repo heads/master && |
| 541 | mk_test two_repo heads/master && |
| 542 | test_config remote.one.url one_repo && |
| 543 | test_config remote.two.url two_repo && |
| 544 | test_config branch.master.pushremote two_repo && |
| 545 | test_config remote.pushdefault one_repo && |
| 546 | test_config push.default matching && |
| 547 | git push && |
| 548 | check_push_result one_repo $the_first_commit heads/master && |
| 549 | check_push_result two_repo $the_commit heads/master |
| 550 | ' |
| 551 | |
Brian Ewins | 11f2441 | 2007-10-11 20:32:27 +0100 | [diff] [blame] | 552 | test_expect_success 'push with dry-run' ' |
| 553 | |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 554 | mk_test testrepo heads/master && |
Jay Soffian | d4785cd | 2010-04-19 18:08:31 -0400 | [diff] [blame] | 555 | ( |
| 556 | cd testrepo && |
| 557 | old_commit=$(git show-ref -s --verify refs/heads/master) |
| 558 | ) && |
Junio C Hamano | 0a42ac0 | 2013-01-04 16:08:26 -0800 | [diff] [blame] | 559 | git push --dry-run testrepo : && |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 560 | check_push_result testrepo $old_commit heads/master |
Brian Ewins | 11f2441 | 2007-10-11 20:32:27 +0100 | [diff] [blame] | 561 | ' |
| 562 | |
Johannes Schindelin | 28391a8 | 2007-11-29 01:02:53 +0000 | [diff] [blame] | 563 | test_expect_success 'push updates local refs' ' |
| 564 | |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 565 | mk_test testrepo heads/master && |
| 566 | mk_child testrepo child && |
Jay Soffian | d4785cd | 2010-04-19 18:08:31 -0400 | [diff] [blame] | 567 | ( |
| 568 | cd child && |
Jeff King | b2dc968 | 2008-11-07 17:20:33 -0500 | [diff] [blame] | 569 | git pull .. master && |
Johannes Schindelin | 28391a8 | 2007-11-29 01:02:53 +0000 | [diff] [blame] | 570 | git push && |
Jay Soffian | d4785cd | 2010-04-19 18:08:31 -0400 | [diff] [blame] | 571 | test $(git rev-parse master) = \ |
| 572 | $(git rev-parse remotes/origin/master) |
| 573 | ) |
Johannes Schindelin | 28391a8 | 2007-11-29 01:02:53 +0000 | [diff] [blame] | 574 | |
| 575 | ' |
| 576 | |
Clemens Buchacher | 16ed2f4 | 2008-11-05 21:55:54 +0100 | [diff] [blame] | 577 | test_expect_success 'push updates up-to-date local refs' ' |
| 578 | |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 579 | mk_test testrepo heads/master && |
| 580 | mk_child testrepo child1 && |
| 581 | mk_child testrepo child2 && |
Jeff King | b2dc968 | 2008-11-07 17:20:33 -0500 | [diff] [blame] | 582 | (cd child1 && git pull .. master && git push) && |
Jay Soffian | d4785cd | 2010-04-19 18:08:31 -0400 | [diff] [blame] | 583 | ( |
| 584 | cd child2 && |
Clemens Buchacher | 16ed2f4 | 2008-11-05 21:55:54 +0100 | [diff] [blame] | 585 | git pull ../child1 master && |
| 586 | git push && |
Jay Soffian | d4785cd | 2010-04-19 18:08:31 -0400 | [diff] [blame] | 587 | test $(git rev-parse master) = \ |
| 588 | $(git rev-parse remotes/origin/master) |
| 589 | ) |
Clemens Buchacher | 16ed2f4 | 2008-11-05 21:55:54 +0100 | [diff] [blame] | 590 | |
| 591 | ' |
| 592 | |
| 593 | test_expect_success 'push preserves up-to-date packed refs' ' |
| 594 | |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 595 | mk_test testrepo heads/master && |
| 596 | mk_child testrepo child && |
Jay Soffian | d4785cd | 2010-04-19 18:08:31 -0400 | [diff] [blame] | 597 | ( |
| 598 | cd child && |
Clemens Buchacher | 16ed2f4 | 2008-11-05 21:55:54 +0100 | [diff] [blame] | 599 | git push && |
Jay Soffian | d4785cd | 2010-04-19 18:08:31 -0400 | [diff] [blame] | 600 | ! test -f .git/refs/remotes/origin/master |
| 601 | ) |
Clemens Buchacher | 16ed2f4 | 2008-11-05 21:55:54 +0100 | [diff] [blame] | 602 | |
| 603 | ' |
| 604 | |
Johannes Schindelin | 28391a8 | 2007-11-29 01:02:53 +0000 | [diff] [blame] | 605 | test_expect_success 'push does not update local refs on failure' ' |
| 606 | |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 607 | mk_test testrepo heads/master && |
| 608 | mk_child testrepo child && |
Jeff King | b2dc968 | 2008-11-07 17:20:33 -0500 | [diff] [blame] | 609 | mkdir testrepo/.git/hooks && |
bert Dvornik | fc012c2 | 2010-05-20 20:57:52 +0200 | [diff] [blame] | 610 | echo "#!/no/frobnication/today" >testrepo/.git/hooks/pre-receive && |
Jeff King | b2dc968 | 2008-11-07 17:20:33 -0500 | [diff] [blame] | 611 | chmod +x testrepo/.git/hooks/pre-receive && |
Jay Soffian | d4785cd | 2010-04-19 18:08:31 -0400 | [diff] [blame] | 612 | ( |
| 613 | cd child && |
Jeff King | b2dc968 | 2008-11-07 17:20:33 -0500 | [diff] [blame] | 614 | git pull .. master |
Stephan Beyer | d492b31 | 2008-07-12 17:47:52 +0200 | [diff] [blame] | 615 | test_must_fail git push && |
Johannes Schindelin | 28391a8 | 2007-11-29 01:02:53 +0000 | [diff] [blame] | 616 | test $(git rev-parse master) != \ |
Jay Soffian | d4785cd | 2010-04-19 18:08:31 -0400 | [diff] [blame] | 617 | $(git rev-parse remotes/origin/master) |
| 618 | ) |
Johannes Schindelin | 28391a8 | 2007-11-29 01:02:53 +0000 | [diff] [blame] | 619 | |
| 620 | ' |
| 621 | |
| 622 | test_expect_success 'allow deleting an invalid remote ref' ' |
| 623 | |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 624 | mk_test testrepo heads/master && |
Johannes Schindelin | 28391a8 | 2007-11-29 01:02:53 +0000 | [diff] [blame] | 625 | rm -f testrepo/.git/objects/??/* && |
| 626 | git push testrepo :refs/heads/master && |
Stephan Beyer | d492b31 | 2008-07-12 17:47:52 +0200 | [diff] [blame] | 627 | (cd testrepo && test_must_fail git rev-parse --verify refs/heads/master) |
Johannes Schindelin | 28391a8 | 2007-11-29 01:02:53 +0000 | [diff] [blame] | 628 | |
| 629 | ' |
| 630 | |
Pang Yan Han | 160b81e | 2011-09-28 23:39:35 +0800 | [diff] [blame] | 631 | test_expect_success 'pushing valid refs triggers post-receive and post-update hooks' ' |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 632 | mk_test_with_hooks testrepo heads/master heads/next && |
Pang Yan Han | 160b81e | 2011-09-28 23:39:35 +0800 | [diff] [blame] | 633 | orgmaster=$(cd testrepo && git show-ref -s --verify refs/heads/master) && |
| 634 | newmaster=$(git show-ref -s --verify refs/heads/master) && |
| 635 | orgnext=$(cd testrepo && git show-ref -s --verify refs/heads/next) && |
| 636 | newnext=$_z40 && |
| 637 | git push testrepo refs/heads/master:refs/heads/master :refs/heads/next && |
| 638 | ( |
| 639 | cd testrepo/.git && |
| 640 | cat >pre-receive.expect <<-EOF && |
| 641 | $orgmaster $newmaster refs/heads/master |
| 642 | $orgnext $newnext refs/heads/next |
| 643 | EOF |
| 644 | |
| 645 | cat >update.expect <<-EOF && |
| 646 | refs/heads/master $orgmaster $newmaster |
| 647 | refs/heads/next $orgnext $newnext |
| 648 | EOF |
| 649 | |
| 650 | cat >post-receive.expect <<-EOF && |
| 651 | $orgmaster $newmaster refs/heads/master |
| 652 | $orgnext $newnext refs/heads/next |
| 653 | EOF |
| 654 | |
| 655 | cat >post-update.expect <<-EOF && |
| 656 | refs/heads/master |
| 657 | refs/heads/next |
| 658 | EOF |
| 659 | |
| 660 | test_cmp pre-receive.expect pre-receive.actual && |
| 661 | test_cmp update.expect update.actual && |
| 662 | test_cmp post-receive.expect post-receive.actual && |
| 663 | test_cmp post-update.expect post-update.actual |
| 664 | ) |
| 665 | ' |
| 666 | |
| 667 | test_expect_success 'deleting dangling ref triggers hooks with correct args' ' |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 668 | mk_test_with_hooks testrepo heads/master && |
Pang Yan Han | 160b81e | 2011-09-28 23:39:35 +0800 | [diff] [blame] | 669 | rm -f testrepo/.git/objects/??/* && |
| 670 | git push testrepo :refs/heads/master && |
| 671 | ( |
| 672 | cd testrepo/.git && |
| 673 | cat >pre-receive.expect <<-EOF && |
| 674 | $_z40 $_z40 refs/heads/master |
| 675 | EOF |
| 676 | |
| 677 | cat >update.expect <<-EOF && |
| 678 | refs/heads/master $_z40 $_z40 |
| 679 | EOF |
| 680 | |
| 681 | cat >post-receive.expect <<-EOF && |
| 682 | $_z40 $_z40 refs/heads/master |
| 683 | EOF |
| 684 | |
| 685 | cat >post-update.expect <<-EOF && |
| 686 | refs/heads/master |
| 687 | EOF |
| 688 | |
| 689 | test_cmp pre-receive.expect pre-receive.actual && |
| 690 | test_cmp update.expect update.actual && |
| 691 | test_cmp post-receive.expect post-receive.actual && |
| 692 | test_cmp post-update.expect post-update.actual |
| 693 | ) |
| 694 | ' |
| 695 | |
| 696 | test_expect_success 'deletion of a non-existent ref is not fed to post-receive and post-update hooks' ' |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 697 | mk_test_with_hooks testrepo heads/master && |
Pang Yan Han | 160b81e | 2011-09-28 23:39:35 +0800 | [diff] [blame] | 698 | orgmaster=$(cd testrepo && git show-ref -s --verify refs/heads/master) && |
| 699 | newmaster=$(git show-ref -s --verify refs/heads/master) && |
| 700 | git push testrepo master :refs/heads/nonexistent && |
| 701 | ( |
| 702 | cd testrepo/.git && |
| 703 | cat >pre-receive.expect <<-EOF && |
| 704 | $orgmaster $newmaster refs/heads/master |
| 705 | $_z40 $_z40 refs/heads/nonexistent |
| 706 | EOF |
| 707 | |
| 708 | cat >update.expect <<-EOF && |
| 709 | refs/heads/master $orgmaster $newmaster |
| 710 | refs/heads/nonexistent $_z40 $_z40 |
| 711 | EOF |
| 712 | |
| 713 | cat >post-receive.expect <<-EOF && |
| 714 | $orgmaster $newmaster refs/heads/master |
| 715 | EOF |
| 716 | |
| 717 | cat >post-update.expect <<-EOF && |
| 718 | refs/heads/master |
| 719 | EOF |
| 720 | |
| 721 | test_cmp pre-receive.expect pre-receive.actual && |
| 722 | test_cmp update.expect update.actual && |
| 723 | test_cmp post-receive.expect post-receive.actual && |
| 724 | test_cmp post-update.expect post-update.actual |
| 725 | ) |
| 726 | ' |
| 727 | |
| 728 | test_expect_success 'deletion of a non-existent ref alone does trigger post-receive and post-update hooks' ' |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 729 | mk_test_with_hooks testrepo heads/master && |
Pang Yan Han | 160b81e | 2011-09-28 23:39:35 +0800 | [diff] [blame] | 730 | git push testrepo :refs/heads/nonexistent && |
| 731 | ( |
| 732 | cd testrepo/.git && |
| 733 | cat >pre-receive.expect <<-EOF && |
| 734 | $_z40 $_z40 refs/heads/nonexistent |
| 735 | EOF |
| 736 | |
| 737 | cat >update.expect <<-EOF && |
| 738 | refs/heads/nonexistent $_z40 $_z40 |
| 739 | EOF |
| 740 | |
| 741 | test_cmp pre-receive.expect pre-receive.actual && |
| 742 | test_cmp update.expect update.actual && |
| 743 | test_path_is_missing post-receive.actual && |
| 744 | test_path_is_missing post-update.actual |
| 745 | ) |
| 746 | ' |
| 747 | |
| 748 | test_expect_success 'mixed ref updates, deletes, invalid deletes trigger hooks with correct input' ' |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 749 | mk_test_with_hooks testrepo heads/master heads/next heads/pu && |
Pang Yan Han | 160b81e | 2011-09-28 23:39:35 +0800 | [diff] [blame] | 750 | orgmaster=$(cd testrepo && git show-ref -s --verify refs/heads/master) && |
| 751 | newmaster=$(git show-ref -s --verify refs/heads/master) && |
| 752 | orgnext=$(cd testrepo && git show-ref -s --verify refs/heads/next) && |
| 753 | newnext=$_z40 && |
| 754 | orgpu=$(cd testrepo && git show-ref -s --verify refs/heads/pu) && |
| 755 | newpu=$(git show-ref -s --verify refs/heads/master) && |
| 756 | git push testrepo refs/heads/master:refs/heads/master \ |
| 757 | refs/heads/master:refs/heads/pu :refs/heads/next \ |
| 758 | :refs/heads/nonexistent && |
| 759 | ( |
| 760 | cd testrepo/.git && |
| 761 | cat >pre-receive.expect <<-EOF && |
| 762 | $orgmaster $newmaster refs/heads/master |
| 763 | $orgnext $newnext refs/heads/next |
| 764 | $orgpu $newpu refs/heads/pu |
| 765 | $_z40 $_z40 refs/heads/nonexistent |
| 766 | EOF |
| 767 | |
| 768 | cat >update.expect <<-EOF && |
| 769 | refs/heads/master $orgmaster $newmaster |
| 770 | refs/heads/next $orgnext $newnext |
| 771 | refs/heads/pu $orgpu $newpu |
| 772 | refs/heads/nonexistent $_z40 $_z40 |
| 773 | EOF |
| 774 | |
| 775 | cat >post-receive.expect <<-EOF && |
| 776 | $orgmaster $newmaster refs/heads/master |
| 777 | $orgnext $newnext refs/heads/next |
| 778 | $orgpu $newpu refs/heads/pu |
| 779 | EOF |
| 780 | |
| 781 | cat >post-update.expect <<-EOF && |
| 782 | refs/heads/master |
| 783 | refs/heads/next |
| 784 | refs/heads/pu |
| 785 | EOF |
| 786 | |
| 787 | test_cmp pre-receive.expect pre-receive.actual && |
| 788 | test_cmp update.expect update.actual && |
| 789 | test_cmp post-receive.expect post-receive.actual && |
| 790 | test_cmp post-update.expect post-update.actual |
| 791 | ) |
| 792 | ' |
| 793 | |
Jan Krüger | f517f1f | 2009-12-30 20:57:42 +0100 | [diff] [blame] | 794 | test_expect_success 'allow deleting a ref using --delete' ' |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 795 | mk_test testrepo heads/master && |
Jan Krüger | f517f1f | 2009-12-30 20:57:42 +0100 | [diff] [blame] | 796 | (cd testrepo && git config receive.denyDeleteCurrent warn) && |
| 797 | git push testrepo --delete master && |
| 798 | (cd testrepo && test_must_fail git rev-parse --verify refs/heads/master) |
| 799 | ' |
| 800 | |
| 801 | test_expect_success 'allow deleting a tag using --delete' ' |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 802 | mk_test testrepo heads/master && |
Jan Krüger | f517f1f | 2009-12-30 20:57:42 +0100 | [diff] [blame] | 803 | git tag -a -m dummy_message deltag heads/master && |
| 804 | git push testrepo --tags && |
| 805 | (cd testrepo && git rev-parse --verify -q refs/tags/deltag) && |
| 806 | git push testrepo --delete tag deltag && |
| 807 | (cd testrepo && test_must_fail git rev-parse --verify refs/tags/deltag) |
| 808 | ' |
| 809 | |
| 810 | test_expect_success 'push --delete without args aborts' ' |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 811 | mk_test testrepo heads/master && |
Jan Krüger | f517f1f | 2009-12-30 20:57:42 +0100 | [diff] [blame] | 812 | test_must_fail git push testrepo --delete |
| 813 | ' |
| 814 | |
| 815 | test_expect_success 'push --delete refuses src:dest refspecs' ' |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 816 | mk_test testrepo heads/master && |
Jan Krüger | f517f1f | 2009-12-30 20:57:42 +0100 | [diff] [blame] | 817 | test_must_fail git push testrepo --delete master:foo |
| 818 | ' |
| 819 | |
Jeff King | 986e823 | 2008-11-08 20:49:27 -0500 | [diff] [blame] | 820 | test_expect_success 'warn on push to HEAD of non-bare repository' ' |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 821 | mk_test testrepo heads/master && |
Jay Soffian | d4785cd | 2010-04-19 18:08:31 -0400 | [diff] [blame] | 822 | ( |
| 823 | cd testrepo && |
Jeff King | 986e823 | 2008-11-08 20:49:27 -0500 | [diff] [blame] | 824 | git checkout master && |
Jay Soffian | d4785cd | 2010-04-19 18:08:31 -0400 | [diff] [blame] | 825 | git config receive.denyCurrentBranch warn |
| 826 | ) && |
Jeff King | 986e823 | 2008-11-08 20:49:27 -0500 | [diff] [blame] | 827 | git push testrepo master 2>stderr && |
Junio C Hamano | 3d95d92 | 2009-01-31 17:34:05 -0800 | [diff] [blame] | 828 | grep "warning: updating the current branch" stderr |
Jeff King | 986e823 | 2008-11-08 20:49:27 -0500 | [diff] [blame] | 829 | ' |
| 830 | |
| 831 | test_expect_success 'deny push to HEAD of non-bare repository' ' |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 832 | mk_test testrepo heads/master && |
Jay Soffian | d4785cd | 2010-04-19 18:08:31 -0400 | [diff] [blame] | 833 | ( |
| 834 | cd testrepo && |
Jeff King | 986e823 | 2008-11-08 20:49:27 -0500 | [diff] [blame] | 835 | git checkout master && |
Jay Soffian | d4785cd | 2010-04-19 18:08:31 -0400 | [diff] [blame] | 836 | git config receive.denyCurrentBranch true |
| 837 | ) && |
Jeff King | 986e823 | 2008-11-08 20:49:27 -0500 | [diff] [blame] | 838 | test_must_fail git push testrepo master |
| 839 | ' |
| 840 | |
| 841 | test_expect_success 'allow push to HEAD of bare repository (bare)' ' |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 842 | mk_test testrepo heads/master && |
Jay Soffian | d4785cd | 2010-04-19 18:08:31 -0400 | [diff] [blame] | 843 | ( |
| 844 | cd testrepo && |
Jeff King | 986e823 | 2008-11-08 20:49:27 -0500 | [diff] [blame] | 845 | git checkout master && |
| 846 | git config receive.denyCurrentBranch true && |
Jay Soffian | d4785cd | 2010-04-19 18:08:31 -0400 | [diff] [blame] | 847 | git config core.bare true |
| 848 | ) && |
Jeff King | 986e823 | 2008-11-08 20:49:27 -0500 | [diff] [blame] | 849 | git push testrepo master 2>stderr && |
Junio C Hamano | 3d95d92 | 2009-01-31 17:34:05 -0800 | [diff] [blame] | 850 | ! grep "warning: updating the current branch" stderr |
Jeff King | 986e823 | 2008-11-08 20:49:27 -0500 | [diff] [blame] | 851 | ' |
| 852 | |
| 853 | test_expect_success 'allow push to HEAD of non-bare repository (config)' ' |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 854 | mk_test testrepo heads/master && |
Jay Soffian | d4785cd | 2010-04-19 18:08:31 -0400 | [diff] [blame] | 855 | ( |
| 856 | cd testrepo && |
Jeff King | 986e823 | 2008-11-08 20:49:27 -0500 | [diff] [blame] | 857 | git checkout master && |
| 858 | git config receive.denyCurrentBranch false |
| 859 | ) && |
| 860 | git push testrepo master 2>stderr && |
Junio C Hamano | 3d95d92 | 2009-01-31 17:34:05 -0800 | [diff] [blame] | 861 | ! grep "warning: updating the current branch" stderr |
Jeff King | 986e823 | 2008-11-08 20:49:27 -0500 | [diff] [blame] | 862 | ' |
| 863 | |
Martin Koegler | 18afe10 | 2008-11-10 22:47:11 +0100 | [diff] [blame] | 864 | test_expect_success 'fetch with branches' ' |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 865 | mk_empty testrepo && |
Martin Koegler | 18afe10 | 2008-11-10 22:47:11 +0100 | [diff] [blame] | 866 | git branch second $the_first_commit && |
| 867 | git checkout second && |
| 868 | echo ".." > testrepo/.git/branches/branch1 && |
Jay Soffian | d4785cd | 2010-04-19 18:08:31 -0400 | [diff] [blame] | 869 | ( |
| 870 | cd testrepo && |
Martin Koegler | 18afe10 | 2008-11-10 22:47:11 +0100 | [diff] [blame] | 871 | git fetch branch1 && |
Jonathan Nieder | 848575d | 2013-03-18 16:13:41 -0700 | [diff] [blame] | 872 | echo "$the_commit commit refs/heads/branch1" >expect && |
| 873 | git for-each-ref refs/heads >actual && |
| 874 | test_cmp expect actual |
Martin Koegler | 18afe10 | 2008-11-10 22:47:11 +0100 | [diff] [blame] | 875 | ) && |
| 876 | git checkout master |
| 877 | ' |
| 878 | |
| 879 | test_expect_success 'fetch with branches containing #' ' |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 880 | mk_empty testrepo && |
Martin Koegler | 18afe10 | 2008-11-10 22:47:11 +0100 | [diff] [blame] | 881 | echo "..#second" > testrepo/.git/branches/branch2 && |
Jay Soffian | d4785cd | 2010-04-19 18:08:31 -0400 | [diff] [blame] | 882 | ( |
| 883 | cd testrepo && |
Martin Koegler | 18afe10 | 2008-11-10 22:47:11 +0100 | [diff] [blame] | 884 | git fetch branch2 && |
Jonathan Nieder | 848575d | 2013-03-18 16:13:41 -0700 | [diff] [blame] | 885 | echo "$the_first_commit commit refs/heads/branch2" >expect && |
| 886 | git for-each-ref refs/heads >actual && |
| 887 | test_cmp expect actual |
Martin Koegler | 18afe10 | 2008-11-10 22:47:11 +0100 | [diff] [blame] | 888 | ) && |
| 889 | git checkout master |
| 890 | ' |
| 891 | |
| 892 | test_expect_success 'push with branches' ' |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 893 | mk_empty testrepo && |
Martin Koegler | 18afe10 | 2008-11-10 22:47:11 +0100 | [diff] [blame] | 894 | git checkout second && |
| 895 | echo "testrepo" > .git/branches/branch1 && |
| 896 | git push branch1 && |
Jay Soffian | d4785cd | 2010-04-19 18:08:31 -0400 | [diff] [blame] | 897 | ( |
| 898 | cd testrepo && |
Jonathan Nieder | 848575d | 2013-03-18 16:13:41 -0700 | [diff] [blame] | 899 | echo "$the_first_commit commit refs/heads/master" >expect && |
| 900 | git for-each-ref refs/heads >actual && |
| 901 | test_cmp expect actual |
Martin Koegler | 18afe10 | 2008-11-10 22:47:11 +0100 | [diff] [blame] | 902 | ) |
| 903 | ' |
| 904 | |
| 905 | test_expect_success 'push with branches containing #' ' |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 906 | mk_empty testrepo && |
Martin Koegler | 18afe10 | 2008-11-10 22:47:11 +0100 | [diff] [blame] | 907 | echo "testrepo#branch3" > .git/branches/branch2 && |
| 908 | git push branch2 && |
Jay Soffian | d4785cd | 2010-04-19 18:08:31 -0400 | [diff] [blame] | 909 | ( |
| 910 | cd testrepo && |
Jonathan Nieder | 848575d | 2013-03-18 16:13:41 -0700 | [diff] [blame] | 911 | echo "$the_first_commit commit refs/heads/branch3" >expect && |
| 912 | git for-each-ref refs/heads >actual && |
| 913 | test_cmp expect actual |
Martin Koegler | 18afe10 | 2008-11-10 22:47:11 +0100 | [diff] [blame] | 914 | ) && |
| 915 | git checkout master |
| 916 | ' |
| 917 | |
Jay Soffian | da3efdb | 2010-04-19 18:19:18 -0400 | [diff] [blame] | 918 | test_expect_success 'push into aliased refs (consistent)' ' |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 919 | mk_test testrepo heads/master && |
| 920 | mk_child testrepo child1 && |
| 921 | mk_child testrepo child2 && |
Jay Soffian | da3efdb | 2010-04-19 18:19:18 -0400 | [diff] [blame] | 922 | ( |
| 923 | cd child1 && |
| 924 | git branch foo && |
| 925 | git symbolic-ref refs/heads/bar refs/heads/foo |
| 926 | git config receive.denyCurrentBranch false |
| 927 | ) && |
| 928 | ( |
| 929 | cd child2 && |
| 930 | >path2 && |
| 931 | git add path2 && |
| 932 | test_tick && |
| 933 | git commit -a -m child2 && |
| 934 | git branch foo && |
| 935 | git branch bar && |
| 936 | git push ../child1 foo bar |
| 937 | ) |
| 938 | ' |
| 939 | |
| 940 | test_expect_success 'push into aliased refs (inconsistent)' ' |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 941 | mk_test testrepo heads/master && |
| 942 | mk_child testrepo child1 && |
| 943 | mk_child testrepo child2 && |
Jay Soffian | da3efdb | 2010-04-19 18:19:18 -0400 | [diff] [blame] | 944 | ( |
| 945 | cd child1 && |
| 946 | git branch foo && |
| 947 | git symbolic-ref refs/heads/bar refs/heads/foo |
| 948 | git config receive.denyCurrentBranch false |
| 949 | ) && |
| 950 | ( |
| 951 | cd child2 && |
| 952 | >path2 && |
| 953 | git add path2 && |
| 954 | test_tick && |
| 955 | git commit -a -m child2 && |
| 956 | git branch foo && |
| 957 | >path3 && |
| 958 | git add path3 && |
| 959 | test_tick && |
| 960 | git commit -a -m child2 && |
| 961 | git branch bar && |
| 962 | test_must_fail git push ../child1 foo bar 2>stderr && |
| 963 | grep "refusing inconsistent update" stderr |
| 964 | ) |
| 965 | ' |
| 966 | |
Chris Rorvick | dbfeddb | 2012-11-29 19:41:37 -0600 | [diff] [blame] | 967 | test_expect_success 'push requires --force to update lightweight tag' ' |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 968 | mk_test testrepo heads/master && |
| 969 | mk_child testrepo child1 && |
| 970 | mk_child testrepo child2 && |
Chris Rorvick | dbfeddb | 2012-11-29 19:41:37 -0600 | [diff] [blame] | 971 | ( |
| 972 | cd child1 && |
| 973 | git tag Tag && |
| 974 | git push ../child2 Tag && |
| 975 | git push ../child2 Tag && |
| 976 | >file1 && |
| 977 | git add file1 && |
| 978 | git commit -m "file1" && |
| 979 | git tag -f Tag && |
| 980 | test_must_fail git push ../child2 Tag && |
| 981 | git push --force ../child2 Tag && |
| 982 | git tag -f Tag && |
| 983 | test_must_fail git push ../child2 Tag HEAD~ && |
| 984 | git push --force ../child2 Tag |
| 985 | ) |
| 986 | ' |
| 987 | |
Larry D'Anna | fbe4f44 | 2010-02-26 23:52:16 -0500 | [diff] [blame] | 988 | test_expect_success 'push --porcelain' ' |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 989 | mk_empty testrepo && |
Larry D'Anna | fbe4f44 | 2010-02-26 23:52:16 -0500 | [diff] [blame] | 990 | echo >.git/foo "To testrepo" && |
| 991 | echo >>.git/foo "* refs/heads/master:refs/remotes/origin/master [new branch]" && |
| 992 | echo >>.git/foo "Done" && |
| 993 | git push >.git/bar --porcelain testrepo refs/heads/master:refs/remotes/origin/master && |
| 994 | ( |
| 995 | cd testrepo && |
Jonathan Nieder | 848575d | 2013-03-18 16:13:41 -0700 | [diff] [blame] | 996 | echo "$the_commit commit refs/remotes/origin/master" >expect && |
| 997 | git for-each-ref refs/remotes/origin >actual && |
| 998 | test_cmp expect actual |
Larry D'Anna | fbe4f44 | 2010-02-26 23:52:16 -0500 | [diff] [blame] | 999 | ) && |
Junio C Hamano | c296134 | 2010-03-11 21:51:57 -0800 | [diff] [blame] | 1000 | test_cmp .git/foo .git/bar |
Larry D'Anna | fbe4f44 | 2010-02-26 23:52:16 -0500 | [diff] [blame] | 1001 | ' |
| 1002 | |
| 1003 | test_expect_success 'push --porcelain bad url' ' |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 1004 | mk_empty testrepo && |
Larry D'Anna | fbe4f44 | 2010-02-26 23:52:16 -0500 | [diff] [blame] | 1005 | test_must_fail git push >.git/bar --porcelain asdfasdfasd refs/heads/master:refs/remotes/origin/master && |
| 1006 | test_must_fail grep -q Done .git/bar |
| 1007 | ' |
| 1008 | |
| 1009 | test_expect_success 'push --porcelain rejected' ' |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 1010 | mk_empty testrepo && |
Larry D'Anna | fbe4f44 | 2010-02-26 23:52:16 -0500 | [diff] [blame] | 1011 | git push testrepo refs/heads/master:refs/remotes/origin/master && |
| 1012 | (cd testrepo && |
| 1013 | git reset --hard origin/master^ |
| 1014 | git config receive.denyCurrentBranch true) && |
| 1015 | |
| 1016 | echo >.git/foo "To testrepo" && |
| 1017 | echo >>.git/foo "! refs/heads/master:refs/heads/master [remote rejected] (branch is currently checked out)" && |
| 1018 | |
| 1019 | test_must_fail git push >.git/bar --porcelain testrepo refs/heads/master:refs/heads/master && |
Junio C Hamano | c296134 | 2010-03-11 21:51:57 -0800 | [diff] [blame] | 1020 | test_cmp .git/foo .git/bar |
Larry D'Anna | fbe4f44 | 2010-02-26 23:52:16 -0500 | [diff] [blame] | 1021 | ' |
| 1022 | |
| 1023 | test_expect_success 'push --porcelain --dry-run rejected' ' |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 1024 | mk_empty testrepo && |
Larry D'Anna | fbe4f44 | 2010-02-26 23:52:16 -0500 | [diff] [blame] | 1025 | git push testrepo refs/heads/master:refs/remotes/origin/master && |
| 1026 | (cd testrepo && |
| 1027 | git reset --hard origin/master |
| 1028 | git config receive.denyCurrentBranch true) && |
| 1029 | |
| 1030 | echo >.git/foo "To testrepo" && |
| 1031 | echo >>.git/foo "! refs/heads/master^:refs/heads/master [rejected] (non-fast-forward)" && |
| 1032 | echo >>.git/foo "Done" && |
| 1033 | |
| 1034 | test_must_fail git push >.git/bar --porcelain --dry-run testrepo refs/heads/master^:refs/heads/master && |
Junio C Hamano | c296134 | 2010-03-11 21:51:57 -0800 | [diff] [blame] | 1035 | test_cmp .git/foo .git/bar |
Larry D'Anna | fbe4f44 | 2010-02-26 23:52:16 -0500 | [diff] [blame] | 1036 | ' |
| 1037 | |
Felipe Contreras | 6ddba5e | 2012-02-23 00:43:41 +0200 | [diff] [blame] | 1038 | test_expect_success 'push --prune' ' |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 1039 | mk_test testrepo heads/master heads/second heads/foo heads/bar && |
Junio C Hamano | 0a42ac0 | 2013-01-04 16:08:26 -0800 | [diff] [blame] | 1040 | git push --prune testrepo : && |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 1041 | check_push_result testrepo $the_commit heads/master && |
| 1042 | check_push_result testrepo $the_first_commit heads/second && |
| 1043 | ! check_push_result testrepo $the_first_commit heads/foo heads/bar |
Felipe Contreras | 6ddba5e | 2012-02-23 00:43:41 +0200 | [diff] [blame] | 1044 | ' |
| 1045 | |
| 1046 | test_expect_success 'push --prune refspec' ' |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 1047 | mk_test testrepo tmp/master tmp/second tmp/foo tmp/bar && |
Felipe Contreras | 6ddba5e | 2012-02-23 00:43:41 +0200 | [diff] [blame] | 1048 | git push --prune testrepo "refs/heads/*:refs/tmp/*" && |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 1049 | check_push_result testrepo $the_commit tmp/master && |
| 1050 | check_push_result testrepo $the_first_commit tmp/second && |
| 1051 | ! check_push_result testrepo $the_first_commit tmp/foo tmp/bar |
Felipe Contreras | 6ddba5e | 2012-02-23 00:43:41 +0200 | [diff] [blame] | 1052 | ' |
| 1053 | |
Junio C Hamano | daebaa7 | 2013-01-18 16:08:30 -0800 | [diff] [blame] | 1054 | for configsection in transfer receive |
| 1055 | do |
| 1056 | test_expect_success "push to update a ref hidden by $configsection.hiderefs" ' |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 1057 | mk_test testrepo heads/master hidden/one hidden/two hidden/three && |
Junio C Hamano | daebaa7 | 2013-01-18 16:08:30 -0800 | [diff] [blame] | 1058 | ( |
| 1059 | cd testrepo && |
| 1060 | git config $configsection.hiderefs refs/hidden |
| 1061 | ) && |
| 1062 | |
| 1063 | # push to unhidden ref succeeds normally |
| 1064 | git push testrepo master:refs/heads/master && |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 1065 | check_push_result testrepo $the_commit heads/master && |
Junio C Hamano | daebaa7 | 2013-01-18 16:08:30 -0800 | [diff] [blame] | 1066 | |
| 1067 | # push to update a hidden ref should fail |
| 1068 | test_must_fail git push testrepo master:refs/hidden/one && |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 1069 | check_push_result testrepo $the_first_commit hidden/one && |
Junio C Hamano | daebaa7 | 2013-01-18 16:08:30 -0800 | [diff] [blame] | 1070 | |
| 1071 | # push to delete a hidden ref should fail |
| 1072 | test_must_fail git push testrepo :refs/hidden/two && |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 1073 | check_push_result testrepo $the_first_commit hidden/two && |
Junio C Hamano | daebaa7 | 2013-01-18 16:08:30 -0800 | [diff] [blame] | 1074 | |
| 1075 | # idempotent push to update a hidden ref should fail |
| 1076 | test_must_fail git push testrepo $the_first_commit:refs/hidden/three && |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 1077 | check_push_result testrepo $the_first_commit hidden/three |
Junio C Hamano | daebaa7 | 2013-01-18 16:08:30 -0800 | [diff] [blame] | 1078 | ' |
| 1079 | done |
| 1080 | |
Junio C Hamano | 6e7b66e | 2013-01-29 14:02:15 -0800 | [diff] [blame] | 1081 | test_expect_success 'fetch exact SHA1' ' |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 1082 | mk_test testrepo heads/master hidden/one && |
Junio C Hamano | 6e7b66e | 2013-01-29 14:02:15 -0800 | [diff] [blame] | 1083 | git push testrepo master:refs/hidden/one && |
| 1084 | ( |
| 1085 | cd testrepo && |
| 1086 | git config transfer.hiderefs refs/hidden |
| 1087 | ) && |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 1088 | check_push_result testrepo $the_commit hidden/one && |
Junio C Hamano | 6e7b66e | 2013-01-29 14:02:15 -0800 | [diff] [blame] | 1089 | |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 1090 | mk_child testrepo child && |
Junio C Hamano | 6e7b66e | 2013-01-29 14:02:15 -0800 | [diff] [blame] | 1091 | ( |
| 1092 | cd child && |
| 1093 | |
| 1094 | # make sure $the_commit does not exist here |
| 1095 | git repack -a -d && |
| 1096 | git prune && |
| 1097 | test_must_fail git cat-file -t $the_commit && |
| 1098 | |
| 1099 | # fetching the hidden object should fail by default |
| 1100 | test_must_fail git fetch -v ../testrepo $the_commit:refs/heads/copy && |
| 1101 | test_must_fail git rev-parse --verify refs/heads/copy && |
| 1102 | |
| 1103 | # the server side can allow it to succeed |
| 1104 | ( |
| 1105 | cd ../testrepo && |
| 1106 | git config uploadpack.allowtipsha1inwant true |
| 1107 | ) && |
| 1108 | |
| 1109 | git fetch -v ../testrepo $the_commit:refs/heads/copy && |
| 1110 | result=$(git rev-parse --verify refs/heads/copy) && |
| 1111 | test "$the_commit" = "$result" |
| 1112 | ) |
| 1113 | ' |
| 1114 | |
Junio C Hamano | c2aba15 | 2013-03-04 12:09:50 -0800 | [diff] [blame] | 1115 | test_expect_success 'fetch follows tags by default' ' |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 1116 | mk_test testrepo heads/master && |
Junio C Hamano | c2aba15 | 2013-03-04 12:09:50 -0800 | [diff] [blame] | 1117 | rm -fr src dst && |
| 1118 | git init src && |
| 1119 | ( |
| 1120 | cd src && |
| 1121 | git pull ../testrepo master && |
| 1122 | git tag -m "annotated" tag && |
| 1123 | git for-each-ref >tmp1 && |
| 1124 | ( |
| 1125 | cat tmp1 |
| 1126 | sed -n "s|refs/heads/master$|refs/remotes/origin/master|p" tmp1 |
| 1127 | ) | |
| 1128 | sort -k 3 >../expect |
| 1129 | ) && |
| 1130 | git init dst && |
| 1131 | ( |
| 1132 | cd dst && |
| 1133 | git remote add origin ../src && |
| 1134 | git config branch.master.remote origin && |
| 1135 | git config branch.master.merge refs/heads/master && |
| 1136 | git pull && |
| 1137 | git for-each-ref >../actual |
| 1138 | ) && |
| 1139 | test_cmp expect actual |
| 1140 | ' |
| 1141 | |
Junio C Hamano | ca02465 | 2013-12-03 15:41:15 -0800 | [diff] [blame] | 1142 | test_expect_success 'pushing a specific ref applies remote.$name.push as refmap' ' |
| 1143 | mk_test testrepo heads/master && |
| 1144 | rm -fr src dst && |
| 1145 | git init src && |
| 1146 | git init --bare dst && |
| 1147 | ( |
| 1148 | cd src && |
| 1149 | git pull ../testrepo master && |
| 1150 | git branch next && |
| 1151 | git config remote.dst.url ../dst && |
| 1152 | git config remote.dst.push "+refs/heads/*:refs/remotes/src/*" && |
| 1153 | git push dst master && |
| 1154 | git show-ref refs/heads/master | |
| 1155 | sed -e "s|refs/heads/|refs/remotes/src/|" >../dst/expect |
| 1156 | ) && |
| 1157 | ( |
| 1158 | cd dst && |
| 1159 | test_must_fail git show-ref refs/heads/next && |
| 1160 | test_must_fail git show-ref refs/heads/master && |
| 1161 | git show-ref refs/remotes/src/master >actual |
| 1162 | ) && |
| 1163 | test_cmp dst/expect dst/actual |
| 1164 | ' |
| 1165 | |
| 1166 | test_expect_success 'with no remote.$name.push, it is not used as refmap' ' |
| 1167 | mk_test testrepo heads/master && |
| 1168 | rm -fr src dst && |
| 1169 | git init src && |
| 1170 | git init --bare dst && |
| 1171 | ( |
| 1172 | cd src && |
| 1173 | git pull ../testrepo master && |
| 1174 | git branch next && |
| 1175 | git config remote.dst.url ../dst && |
Junio C Hamano | fc9261c | 2013-12-03 16:23:35 -0800 | [diff] [blame] | 1176 | git config push.default matching && |
Junio C Hamano | ca02465 | 2013-12-03 15:41:15 -0800 | [diff] [blame] | 1177 | git push dst master && |
| 1178 | git show-ref refs/heads/master >../dst/expect |
| 1179 | ) && |
| 1180 | ( |
| 1181 | cd dst && |
| 1182 | test_must_fail git show-ref refs/heads/next && |
| 1183 | git show-ref refs/heads/master >actual |
| 1184 | ) && |
| 1185 | test_cmp dst/expect dst/actual |
| 1186 | ' |
| 1187 | |
Junio C Hamano | fc9261c | 2013-12-03 16:23:35 -0800 | [diff] [blame] | 1188 | test_expect_success 'with no remote.$name.push, upstream mapping is used' ' |
| 1189 | mk_test testrepo heads/master && |
| 1190 | rm -fr src dst && |
| 1191 | git init src && |
| 1192 | git init --bare dst && |
| 1193 | ( |
| 1194 | cd src && |
| 1195 | git pull ../testrepo master && |
| 1196 | git branch next && |
| 1197 | git config remote.dst.url ../dst && |
| 1198 | git config remote.dst.fetch "+refs/heads/*:refs/remotes/dst/*" && |
| 1199 | git config push.default upstream && |
| 1200 | |
| 1201 | git config branch.master.merge refs/heads/trunk && |
| 1202 | git config branch.master.remote dst && |
| 1203 | |
| 1204 | git push dst master && |
| 1205 | git show-ref refs/heads/master | |
| 1206 | sed -e "s|refs/heads/master|refs/heads/trunk|" >../dst/expect |
| 1207 | ) && |
| 1208 | ( |
| 1209 | cd dst && |
| 1210 | test_must_fail git show-ref refs/heads/master && |
| 1211 | test_must_fail git show-ref refs/heads/next && |
| 1212 | git show-ref refs/heads/trunk >actual |
| 1213 | ) && |
| 1214 | test_cmp dst/expect dst/actual |
| 1215 | ' |
| 1216 | |
Junio C Hamano | c2aba15 | 2013-03-04 12:09:50 -0800 | [diff] [blame] | 1217 | test_expect_success 'push does not follow tags by default' ' |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 1218 | mk_test testrepo heads/master && |
Junio C Hamano | c2aba15 | 2013-03-04 12:09:50 -0800 | [diff] [blame] | 1219 | rm -fr src dst && |
| 1220 | git init src && |
| 1221 | git init --bare dst && |
| 1222 | ( |
| 1223 | cd src && |
| 1224 | git pull ../testrepo master && |
| 1225 | git tag -m "annotated" tag && |
| 1226 | git checkout -b another && |
| 1227 | git commit --allow-empty -m "future commit" && |
| 1228 | git tag -m "future" future && |
| 1229 | git checkout master && |
| 1230 | git for-each-ref refs/heads/master >../expect && |
| 1231 | git push ../dst master |
| 1232 | ) && |
| 1233 | ( |
| 1234 | cd dst && |
| 1235 | git for-each-ref >../actual |
| 1236 | ) && |
| 1237 | test_cmp expect actual |
| 1238 | ' |
| 1239 | |
| 1240 | test_expect_success 'push --follow-tag only pushes relevant tags' ' |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 1241 | mk_test testrepo heads/master && |
Junio C Hamano | c2aba15 | 2013-03-04 12:09:50 -0800 | [diff] [blame] | 1242 | rm -fr src dst && |
| 1243 | git init src && |
| 1244 | git init --bare dst && |
| 1245 | ( |
| 1246 | cd src && |
| 1247 | git pull ../testrepo master && |
| 1248 | git tag -m "annotated" tag && |
| 1249 | git checkout -b another && |
| 1250 | git commit --allow-empty -m "future commit" && |
| 1251 | git tag -m "future" future && |
| 1252 | git checkout master && |
| 1253 | git for-each-ref refs/heads/master refs/tags/tag >../expect |
| 1254 | git push --follow-tag ../dst master |
| 1255 | ) && |
| 1256 | ( |
| 1257 | cd dst && |
| 1258 | git for-each-ref >../actual |
| 1259 | ) && |
| 1260 | test_cmp expect actual |
| 1261 | ' |
| 1262 | |
Nguyễn Thái Ngọc Duy | f7c815c | 2013-08-12 20:55:55 +0700 | [diff] [blame] | 1263 | test_expect_success 'push --no-thin must produce non-thin pack' ' |
| 1264 | cat >>path1 <<\EOF && |
| 1265 | keep base version of path1 big enough, compared to the new changes |
| 1266 | later, in order to pass size heuristics in |
| 1267 | builtin/pack-objects.c:try_delta() |
| 1268 | EOF |
| 1269 | git commit -am initial && |
| 1270 | git init no-thin && |
| 1271 | git --git-dir=no-thin/.git config receive.unpacklimit 0 && |
| 1272 | git push no-thin/.git refs/heads/master:refs/heads/foo && |
| 1273 | echo modified >> path1 && |
| 1274 | git commit -am modified && |
| 1275 | git repack -adf && |
| 1276 | rcvpck="git receive-pack --reject-thin-pack-for-testing" && |
| 1277 | git push --no-thin --receive-pack="$rcvpck" no-thin/.git refs/heads/master:refs/heads/foo |
| 1278 | ' |
| 1279 | |
Junio C Hamano | bcdb34f | 2007-06-08 00:43:22 -0700 | [diff] [blame] | 1280 | test_done |