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 |
Jeff King | 72549df | 2014-11-04 08:11:19 -0500 | [diff] [blame] | 14 | * reflogs |
Ramkumar Ramachandra | 2ead7a6 | 2013-04-02 13:10:30 +0530 | [diff] [blame] | 15 | ' |
Junio C Hamano | bcdb34f | 2007-06-08 00:43:22 -0700 | [diff] [blame] | 16 | |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 17 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
Johannes Schindelin | 334afbc | 2020-11-18 23:44:19 +0000 | [diff] [blame] | 18 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 19 | |
Junio C Hamano | bcdb34f | 2007-06-08 00:43:22 -0700 | [diff] [blame] | 20 | . ./test-lib.sh |
| 21 | |
Elia Pinto | bf45242 | 2015-12-23 14:45:57 +0100 | [diff] [blame] | 22 | D=$(pwd) |
Junio C Hamano | bcdb34f | 2007-06-08 00:43:22 -0700 | [diff] [blame] | 23 | |
| 24 | mk_empty () { |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 25 | repo_name="$1" |
| 26 | rm -fr "$repo_name" && |
| 27 | mkdir "$repo_name" && |
Junio C Hamano | bcdb34f | 2007-06-08 00:43:22 -0700 | [diff] [blame] | 28 | ( |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 29 | cd "$repo_name" && |
Alex Riesen | 586e4ce | 2007-07-04 14:06:04 +0200 | [diff] [blame] | 30 | git init && |
Junio C Hamano | acd2a45 | 2009-02-11 02:28:03 -0800 | [diff] [blame] | 31 | git config receive.denyCurrentBranch warn && |
Alex Riesen | 586e4ce | 2007-07-04 14:06:04 +0200 | [diff] [blame] | 32 | mv .git/hooks .git/hooks-disabled |
Junio C Hamano | bcdb34f | 2007-06-08 00:43:22 -0700 | [diff] [blame] | 33 | ) |
| 34 | } |
| 35 | |
Junio C Hamano | 6125796 | 2007-06-09 01:23:53 -0700 | [diff] [blame] | 36 | mk_test () { |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 37 | repo_name="$1" |
| 38 | shift |
| 39 | |
| 40 | mk_empty "$repo_name" && |
Junio C Hamano | 6125796 | 2007-06-09 01:23:53 -0700 | [diff] [blame] | 41 | ( |
| 42 | for ref in "$@" |
| 43 | do |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 44 | git push "$repo_name" $the_first_commit:refs/$ref || |
Jonathan Nieder | 5bd81c7 | 2013-03-18 16:14:26 -0700 | [diff] [blame] | 45 | exit |
Junio C Hamano | 6125796 | 2007-06-09 01:23:53 -0700 | [diff] [blame] | 46 | done && |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 47 | cd "$repo_name" && |
Junio C Hamano | 6125796 | 2007-06-09 01:23:53 -0700 | [diff] [blame] | 48 | for ref in "$@" |
| 49 | do |
Jonathan Nieder | 848575d | 2013-03-18 16:13:41 -0700 | [diff] [blame] | 50 | echo "$the_first_commit" >expect && |
| 51 | git show-ref -s --verify refs/$ref >actual && |
| 52 | test_cmp expect actual || |
| 53 | exit |
Junio C Hamano | 6125796 | 2007-06-09 01:23:53 -0700 | [diff] [blame] | 54 | done && |
| 55 | git fsck --full |
| 56 | ) |
| 57 | } |
| 58 | |
Pang Yan Han | 160b81e | 2011-09-28 23:39:35 +0800 | [diff] [blame] | 59 | mk_test_with_hooks() { |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 60 | repo_name=$1 |
Pang Yan Han | 160b81e | 2011-09-28 23:39:35 +0800 | [diff] [blame] | 61 | mk_test "$@" && |
| 62 | ( |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 63 | cd "$repo_name" && |
Pang Yan Han | 160b81e | 2011-09-28 23:39:35 +0800 | [diff] [blame] | 64 | mkdir .git/hooks && |
| 65 | cd .git/hooks && |
| 66 | |
| 67 | cat >pre-receive <<-'EOF' && |
| 68 | #!/bin/sh |
| 69 | cat - >>pre-receive.actual |
| 70 | EOF |
| 71 | |
| 72 | cat >update <<-'EOF' && |
| 73 | #!/bin/sh |
| 74 | printf "%s %s %s\n" "$@" >>update.actual |
| 75 | EOF |
| 76 | |
| 77 | cat >post-receive <<-'EOF' && |
| 78 | #!/bin/sh |
| 79 | cat - >>post-receive.actual |
| 80 | EOF |
| 81 | |
| 82 | cat >post-update <<-'EOF' && |
| 83 | #!/bin/sh |
| 84 | for ref in "$@" |
| 85 | do |
| 86 | printf "%s\n" "$ref" >>post-update.actual |
| 87 | done |
| 88 | EOF |
| 89 | |
| 90 | chmod +x pre-receive update post-receive post-update |
| 91 | ) |
| 92 | } |
| 93 | |
Jeff King | b2dc968 | 2008-11-07 17:20:33 -0500 | [diff] [blame] | 94 | mk_child() { |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 95 | rm -rf "$2" && |
| 96 | git clone "$1" "$2" |
Jeff King | b2dc968 | 2008-11-07 17:20:33 -0500 | [diff] [blame] | 97 | } |
| 98 | |
Junio C Hamano | 6125796 | 2007-06-09 01:23:53 -0700 | [diff] [blame] | 99 | check_push_result () { |
SZEDER Gábor | cfb482b | 2018-05-10 16:01:53 +0200 | [diff] [blame] | 100 | test $# -ge 3 || |
SZEDER Gábor | 165293a | 2018-11-19 14:13:26 +0100 | [diff] [blame] | 101 | BUG "check_push_result requires at least 3 parameters" |
SZEDER Gábor | cfb482b | 2018-05-10 16:01:53 +0200 | [diff] [blame] | 102 | |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 103 | repo_name="$1" |
| 104 | shift |
| 105 | |
Junio C Hamano | 6125796 | 2007-06-09 01:23:53 -0700 | [diff] [blame] | 106 | ( |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 107 | cd "$repo_name" && |
Jonathan Nieder | 848575d | 2013-03-18 16:13:41 -0700 | [diff] [blame] | 108 | echo "$1" >expect && |
| 109 | shift && |
Junio C Hamano | 6125796 | 2007-06-09 01:23:53 -0700 | [diff] [blame] | 110 | for ref in "$@" |
| 111 | do |
Jonathan Nieder | 848575d | 2013-03-18 16:13:41 -0700 | [diff] [blame] | 112 | git show-ref -s --verify refs/$ref >actual && |
| 113 | test_cmp expect actual || |
| 114 | exit |
Junio C Hamano | 6125796 | 2007-06-09 01:23:53 -0700 | [diff] [blame] | 115 | done && |
| 116 | git fsck --full |
| 117 | ) |
| 118 | } |
| 119 | |
Junio C Hamano | bcdb34f | 2007-06-08 00:43:22 -0700 | [diff] [blame] | 120 | test_expect_success setup ' |
| 121 | |
Jay Soffian | d4785cd | 2010-04-19 18:08:31 -0400 | [diff] [blame] | 122 | >path1 && |
Junio C Hamano | bcdb34f | 2007-06-08 00:43:22 -0700 | [diff] [blame] | 123 | git add path1 && |
| 124 | test_tick && |
| 125 | git commit -a -m repo && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 126 | the_first_commit=$(git show-ref -s --verify refs/heads/main) && |
Junio C Hamano | 6125796 | 2007-06-09 01:23:53 -0700 | [diff] [blame] | 127 | |
Jay Soffian | d4785cd | 2010-04-19 18:08:31 -0400 | [diff] [blame] | 128 | >path2 && |
Junio C Hamano | 6125796 | 2007-06-09 01:23:53 -0700 | [diff] [blame] | 129 | git add path2 && |
| 130 | test_tick && |
| 131 | git commit -a -m second && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 132 | the_commit=$(git show-ref -s --verify refs/heads/main) |
Junio C Hamano | bcdb34f | 2007-06-08 00:43:22 -0700 | [diff] [blame] | 133 | |
| 134 | ' |
| 135 | |
| 136 | test_expect_success 'fetch without wildcard' ' |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 137 | mk_empty testrepo && |
Junio C Hamano | bcdb34f | 2007-06-08 00:43:22 -0700 | [diff] [blame] | 138 | ( |
| 139 | cd testrepo && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 140 | git fetch .. refs/heads/main:refs/remotes/origin/main && |
Junio C Hamano | bcdb34f | 2007-06-08 00:43:22 -0700 | [diff] [blame] | 141 | |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 142 | echo "$the_commit commit refs/remotes/origin/main" >expect && |
Jonathan Nieder | 848575d | 2013-03-18 16:13:41 -0700 | [diff] [blame] | 143 | git for-each-ref refs/remotes/origin >actual && |
| 144 | test_cmp expect actual |
Junio C Hamano | bcdb34f | 2007-06-08 00:43:22 -0700 | [diff] [blame] | 145 | ) |
| 146 | ' |
| 147 | |
| 148 | test_expect_success 'fetch with wildcard' ' |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 149 | mk_empty testrepo && |
Junio C Hamano | bcdb34f | 2007-06-08 00:43:22 -0700 | [diff] [blame] | 150 | ( |
| 151 | cd testrepo && |
| 152 | git config remote.up.url .. && |
| 153 | git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" && |
| 154 | git fetch up && |
| 155 | |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 156 | echo "$the_commit commit refs/remotes/origin/main" >expect && |
Jonathan Nieder | 848575d | 2013-03-18 16:13:41 -0700 | [diff] [blame] | 157 | git for-each-ref refs/remotes/origin >actual && |
| 158 | test_cmp expect actual |
Junio C Hamano | bcdb34f | 2007-06-08 00:43:22 -0700 | [diff] [blame] | 159 | ) |
| 160 | ' |
| 161 | |
Daniel Barkalow | 55029ae | 2008-02-20 13:43:53 -0500 | [diff] [blame] | 162 | test_expect_success 'fetch with insteadOf' ' |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 163 | mk_empty testrepo && |
Daniel Barkalow | 55029ae | 2008-02-20 13:43:53 -0500 | [diff] [blame] | 164 | ( |
Daniel Barkalow | 60e3aba | 2008-04-12 15:32:00 -0400 | [diff] [blame] | 165 | TRASH=$(pwd)/ && |
Daniel Barkalow | 55029ae | 2008-02-20 13:43:53 -0500 | [diff] [blame] | 166 | cd testrepo && |
Bryan Donlan | f69e836 | 2008-05-04 01:37:59 -0400 | [diff] [blame] | 167 | git config "url.$TRASH.insteadOf" trash/ && |
Daniel Barkalow | 55029ae | 2008-02-20 13:43:53 -0500 | [diff] [blame] | 168 | git config remote.up.url trash/. && |
| 169 | git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" && |
| 170 | git fetch up && |
| 171 | |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 172 | echo "$the_commit commit refs/remotes/origin/main" >expect && |
Jonathan Nieder | 848575d | 2013-03-18 16:13:41 -0700 | [diff] [blame] | 173 | git for-each-ref refs/remotes/origin >actual && |
| 174 | test_cmp expect actual |
Daniel Barkalow | 55029ae | 2008-02-20 13:43:53 -0500 | [diff] [blame] | 175 | ) |
| 176 | ' |
| 177 | |
Josh Triplett | 1c2eafb | 2009-09-07 01:56:33 -0700 | [diff] [blame] | 178 | test_expect_success 'fetch with pushInsteadOf (should not rewrite)' ' |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 179 | mk_empty testrepo && |
Josh Triplett | 1c2eafb | 2009-09-07 01:56:33 -0700 | [diff] [blame] | 180 | ( |
| 181 | TRASH=$(pwd)/ && |
| 182 | cd testrepo && |
| 183 | git config "url.trash/.pushInsteadOf" "$TRASH" && |
| 184 | git config remote.up.url "$TRASH." && |
| 185 | git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" && |
| 186 | git fetch up && |
| 187 | |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 188 | echo "$the_commit commit refs/remotes/origin/main" >expect && |
Jonathan Nieder | 848575d | 2013-03-18 16:13:41 -0700 | [diff] [blame] | 189 | git for-each-ref refs/remotes/origin >actual && |
| 190 | test_cmp expect actual |
Josh Triplett | 1c2eafb | 2009-09-07 01:56:33 -0700 | [diff] [blame] | 191 | ) |
| 192 | ' |
| 193 | |
Jonathan Tan | 477673d | 2021-05-04 14:16:02 -0700 | [diff] [blame] | 194 | grep_wrote () { |
| 195 | object_count=$1 |
| 196 | file_name=$2 |
| 197 | grep 'write_pack_file/wrote.*"value":"'$1'"' $2 |
| 198 | } |
| 199 | |
| 200 | test_expect_success 'push with negotiation' ' |
| 201 | # Without negotiation |
| 202 | mk_empty testrepo && |
| 203 | git push testrepo $the_first_commit:refs/remotes/origin/first_commit && |
Jonathan Tan | 54a03bc | 2021-07-15 10:44:31 -0700 | [diff] [blame] | 204 | test_commit -C testrepo unrelated_commit && |
Jonathan Tan | 477673d | 2021-05-04 14:16:02 -0700 | [diff] [blame] | 205 | git -C testrepo config receive.hideRefs refs/remotes/origin/first_commit && |
| 206 | echo now pushing without negotiation && |
| 207 | GIT_TRACE2_EVENT="$(pwd)/event" git -c protocol.version=2 push testrepo refs/heads/main:refs/remotes/origin/main && |
| 208 | grep_wrote 5 event && # 2 commits, 2 trees, 1 blob |
| 209 | |
| 210 | # Same commands, but with negotiation |
| 211 | rm event && |
| 212 | mk_empty testrepo && |
| 213 | git push testrepo $the_first_commit:refs/remotes/origin/first_commit && |
Jonathan Tan | 54a03bc | 2021-07-15 10:44:31 -0700 | [diff] [blame] | 214 | test_commit -C testrepo unrelated_commit && |
Jonathan Tan | 477673d | 2021-05-04 14:16:02 -0700 | [diff] [blame] | 215 | git -C testrepo config receive.hideRefs refs/remotes/origin/first_commit && |
| 216 | GIT_TRACE2_EVENT="$(pwd)/event" git -c protocol.version=2 -c push.negotiate=1 push testrepo refs/heads/main:refs/remotes/origin/main && |
| 217 | grep_wrote 2 event # 1 commit, 1 tree |
| 218 | ' |
| 219 | |
| 220 | test_expect_success 'push with negotiation proceeds anyway even if negotiation fails' ' |
| 221 | rm event && |
| 222 | mk_empty testrepo && |
| 223 | git push testrepo $the_first_commit:refs/remotes/origin/first_commit && |
Jonathan Tan | 54a03bc | 2021-07-15 10:44:31 -0700 | [diff] [blame] | 224 | test_commit -C testrepo unrelated_commit && |
Jonathan Tan | 477673d | 2021-05-04 14:16:02 -0700 | [diff] [blame] | 225 | git -C testrepo config receive.hideRefs refs/remotes/origin/first_commit && |
| 226 | GIT_TEST_PROTOCOL_VERSION=0 GIT_TRACE2_EVENT="$(pwd)/event" \ |
| 227 | git -c push.negotiate=1 push testrepo refs/heads/main:refs/remotes/origin/main 2>err && |
| 228 | grep_wrote 5 event && # 2 commits, 2 trees, 1 blob |
| 229 | test_i18ngrep "push negotiation failed" err |
| 230 | ' |
| 231 | |
Junio C Hamano | bcdb34f | 2007-06-08 00:43:22 -0700 | [diff] [blame] | 232 | test_expect_success 'push without wildcard' ' |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 233 | mk_empty testrepo && |
Junio C Hamano | bcdb34f | 2007-06-08 00:43:22 -0700 | [diff] [blame] | 234 | |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 235 | git push testrepo refs/heads/main:refs/remotes/origin/main && |
Junio C Hamano | bcdb34f | 2007-06-08 00:43:22 -0700 | [diff] [blame] | 236 | ( |
| 237 | cd testrepo && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 238 | echo "$the_commit commit refs/remotes/origin/main" >expect && |
Jonathan Nieder | 848575d | 2013-03-18 16:13:41 -0700 | [diff] [blame] | 239 | git for-each-ref refs/remotes/origin >actual && |
| 240 | test_cmp expect actual |
Junio C Hamano | bcdb34f | 2007-06-08 00:43:22 -0700 | [diff] [blame] | 241 | ) |
| 242 | ' |
| 243 | |
| 244 | test_expect_success 'push with wildcard' ' |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 245 | mk_empty testrepo && |
Junio C Hamano | bcdb34f | 2007-06-08 00:43:22 -0700 | [diff] [blame] | 246 | |
| 247 | git push testrepo "refs/heads/*:refs/remotes/origin/*" && |
| 248 | ( |
| 249 | cd testrepo && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 250 | echo "$the_commit commit refs/remotes/origin/main" >expect && |
Jonathan Nieder | 848575d | 2013-03-18 16:13:41 -0700 | [diff] [blame] | 251 | git for-each-ref refs/remotes/origin >actual && |
| 252 | test_cmp expect actual |
Junio C Hamano | bcdb34f | 2007-06-08 00:43:22 -0700 | [diff] [blame] | 253 | ) |
| 254 | ' |
| 255 | |
Daniel Barkalow | 55029ae | 2008-02-20 13:43:53 -0500 | [diff] [blame] | 256 | test_expect_success 'push with insteadOf' ' |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 257 | mk_empty testrepo && |
Bryan Donlan | f69e836 | 2008-05-04 01:37:59 -0400 | [diff] [blame] | 258 | TRASH="$(pwd)/" && |
Jonathan Nieder | 3c69552 | 2013-03-18 16:12:11 -0700 | [diff] [blame] | 259 | test_config "url.$TRASH.insteadOf" trash/ && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 260 | git push trash/testrepo refs/heads/main:refs/remotes/origin/main && |
Daniel Barkalow | 55029ae | 2008-02-20 13:43:53 -0500 | [diff] [blame] | 261 | ( |
| 262 | cd testrepo && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 263 | echo "$the_commit commit refs/remotes/origin/main" >expect && |
Jonathan Nieder | 848575d | 2013-03-18 16:13:41 -0700 | [diff] [blame] | 264 | git for-each-ref refs/remotes/origin >actual && |
| 265 | test_cmp expect actual |
Daniel Barkalow | 55029ae | 2008-02-20 13:43:53 -0500 | [diff] [blame] | 266 | ) |
| 267 | ' |
| 268 | |
Josh Triplett | 1c2eafb | 2009-09-07 01:56:33 -0700 | [diff] [blame] | 269 | test_expect_success 'push with pushInsteadOf' ' |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 270 | mk_empty testrepo && |
Josh Triplett | 1c2eafb | 2009-09-07 01:56:33 -0700 | [diff] [blame] | 271 | TRASH="$(pwd)/" && |
Jonathan Nieder | 3c69552 | 2013-03-18 16:12:11 -0700 | [diff] [blame] | 272 | test_config "url.$TRASH.pushInsteadOf" trash/ && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 273 | git push trash/testrepo refs/heads/main:refs/remotes/origin/main && |
Josh Triplett | 1c2eafb | 2009-09-07 01:56:33 -0700 | [diff] [blame] | 274 | ( |
| 275 | cd testrepo && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 276 | echo "$the_commit commit refs/remotes/origin/main" >expect && |
Jonathan Nieder | 848575d | 2013-03-18 16:13:41 -0700 | [diff] [blame] | 277 | git for-each-ref refs/remotes/origin >actual && |
| 278 | test_cmp expect actual |
Josh Triplett | 1c2eafb | 2009-09-07 01:56:33 -0700 | [diff] [blame] | 279 | ) |
| 280 | ' |
| 281 | |
| 282 | 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] | 283 | mk_empty testrepo && |
Junio C Hamano | 41ae34d | 2013-04-03 09:34:48 -0700 | [diff] [blame] | 284 | test_config "url.trash2/.pushInsteadOf" testrepo/ && |
Anders Kaseorg | eb32c66 | 2015-02-28 23:18:14 -0500 | [diff] [blame] | 285 | test_config "url.trash3/.pushInsteadOf" trash/wrong && |
Jonathan Nieder | 3c69552 | 2013-03-18 16:12:11 -0700 | [diff] [blame] | 286 | test_config remote.r.url trash/wrong && |
Junio C Hamano | 41ae34d | 2013-04-03 09:34:48 -0700 | [diff] [blame] | 287 | test_config remote.r.pushurl "testrepo/" && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 288 | git push r refs/heads/main:refs/remotes/origin/main && |
Josh Triplett | 1c2eafb | 2009-09-07 01:56:33 -0700 | [diff] [blame] | 289 | ( |
| 290 | cd testrepo && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 291 | echo "$the_commit commit refs/remotes/origin/main" >expect && |
Jonathan Nieder | 848575d | 2013-03-18 16:13:41 -0700 | [diff] [blame] | 292 | git for-each-ref refs/remotes/origin >actual && |
| 293 | test_cmp expect actual |
Josh Triplett | 1c2eafb | 2009-09-07 01:56:33 -0700 | [diff] [blame] | 294 | ) |
| 295 | ' |
| 296 | |
Junio C Hamano | 6125796 | 2007-06-09 01:23:53 -0700 | [diff] [blame] | 297 | test_expect_success 'push with matching heads' ' |
| 298 | |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 299 | mk_test testrepo heads/main && |
Junio C Hamano | 0a42ac0 | 2013-01-04 16:08:26 -0800 | [diff] [blame] | 300 | git push testrepo : && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 301 | check_push_result testrepo $the_commit heads/main |
Junio C Hamano | 6125796 | 2007-06-09 01:23:53 -0700 | [diff] [blame] | 302 | |
| 303 | ' |
| 304 | |
Paolo Bonzini | a83619d | 2008-04-28 11:32:12 -0400 | [diff] [blame] | 305 | test_expect_success 'push with matching heads on the command line' ' |
| 306 | |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 307 | mk_test testrepo heads/main && |
Paolo Bonzini | a83619d | 2008-04-28 11:32:12 -0400 | [diff] [blame] | 308 | git push testrepo : && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 309 | check_push_result testrepo $the_commit heads/main |
Paolo Bonzini | a83619d | 2008-04-28 11:32:12 -0400 | [diff] [blame] | 310 | |
| 311 | ' |
| 312 | |
| 313 | test_expect_success 'failed (non-fast-forward) push with matching heads' ' |
| 314 | |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 315 | mk_test testrepo heads/main && |
Paolo Bonzini | a83619d | 2008-04-28 11:32:12 -0400 | [diff] [blame] | 316 | git push testrepo : && |
| 317 | git commit --amend -massaged && |
Stephan Beyer | d492b31 | 2008-07-12 17:47:52 +0200 | [diff] [blame] | 318 | test_must_fail git push testrepo && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 319 | check_push_result testrepo $the_commit heads/main && |
Paolo Bonzini | a83619d | 2008-04-28 11:32:12 -0400 | [diff] [blame] | 320 | git reset --hard $the_commit |
| 321 | |
| 322 | ' |
| 323 | |
| 324 | test_expect_success 'push --force with matching heads' ' |
| 325 | |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 326 | mk_test testrepo heads/main && |
Paolo Bonzini | a83619d | 2008-04-28 11:32:12 -0400 | [diff] [blame] | 327 | git push testrepo : && |
| 328 | git commit --amend -massaged && |
Junio C Hamano | 0a42ac0 | 2013-01-04 16:08:26 -0800 | [diff] [blame] | 329 | git push --force testrepo : && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 330 | ! check_push_result testrepo $the_commit heads/main && |
Paolo Bonzini | a83619d | 2008-04-28 11:32:12 -0400 | [diff] [blame] | 331 | git reset --hard $the_commit |
| 332 | |
| 333 | ' |
| 334 | |
| 335 | test_expect_success 'push with matching heads and forced update' ' |
| 336 | |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 337 | mk_test testrepo heads/main && |
Paolo Bonzini | a83619d | 2008-04-28 11:32:12 -0400 | [diff] [blame] | 338 | git push testrepo : && |
| 339 | git commit --amend -massaged && |
| 340 | git push testrepo +: && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 341 | ! check_push_result testrepo $the_commit heads/main && |
Paolo Bonzini | a83619d | 2008-04-28 11:32:12 -0400 | [diff] [blame] | 342 | git reset --hard $the_commit |
| 343 | |
| 344 | ' |
| 345 | |
Junio C Hamano | 6125796 | 2007-06-09 01:23:53 -0700 | [diff] [blame] | 346 | test_expect_success 'push with no ambiguity (1)' ' |
| 347 | |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 348 | mk_test testrepo heads/main && |
| 349 | git push testrepo main:main && |
| 350 | check_push_result testrepo $the_commit heads/main |
Junio C Hamano | 6125796 | 2007-06-09 01:23:53 -0700 | [diff] [blame] | 351 | |
| 352 | ' |
| 353 | |
| 354 | test_expect_success 'push with no ambiguity (2)' ' |
| 355 | |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 356 | mk_test testrepo remotes/origin/main && |
| 357 | git push testrepo main:origin/main && |
| 358 | check_push_result testrepo $the_commit remotes/origin/main |
Junio C Hamano | 6125796 | 2007-06-09 01:23:53 -0700 | [diff] [blame] | 359 | |
| 360 | ' |
| 361 | |
Steffen Prohaska | ae36bdc | 2007-11-11 15:01:47 +0100 | [diff] [blame] | 362 | test_expect_success 'push with colon-less refspec, no ambiguity' ' |
| 363 | |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 364 | mk_test testrepo heads/main heads/t/main && |
| 365 | git branch -f t/main main && |
| 366 | git push testrepo main && |
| 367 | check_push_result testrepo $the_commit heads/main && |
| 368 | check_push_result testrepo $the_first_commit heads/t/main |
Steffen Prohaska | ae36bdc | 2007-11-11 15:01:47 +0100 | [diff] [blame] | 369 | |
| 370 | ' |
| 371 | |
Junio C Hamano | 6125796 | 2007-06-09 01:23:53 -0700 | [diff] [blame] | 372 | test_expect_success 'push with weak ambiguity (1)' ' |
| 373 | |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 374 | mk_test testrepo heads/main remotes/origin/main && |
| 375 | git push testrepo main:main && |
| 376 | check_push_result testrepo $the_commit heads/main && |
| 377 | check_push_result testrepo $the_first_commit remotes/origin/main |
Junio C Hamano | 6125796 | 2007-06-09 01:23:53 -0700 | [diff] [blame] | 378 | |
| 379 | ' |
| 380 | |
| 381 | test_expect_success 'push with weak ambiguity (2)' ' |
| 382 | |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 383 | mk_test testrepo heads/main remotes/origin/main remotes/another/main && |
| 384 | git push testrepo main:main && |
| 385 | check_push_result testrepo $the_commit heads/main && |
| 386 | check_push_result testrepo $the_first_commit remotes/origin/main remotes/another/main |
Junio C Hamano | 6125796 | 2007-06-09 01:23:53 -0700 | [diff] [blame] | 387 | |
| 388 | ' |
| 389 | |
Jeff King | 3ef6a1f | 2008-04-23 05:21:45 -0400 | [diff] [blame] | 390 | test_expect_success 'push with ambiguity' ' |
Junio C Hamano | 6125796 | 2007-06-09 01:23:53 -0700 | [diff] [blame] | 391 | |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 392 | mk_test testrepo heads/frotz tags/frotz && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 393 | test_must_fail git push testrepo main:frotz && |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 394 | check_push_result testrepo $the_first_commit heads/frotz tags/frotz |
Junio C Hamano | 1ed10b8 | 2007-06-09 01:37:14 -0700 | [diff] [blame] | 395 | |
| 396 | ' |
| 397 | |
| 398 | test_expect_success 'push with colon-less refspec (1)' ' |
| 399 | |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 400 | mk_test testrepo heads/frotz tags/frotz && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 401 | git branch -f frotz main && |
Junio C Hamano | 1ed10b8 | 2007-06-09 01:37:14 -0700 | [diff] [blame] | 402 | git push testrepo frotz && |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 403 | check_push_result testrepo $the_commit heads/frotz && |
| 404 | check_push_result testrepo $the_first_commit tags/frotz |
Junio C Hamano | 1ed10b8 | 2007-06-09 01:37:14 -0700 | [diff] [blame] | 405 | |
| 406 | ' |
| 407 | |
| 408 | test_expect_success 'push with colon-less refspec (2)' ' |
| 409 | |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 410 | mk_test testrepo heads/frotz tags/frotz && |
Junio C Hamano | 1ed10b8 | 2007-06-09 01:37:14 -0700 | [diff] [blame] | 411 | if git show-ref --verify -q refs/heads/frotz |
| 412 | then |
| 413 | git branch -D frotz |
| 414 | fi && |
| 415 | git tag -f frotz && |
Chris Rorvick | dbfeddb | 2012-11-29 19:41:37 -0600 | [diff] [blame] | 416 | git push -f testrepo frotz && |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 417 | check_push_result testrepo $the_commit tags/frotz && |
| 418 | check_push_result testrepo $the_first_commit heads/frotz |
Junio C Hamano | 1ed10b8 | 2007-06-09 01:37:14 -0700 | [diff] [blame] | 419 | |
| 420 | ' |
| 421 | |
| 422 | test_expect_success 'push with colon-less refspec (3)' ' |
| 423 | |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 424 | mk_test testrepo && |
Junio C Hamano | 1ed10b8 | 2007-06-09 01:37:14 -0700 | [diff] [blame] | 425 | if git show-ref --verify -q refs/tags/frotz |
| 426 | then |
| 427 | git tag -d frotz |
| 428 | fi && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 429 | git branch -f frotz main && |
Junio C Hamano | 1ed10b8 | 2007-06-09 01:37:14 -0700 | [diff] [blame] | 430 | git push testrepo frotz && |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 431 | check_push_result testrepo $the_commit heads/frotz && |
Brian Gernhardt | 9a3c6f7 | 2007-07-01 11:48:54 -0400 | [diff] [blame] | 432 | test 1 = $( cd testrepo && git show-ref | wc -l ) |
Junio C Hamano | 1ed10b8 | 2007-06-09 01:37:14 -0700 | [diff] [blame] | 433 | ' |
| 434 | |
| 435 | test_expect_success 'push with colon-less refspec (4)' ' |
| 436 | |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 437 | mk_test testrepo && |
Junio C Hamano | 1ed10b8 | 2007-06-09 01:37:14 -0700 | [diff] [blame] | 438 | if git show-ref --verify -q refs/heads/frotz |
| 439 | then |
| 440 | git branch -D frotz |
| 441 | fi && |
| 442 | git tag -f frotz && |
| 443 | git push testrepo frotz && |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 444 | check_push_result testrepo $the_commit tags/frotz && |
Brian Gernhardt | 9a3c6f7 | 2007-07-01 11:48:54 -0400 | [diff] [blame] | 445 | test 1 = $( cd testrepo && git show-ref | wc -l ) |
Junio C Hamano | 1ed10b8 | 2007-06-09 01:37:14 -0700 | [diff] [blame] | 446 | |
Junio C Hamano | 6125796 | 2007-06-09 01:23:53 -0700 | [diff] [blame] | 447 | ' |
| 448 | |
Dmitry Ivankov | 7be8b3b | 2011-06-16 19:42:48 +0600 | [diff] [blame] | 449 | test_expect_success 'push head with non-existent, incomplete dest' ' |
Jeff King | f8aae12 | 2008-04-23 05:16:06 -0400 | [diff] [blame] | 450 | |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 451 | mk_test testrepo && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 452 | git push testrepo main:branch && |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 453 | check_push_result testrepo $the_commit heads/branch |
Jeff King | f8aae12 | 2008-04-23 05:16:06 -0400 | [diff] [blame] | 454 | |
| 455 | ' |
| 456 | |
Dmitry Ivankov | 7be8b3b | 2011-06-16 19:42:48 +0600 | [diff] [blame] | 457 | test_expect_success 'push tag with non-existent, incomplete dest' ' |
Jeff King | f8aae12 | 2008-04-23 05:16:06 -0400 | [diff] [blame] | 458 | |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 459 | mk_test testrepo && |
Jeff King | f8aae12 | 2008-04-23 05:16:06 -0400 | [diff] [blame] | 460 | git tag -f v1.0 && |
| 461 | git push testrepo v1.0:tag && |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 462 | check_push_result testrepo $the_commit tags/tag |
Jeff King | f8aae12 | 2008-04-23 05:16:06 -0400 | [diff] [blame] | 463 | |
| 464 | ' |
| 465 | |
Dmitry Ivankov | 7be8b3b | 2011-06-16 19:42:48 +0600 | [diff] [blame] | 466 | test_expect_success 'push sha1 with non-existent, incomplete dest' ' |
Jeff King | f8aae12 | 2008-04-23 05:16:06 -0400 | [diff] [blame] | 467 | |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 468 | mk_test testrepo && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 469 | test_must_fail git push testrepo $(git rev-parse main):foo |
Jeff King | f8aae12 | 2008-04-23 05:16:06 -0400 | [diff] [blame] | 470 | |
| 471 | ' |
| 472 | |
Dmitry Ivankov | 7be8b3b | 2011-06-16 19:42:48 +0600 | [diff] [blame] | 473 | test_expect_success 'push ref expression 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 && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 476 | test_must_fail git push testrepo main^:branch |
Jeff King | f8aae12 | 2008-04-23 05:16:06 -0400 | [diff] [blame] | 477 | |
| 478 | ' |
| 479 | |
Felipe Contreras | 374fbae | 2020-11-25 18:16:16 -0600 | [diff] [blame] | 480 | for head in HEAD @ |
| 481 | do |
Steffen Prohaska | 47d996a | 2007-11-11 15:35:07 +0100 | [diff] [blame] | 482 | |
Felipe Contreras | 374fbae | 2020-11-25 18:16:16 -0600 | [diff] [blame] | 483 | test_expect_success "push with $head" ' |
Junio C Hamano | 27d7c85 | 2021-01-25 14:19:18 -0800 | [diff] [blame] | 484 | mk_test testrepo heads/main && |
| 485 | git checkout main && |
Felipe Contreras | 374fbae | 2020-11-25 18:16:16 -0600 | [diff] [blame] | 486 | git push testrepo $head && |
Junio C Hamano | 27d7c85 | 2021-01-25 14:19:18 -0800 | [diff] [blame] | 487 | check_push_result testrepo $the_commit heads/main |
Felipe Contreras | 374fbae | 2020-11-25 18:16:16 -0600 | [diff] [blame] | 488 | ' |
Steffen Prohaska | 47d996a | 2007-11-11 15:35:07 +0100 | [diff] [blame] | 489 | |
Felipe Contreras | 374fbae | 2020-11-25 18:16:16 -0600 | [diff] [blame] | 490 | test_expect_success "push with $head nonexisting at remote" ' |
Junio C Hamano | 27d7c85 | 2021-01-25 14:19:18 -0800 | [diff] [blame] | 491 | mk_test testrepo heads/main && |
| 492 | git checkout -b local main && |
| 493 | test_when_finished "git checkout main; git branch -D local" && |
Felipe Contreras | 374fbae | 2020-11-25 18:16:16 -0600 | [diff] [blame] | 494 | git push testrepo $head && |
| 495 | check_push_result testrepo $the_commit heads/local |
| 496 | ' |
Daniel Barkalow | 9f0ea7e | 2008-02-20 12:54:05 -0500 | [diff] [blame] | 497 | |
Felipe Contreras | 374fbae | 2020-11-25 18:16:16 -0600 | [diff] [blame] | 498 | test_expect_success "push with +$head" ' |
Junio C Hamano | 27d7c85 | 2021-01-25 14:19:18 -0800 | [diff] [blame] | 499 | mk_test testrepo heads/main && |
| 500 | git checkout -b local main && |
| 501 | test_when_finished "git checkout main; git branch -D local" && |
| 502 | git push testrepo main local && |
| 503 | check_push_result testrepo $the_commit heads/main && |
Felipe Contreras | 374fbae | 2020-11-25 18:16:16 -0600 | [diff] [blame] | 504 | check_push_result testrepo $the_commit heads/local && |
Daniel Barkalow | 9f0ea7e | 2008-02-20 12:54:05 -0500 | [diff] [blame] | 505 | |
Felipe Contreras | 374fbae | 2020-11-25 18:16:16 -0600 | [diff] [blame] | 506 | # Without force rewinding should fail |
| 507 | git reset --hard $head^ && |
| 508 | test_must_fail git push testrepo $head && |
| 509 | check_push_result testrepo $the_commit heads/local && |
Daniel Barkalow | 9f0ea7e | 2008-02-20 12:54:05 -0500 | [diff] [blame] | 510 | |
Felipe Contreras | 374fbae | 2020-11-25 18:16:16 -0600 | [diff] [blame] | 511 | # With force rewinding should succeed |
| 512 | git push testrepo +$head && |
| 513 | check_push_result testrepo $the_first_commit heads/local |
Felipe Contreras | 374fbae | 2020-11-25 18:16:16 -0600 | [diff] [blame] | 514 | ' |
Jeff King | f8aae12 | 2008-04-23 05:16:06 -0400 | [diff] [blame] | 515 | |
Felipe Contreras | 374fbae | 2020-11-25 18:16:16 -0600 | [diff] [blame] | 516 | test_expect_success "push $head with non-existent, incomplete dest" ' |
Felipe Contreras | 374fbae | 2020-11-25 18:16:16 -0600 | [diff] [blame] | 517 | mk_test testrepo && |
Junio C Hamano | 27d7c85 | 2021-01-25 14:19:18 -0800 | [diff] [blame] | 518 | git checkout main && |
Felipe Contreras | 374fbae | 2020-11-25 18:16:16 -0600 | [diff] [blame] | 519 | git push testrepo $head:branch && |
| 520 | check_push_result testrepo $the_commit heads/branch |
Jeff King | f8aae12 | 2008-04-23 05:16:06 -0400 | [diff] [blame] | 521 | |
Felipe Contreras | 374fbae | 2020-11-25 18:16:16 -0600 | [diff] [blame] | 522 | ' |
Daniel Barkalow | 9f0ea7e | 2008-02-20 12:54:05 -0500 | [diff] [blame] | 523 | |
Felipe Contreras | 374fbae | 2020-11-25 18:16:16 -0600 | [diff] [blame] | 524 | test_expect_success "push with config remote.*.push = $head" ' |
Felipe Contreras | 374fbae | 2020-11-25 18:16:16 -0600 | [diff] [blame] | 525 | mk_test testrepo heads/local && |
Junio C Hamano | 27d7c85 | 2021-01-25 14:19:18 -0800 | [diff] [blame] | 526 | git checkout main && |
Felipe Contreras | 374fbae | 2020-11-25 18:16:16 -0600 | [diff] [blame] | 527 | git branch -f local $the_commit && |
| 528 | test_when_finished "git branch -D local" && |
| 529 | ( |
| 530 | cd testrepo && |
| 531 | git checkout local && |
| 532 | git reset --hard $the_first_commit |
| 533 | ) && |
| 534 | test_config remote.there.url testrepo && |
| 535 | test_config remote.there.push $head && |
Junio C Hamano | 27d7c85 | 2021-01-25 14:19:18 -0800 | [diff] [blame] | 536 | test_config branch.main.remote there && |
Felipe Contreras | 374fbae | 2020-11-25 18:16:16 -0600 | [diff] [blame] | 537 | git push && |
Junio C Hamano | 27d7c85 | 2021-01-25 14:19:18 -0800 | [diff] [blame] | 538 | check_push_result testrepo $the_commit heads/main && |
Felipe Contreras | 374fbae | 2020-11-25 18:16:16 -0600 | [diff] [blame] | 539 | check_push_result testrepo $the_first_commit heads/local |
| 540 | ' |
| 541 | |
| 542 | done |
Daniel Barkalow | 9f0ea7e | 2008-02-20 12:54:05 -0500 | [diff] [blame] | 543 | |
Glen Choo | e083ef5 | 2021-11-17 16:53:21 -0800 | [diff] [blame] | 544 | test_expect_success "push to remote with no explicit refspec and config remote.*.push = src:dest" ' |
| 545 | mk_test testrepo heads/main && |
| 546 | git checkout $the_first_commit && |
| 547 | test_config remote.there.url testrepo && |
| 548 | test_config remote.there.push refs/heads/main:refs/heads/main && |
| 549 | git push there && |
| 550 | check_push_result testrepo $the_commit heads/main |
| 551 | ' |
| 552 | |
Ramkumar Ramachandra | 224c217 | 2013-04-02 13:10:33 +0530 | [diff] [blame] | 553 | test_expect_success 'push with remote.pushdefault' ' |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 554 | mk_test up_repo heads/main && |
| 555 | mk_test down_repo heads/main && |
Ramkumar Ramachandra | 224c217 | 2013-04-02 13:10:33 +0530 | [diff] [blame] | 556 | test_config remote.up.url up_repo && |
| 557 | test_config remote.down.url down_repo && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 558 | test_config branch.main.remote up && |
Ramkumar Ramachandra | 224c217 | 2013-04-02 13:10:33 +0530 | [diff] [blame] | 559 | test_config remote.pushdefault down && |
Junio C Hamano | 54a3c67 | 2013-04-18 11:47:59 -0700 | [diff] [blame] | 560 | test_config push.default matching && |
Ramkumar Ramachandra | 224c217 | 2013-04-02 13:10:33 +0530 | [diff] [blame] | 561 | git push && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 562 | check_push_result up_repo $the_first_commit heads/main && |
| 563 | check_push_result down_repo $the_commit heads/main |
Daniel Barkalow | 9f0ea7e | 2008-02-20 12:54:05 -0500 | [diff] [blame] | 564 | ' |
| 565 | |
Michael J Gruber | e1ca424 | 2009-06-09 18:01:35 +0200 | [diff] [blame] | 566 | test_expect_success 'push with config remote.*.pushurl' ' |
| 567 | |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 568 | mk_test testrepo heads/main && |
| 569 | git checkout main && |
Jonathan Nieder | 3c69552 | 2013-03-18 16:12:11 -0700 | [diff] [blame] | 570 | test_config remote.there.url test2repo && |
| 571 | test_config remote.there.pushurl testrepo && |
Junio C Hamano | 0a42ac0 | 2013-01-04 16:08:26 -0800 | [diff] [blame] | 572 | git push there : && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 573 | check_push_result testrepo $the_commit heads/main |
Michael J Gruber | e1ca424 | 2009-06-09 18:01:35 +0200 | [diff] [blame] | 574 | ' |
| 575 | |
Ramkumar Ramachandra | 9f765ce | 2013-04-02 13:10:34 +0530 | [diff] [blame] | 576 | test_expect_success 'push with config branch.*.pushremote' ' |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 577 | mk_test up_repo heads/main && |
| 578 | mk_test side_repo heads/main && |
| 579 | mk_test down_repo heads/main && |
Ramkumar Ramachandra | 9f765ce | 2013-04-02 13:10:34 +0530 | [diff] [blame] | 580 | test_config remote.up.url up_repo && |
| 581 | test_config remote.pushdefault side_repo && |
| 582 | test_config remote.down.url down_repo && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 583 | test_config branch.main.remote up && |
| 584 | test_config branch.main.pushremote down && |
Junio C Hamano | 54a3c67 | 2013-04-18 11:47:59 -0700 | [diff] [blame] | 585 | test_config push.default matching && |
Ramkumar Ramachandra | 9f765ce | 2013-04-02 13:10:34 +0530 | [diff] [blame] | 586 | git push && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 587 | check_push_result up_repo $the_first_commit heads/main && |
| 588 | check_push_result side_repo $the_first_commit heads/main && |
| 589 | check_push_result down_repo $the_commit heads/main |
Michael J Gruber | e1ca424 | 2009-06-09 18:01:35 +0200 | [diff] [blame] | 590 | ' |
| 591 | |
Jeff King | 98b406f | 2014-02-24 03:59:03 -0500 | [diff] [blame] | 592 | test_expect_success 'branch.*.pushremote config order is irrelevant' ' |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 593 | mk_test one_repo heads/main && |
| 594 | mk_test two_repo heads/main && |
Jeff King | 98b406f | 2014-02-24 03:59:03 -0500 | [diff] [blame] | 595 | test_config remote.one.url one_repo && |
| 596 | test_config remote.two.url two_repo && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 597 | test_config branch.main.pushremote two_repo && |
Jeff King | 98b406f | 2014-02-24 03:59:03 -0500 | [diff] [blame] | 598 | test_config remote.pushdefault one_repo && |
| 599 | test_config push.default matching && |
| 600 | git push && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 601 | check_push_result one_repo $the_first_commit heads/main && |
| 602 | check_push_result two_repo $the_commit heads/main |
Jeff King | 98b406f | 2014-02-24 03:59:03 -0500 | [diff] [blame] | 603 | ' |
| 604 | |
Glen Choo | 91e2e8f | 2022-05-31 23:12:33 +0000 | [diff] [blame^] | 605 | test_expect_success 'push ignores empty branch name entries' ' |
| 606 | mk_test one_repo heads/main && |
| 607 | test_config remote.one.url one_repo && |
| 608 | test_config branch..remote one && |
| 609 | test_config branch..merge refs/heads/ && |
| 610 | test_config branch.main.remote one && |
| 611 | test_config branch.main.merge refs/heads/main && |
| 612 | git push |
| 613 | ' |
| 614 | |
Brian Ewins | 11f2441 | 2007-10-11 20:32:27 +0100 | [diff] [blame] | 615 | test_expect_success 'push with dry-run' ' |
| 616 | |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 617 | mk_test testrepo heads/main && |
| 618 | old_commit=$(git -C testrepo show-ref -s --verify refs/heads/main) && |
Junio C Hamano | 0a42ac0 | 2013-01-04 16:08:26 -0800 | [diff] [blame] | 619 | git push --dry-run testrepo : && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 620 | check_push_result testrepo $old_commit heads/main |
Brian Ewins | 11f2441 | 2007-10-11 20:32:27 +0100 | [diff] [blame] | 621 | ' |
| 622 | |
Johannes Schindelin | 28391a8 | 2007-11-29 01:02:53 +0000 | [diff] [blame] | 623 | test_expect_success 'push updates local refs' ' |
| 624 | |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 625 | mk_test testrepo heads/main && |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 626 | mk_child testrepo child && |
Jay Soffian | d4785cd | 2010-04-19 18:08:31 -0400 | [diff] [blame] | 627 | ( |
| 628 | cd child && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 629 | git pull .. main && |
Johannes Schindelin | 28391a8 | 2007-11-29 01:02:53 +0000 | [diff] [blame] | 630 | git push && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 631 | test $(git rev-parse main) = \ |
| 632 | $(git rev-parse remotes/origin/main) |
Jay Soffian | d4785cd | 2010-04-19 18:08:31 -0400 | [diff] [blame] | 633 | ) |
Johannes Schindelin | 28391a8 | 2007-11-29 01:02:53 +0000 | [diff] [blame] | 634 | |
| 635 | ' |
| 636 | |
Clemens Buchacher | 16ed2f4 | 2008-11-05 21:55:54 +0100 | [diff] [blame] | 637 | test_expect_success 'push updates up-to-date local refs' ' |
| 638 | |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 639 | mk_test testrepo heads/main && |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 640 | mk_child testrepo child1 && |
| 641 | mk_child testrepo child2 && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 642 | (cd child1 && git pull .. main && git push) && |
Jay Soffian | d4785cd | 2010-04-19 18:08:31 -0400 | [diff] [blame] | 643 | ( |
| 644 | cd child2 && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 645 | git pull ../child1 main && |
Clemens Buchacher | 16ed2f4 | 2008-11-05 21:55:54 +0100 | [diff] [blame] | 646 | git push && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 647 | test $(git rev-parse main) = \ |
| 648 | $(git rev-parse remotes/origin/main) |
Jay Soffian | d4785cd | 2010-04-19 18:08:31 -0400 | [diff] [blame] | 649 | ) |
Clemens Buchacher | 16ed2f4 | 2008-11-05 21:55:54 +0100 | [diff] [blame] | 650 | |
| 651 | ' |
| 652 | |
| 653 | test_expect_success 'push preserves up-to-date packed refs' ' |
| 654 | |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 655 | mk_test testrepo heads/main && |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 656 | mk_child testrepo child && |
Jay Soffian | d4785cd | 2010-04-19 18:08:31 -0400 | [diff] [blame] | 657 | ( |
| 658 | cd child && |
Clemens Buchacher | 16ed2f4 | 2008-11-05 21:55:54 +0100 | [diff] [blame] | 659 | git push && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 660 | ! test -f .git/refs/remotes/origin/main |
Jay Soffian | d4785cd | 2010-04-19 18:08:31 -0400 | [diff] [blame] | 661 | ) |
Clemens Buchacher | 16ed2f4 | 2008-11-05 21:55:54 +0100 | [diff] [blame] | 662 | |
| 663 | ' |
| 664 | |
Johannes Schindelin | 28391a8 | 2007-11-29 01:02:53 +0000 | [diff] [blame] | 665 | test_expect_success 'push does not update local refs on failure' ' |
| 666 | |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 667 | mk_test testrepo heads/main && |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 668 | mk_child testrepo child && |
Jeff King | b2dc968 | 2008-11-07 17:20:33 -0500 | [diff] [blame] | 669 | mkdir testrepo/.git/hooks && |
bert Dvornik | fc012c2 | 2010-05-20 20:57:52 +0200 | [diff] [blame] | 670 | echo "#!/no/frobnication/today" >testrepo/.git/hooks/pre-receive && |
Jeff King | b2dc968 | 2008-11-07 17:20:33 -0500 | [diff] [blame] | 671 | chmod +x testrepo/.git/hooks/pre-receive && |
Jay Soffian | d4785cd | 2010-04-19 18:08:31 -0400 | [diff] [blame] | 672 | ( |
| 673 | cd child && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 674 | git pull .. main && |
Stephan Beyer | d492b31 | 2008-07-12 17:47:52 +0200 | [diff] [blame] | 675 | test_must_fail git push && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 676 | test $(git rev-parse main) != \ |
| 677 | $(git rev-parse remotes/origin/main) |
Jay Soffian | d4785cd | 2010-04-19 18:08:31 -0400 | [diff] [blame] | 678 | ) |
Johannes Schindelin | 28391a8 | 2007-11-29 01:02:53 +0000 | [diff] [blame] | 679 | |
| 680 | ' |
| 681 | |
| 682 | test_expect_success 'allow deleting an invalid remote ref' ' |
| 683 | |
Jeff King | e9de7a5 | 2021-09-24 14:33:00 -0400 | [diff] [blame] | 684 | mk_test testrepo heads/branch && |
Johannes Schindelin | 28391a8 | 2007-11-29 01:02:53 +0000 | [diff] [blame] | 685 | rm -f testrepo/.git/objects/??/* && |
Jeff King | e9de7a5 | 2021-09-24 14:33:00 -0400 | [diff] [blame] | 686 | git push testrepo :refs/heads/branch && |
| 687 | (cd testrepo && test_must_fail git rev-parse --verify refs/heads/branch) |
Johannes Schindelin | 28391a8 | 2007-11-29 01:02:53 +0000 | [diff] [blame] | 688 | |
| 689 | ' |
| 690 | |
Pang Yan Han | 160b81e | 2011-09-28 23:39:35 +0800 | [diff] [blame] | 691 | test_expect_success 'pushing valid refs triggers post-receive and post-update hooks' ' |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 692 | mk_test_with_hooks testrepo heads/main heads/next && |
| 693 | orgmain=$(cd testrepo && git show-ref -s --verify refs/heads/main) && |
| 694 | newmain=$(git show-ref -s --verify refs/heads/main) && |
Pang Yan Han | 160b81e | 2011-09-28 23:39:35 +0800 | [diff] [blame] | 695 | orgnext=$(cd testrepo && git show-ref -s --verify refs/heads/next) && |
brian m. carlson | 8125a58 | 2018-05-13 02:24:13 +0000 | [diff] [blame] | 696 | newnext=$ZERO_OID && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 697 | git push testrepo refs/heads/main:refs/heads/main :refs/heads/next && |
Pang Yan Han | 160b81e | 2011-09-28 23:39:35 +0800 | [diff] [blame] | 698 | ( |
| 699 | cd testrepo/.git && |
| 700 | cat >pre-receive.expect <<-EOF && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 701 | $orgmain $newmain refs/heads/main |
Pang Yan Han | 160b81e | 2011-09-28 23:39:35 +0800 | [diff] [blame] | 702 | $orgnext $newnext refs/heads/next |
| 703 | EOF |
| 704 | |
| 705 | cat >update.expect <<-EOF && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 706 | refs/heads/main $orgmain $newmain |
Pang Yan Han | 160b81e | 2011-09-28 23:39:35 +0800 | [diff] [blame] | 707 | refs/heads/next $orgnext $newnext |
| 708 | EOF |
| 709 | |
| 710 | cat >post-receive.expect <<-EOF && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 711 | $orgmain $newmain refs/heads/main |
Pang Yan Han | 160b81e | 2011-09-28 23:39:35 +0800 | [diff] [blame] | 712 | $orgnext $newnext refs/heads/next |
| 713 | EOF |
| 714 | |
| 715 | cat >post-update.expect <<-EOF && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 716 | refs/heads/main |
Pang Yan Han | 160b81e | 2011-09-28 23:39:35 +0800 | [diff] [blame] | 717 | refs/heads/next |
| 718 | EOF |
| 719 | |
| 720 | test_cmp pre-receive.expect pre-receive.actual && |
| 721 | test_cmp update.expect update.actual && |
| 722 | test_cmp post-receive.expect post-receive.actual && |
| 723 | test_cmp post-update.expect post-update.actual |
| 724 | ) |
| 725 | ' |
| 726 | |
| 727 | test_expect_success 'deleting dangling ref triggers hooks with correct args' ' |
Jeff King | e9de7a5 | 2021-09-24 14:33:00 -0400 | [diff] [blame] | 728 | mk_test_with_hooks testrepo heads/branch && |
Jeff King | 968f12f | 2021-09-24 14:46:13 -0400 | [diff] [blame] | 729 | orig=$(git -C testrepo rev-parse refs/heads/branch) && |
Pang Yan Han | 160b81e | 2011-09-28 23:39:35 +0800 | [diff] [blame] | 730 | rm -f testrepo/.git/objects/??/* && |
Jeff King | e9de7a5 | 2021-09-24 14:33:00 -0400 | [diff] [blame] | 731 | git push testrepo :refs/heads/branch && |
Pang Yan Han | 160b81e | 2011-09-28 23:39:35 +0800 | [diff] [blame] | 732 | ( |
| 733 | cd testrepo/.git && |
| 734 | cat >pre-receive.expect <<-EOF && |
Jeff King | 968f12f | 2021-09-24 14:46:13 -0400 | [diff] [blame] | 735 | $orig $ZERO_OID refs/heads/branch |
Pang Yan Han | 160b81e | 2011-09-28 23:39:35 +0800 | [diff] [blame] | 736 | EOF |
| 737 | |
| 738 | cat >update.expect <<-EOF && |
Jeff King | 968f12f | 2021-09-24 14:46:13 -0400 | [diff] [blame] | 739 | refs/heads/branch $orig $ZERO_OID |
Pang Yan Han | 160b81e | 2011-09-28 23:39:35 +0800 | [diff] [blame] | 740 | EOF |
| 741 | |
| 742 | cat >post-receive.expect <<-EOF && |
Jeff King | 968f12f | 2021-09-24 14:46:13 -0400 | [diff] [blame] | 743 | $orig $ZERO_OID refs/heads/branch |
Pang Yan Han | 160b81e | 2011-09-28 23:39:35 +0800 | [diff] [blame] | 744 | EOF |
| 745 | |
| 746 | cat >post-update.expect <<-EOF && |
Jeff King | e9de7a5 | 2021-09-24 14:33:00 -0400 | [diff] [blame] | 747 | refs/heads/branch |
Pang Yan Han | 160b81e | 2011-09-28 23:39:35 +0800 | [diff] [blame] | 748 | EOF |
| 749 | |
| 750 | test_cmp pre-receive.expect pre-receive.actual && |
| 751 | test_cmp update.expect update.actual && |
| 752 | test_cmp post-receive.expect post-receive.actual && |
| 753 | test_cmp post-update.expect post-update.actual |
| 754 | ) |
| 755 | ' |
| 756 | |
| 757 | test_expect_success 'deletion of a non-existent ref is not fed to post-receive and post-update hooks' ' |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 758 | mk_test_with_hooks testrepo heads/main && |
| 759 | orgmain=$(cd testrepo && git show-ref -s --verify refs/heads/main) && |
| 760 | newmain=$(git show-ref -s --verify refs/heads/main) && |
| 761 | git push testrepo main :refs/heads/nonexistent && |
Pang Yan Han | 160b81e | 2011-09-28 23:39:35 +0800 | [diff] [blame] | 762 | ( |
| 763 | cd testrepo/.git && |
| 764 | cat >pre-receive.expect <<-EOF && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 765 | $orgmain $newmain refs/heads/main |
brian m. carlson | 8125a58 | 2018-05-13 02:24:13 +0000 | [diff] [blame] | 766 | $ZERO_OID $ZERO_OID refs/heads/nonexistent |
Pang Yan Han | 160b81e | 2011-09-28 23:39:35 +0800 | [diff] [blame] | 767 | EOF |
| 768 | |
| 769 | cat >update.expect <<-EOF && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 770 | refs/heads/main $orgmain $newmain |
brian m. carlson | 8125a58 | 2018-05-13 02:24:13 +0000 | [diff] [blame] | 771 | refs/heads/nonexistent $ZERO_OID $ZERO_OID |
Pang Yan Han | 160b81e | 2011-09-28 23:39:35 +0800 | [diff] [blame] | 772 | EOF |
| 773 | |
| 774 | cat >post-receive.expect <<-EOF && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 775 | $orgmain $newmain refs/heads/main |
Pang Yan Han | 160b81e | 2011-09-28 23:39:35 +0800 | [diff] [blame] | 776 | EOF |
| 777 | |
| 778 | cat >post-update.expect <<-EOF && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 779 | refs/heads/main |
Pang Yan Han | 160b81e | 2011-09-28 23:39:35 +0800 | [diff] [blame] | 780 | EOF |
| 781 | |
| 782 | test_cmp pre-receive.expect pre-receive.actual && |
| 783 | test_cmp update.expect update.actual && |
| 784 | test_cmp post-receive.expect post-receive.actual && |
| 785 | test_cmp post-update.expect post-update.actual |
| 786 | ) |
| 787 | ' |
| 788 | |
| 789 | test_expect_success 'deletion of a non-existent ref alone does trigger post-receive and post-update hooks' ' |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 790 | mk_test_with_hooks testrepo heads/main && |
Pang Yan Han | 160b81e | 2011-09-28 23:39:35 +0800 | [diff] [blame] | 791 | git push testrepo :refs/heads/nonexistent && |
| 792 | ( |
| 793 | cd testrepo/.git && |
| 794 | cat >pre-receive.expect <<-EOF && |
brian m. carlson | 8125a58 | 2018-05-13 02:24:13 +0000 | [diff] [blame] | 795 | $ZERO_OID $ZERO_OID refs/heads/nonexistent |
Pang Yan Han | 160b81e | 2011-09-28 23:39:35 +0800 | [diff] [blame] | 796 | EOF |
| 797 | |
| 798 | cat >update.expect <<-EOF && |
brian m. carlson | 8125a58 | 2018-05-13 02:24:13 +0000 | [diff] [blame] | 799 | refs/heads/nonexistent $ZERO_OID $ZERO_OID |
Pang Yan Han | 160b81e | 2011-09-28 23:39:35 +0800 | [diff] [blame] | 800 | EOF |
| 801 | |
| 802 | test_cmp pre-receive.expect pre-receive.actual && |
| 803 | test_cmp update.expect update.actual && |
| 804 | test_path_is_missing post-receive.actual && |
| 805 | test_path_is_missing post-update.actual |
| 806 | ) |
| 807 | ' |
| 808 | |
| 809 | test_expect_success 'mixed ref updates, deletes, invalid deletes trigger hooks with correct input' ' |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 810 | mk_test_with_hooks testrepo heads/main heads/next heads/seen && |
| 811 | orgmain=$(cd testrepo && git show-ref -s --verify refs/heads/main) && |
| 812 | newmain=$(git show-ref -s --verify refs/heads/main) && |
Pang Yan Han | 160b81e | 2011-09-28 23:39:35 +0800 | [diff] [blame] | 813 | orgnext=$(cd testrepo && git show-ref -s --verify refs/heads/next) && |
brian m. carlson | 8125a58 | 2018-05-13 02:24:13 +0000 | [diff] [blame] | 814 | newnext=$ZERO_OID && |
Johannes Schindelin | 6dca5db | 2020-06-25 12:18:59 +0000 | [diff] [blame] | 815 | orgseen=$(cd testrepo && git show-ref -s --verify refs/heads/seen) && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 816 | newseen=$(git show-ref -s --verify refs/heads/main) && |
| 817 | git push testrepo refs/heads/main:refs/heads/main \ |
| 818 | refs/heads/main:refs/heads/seen :refs/heads/next \ |
Pang Yan Han | 160b81e | 2011-09-28 23:39:35 +0800 | [diff] [blame] | 819 | :refs/heads/nonexistent && |
| 820 | ( |
| 821 | cd testrepo/.git && |
| 822 | cat >pre-receive.expect <<-EOF && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 823 | $orgmain $newmain refs/heads/main |
Pang Yan Han | 160b81e | 2011-09-28 23:39:35 +0800 | [diff] [blame] | 824 | $orgnext $newnext refs/heads/next |
Johannes Schindelin | 6dca5db | 2020-06-25 12:18:59 +0000 | [diff] [blame] | 825 | $orgseen $newseen refs/heads/seen |
brian m. carlson | 8125a58 | 2018-05-13 02:24:13 +0000 | [diff] [blame] | 826 | $ZERO_OID $ZERO_OID refs/heads/nonexistent |
Pang Yan Han | 160b81e | 2011-09-28 23:39:35 +0800 | [diff] [blame] | 827 | EOF |
| 828 | |
| 829 | cat >update.expect <<-EOF && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 830 | refs/heads/main $orgmain $newmain |
Pang Yan Han | 160b81e | 2011-09-28 23:39:35 +0800 | [diff] [blame] | 831 | refs/heads/next $orgnext $newnext |
Johannes Schindelin | 6dca5db | 2020-06-25 12:18:59 +0000 | [diff] [blame] | 832 | refs/heads/seen $orgseen $newseen |
brian m. carlson | 8125a58 | 2018-05-13 02:24:13 +0000 | [diff] [blame] | 833 | refs/heads/nonexistent $ZERO_OID $ZERO_OID |
Pang Yan Han | 160b81e | 2011-09-28 23:39:35 +0800 | [diff] [blame] | 834 | EOF |
| 835 | |
| 836 | cat >post-receive.expect <<-EOF && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 837 | $orgmain $newmain refs/heads/main |
Pang Yan Han | 160b81e | 2011-09-28 23:39:35 +0800 | [diff] [blame] | 838 | $orgnext $newnext refs/heads/next |
Johannes Schindelin | 6dca5db | 2020-06-25 12:18:59 +0000 | [diff] [blame] | 839 | $orgseen $newseen refs/heads/seen |
Pang Yan Han | 160b81e | 2011-09-28 23:39:35 +0800 | [diff] [blame] | 840 | EOF |
| 841 | |
| 842 | cat >post-update.expect <<-EOF && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 843 | refs/heads/main |
Pang Yan Han | 160b81e | 2011-09-28 23:39:35 +0800 | [diff] [blame] | 844 | refs/heads/next |
Johannes Schindelin | 6dca5db | 2020-06-25 12:18:59 +0000 | [diff] [blame] | 845 | refs/heads/seen |
Pang Yan Han | 160b81e | 2011-09-28 23:39:35 +0800 | [diff] [blame] | 846 | EOF |
| 847 | |
| 848 | test_cmp pre-receive.expect pre-receive.actual && |
| 849 | test_cmp update.expect update.actual && |
| 850 | test_cmp post-receive.expect post-receive.actual && |
| 851 | test_cmp post-update.expect post-update.actual |
| 852 | ) |
| 853 | ' |
| 854 | |
Jan Krüger | f517f1f | 2009-12-30 20:57:42 +0100 | [diff] [blame] | 855 | test_expect_success 'allow deleting a ref using --delete' ' |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 856 | mk_test testrepo heads/main && |
Jan Krüger | f517f1f | 2009-12-30 20:57:42 +0100 | [diff] [blame] | 857 | (cd testrepo && git config receive.denyDeleteCurrent warn) && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 858 | git push testrepo --delete main && |
| 859 | (cd testrepo && test_must_fail git rev-parse --verify refs/heads/main) |
Jan Krüger | f517f1f | 2009-12-30 20:57:42 +0100 | [diff] [blame] | 860 | ' |
| 861 | |
| 862 | test_expect_success 'allow deleting a tag using --delete' ' |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 863 | mk_test testrepo heads/main && |
| 864 | git tag -a -m dummy_message deltag heads/main && |
Jan Krüger | f517f1f | 2009-12-30 20:57:42 +0100 | [diff] [blame] | 865 | git push testrepo --tags && |
| 866 | (cd testrepo && git rev-parse --verify -q refs/tags/deltag) && |
| 867 | git push testrepo --delete tag deltag && |
| 868 | (cd testrepo && test_must_fail git rev-parse --verify refs/tags/deltag) |
| 869 | ' |
| 870 | |
| 871 | test_expect_success 'push --delete without args aborts' ' |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 872 | mk_test testrepo heads/main && |
Jan Krüger | f517f1f | 2009-12-30 20:57:42 +0100 | [diff] [blame] | 873 | test_must_fail git push testrepo --delete |
| 874 | ' |
| 875 | |
| 876 | test_expect_success 'push --delete refuses src:dest refspecs' ' |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 877 | mk_test testrepo heads/main && |
| 878 | test_must_fail git push testrepo --delete main:foo |
Jan Krüger | f517f1f | 2009-12-30 20:57:42 +0100 | [diff] [blame] | 879 | ' |
| 880 | |
Junio C Hamano | 20e4164 | 2021-02-23 15:13:32 -0800 | [diff] [blame] | 881 | test_expect_success 'push --delete refuses empty string' ' |
| 882 | mk_test testrepo heads/master && |
| 883 | test_must_fail git push testrepo --delete "" |
| 884 | ' |
| 885 | |
Jeff King | 986e823 | 2008-11-08 20:49:27 -0500 | [diff] [blame] | 886 | test_expect_success 'warn on push to HEAD of non-bare repository' ' |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 887 | mk_test testrepo heads/main && |
Jay Soffian | d4785cd | 2010-04-19 18:08:31 -0400 | [diff] [blame] | 888 | ( |
| 889 | cd testrepo && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 890 | git checkout main && |
Jay Soffian | d4785cd | 2010-04-19 18:08:31 -0400 | [diff] [blame] | 891 | git config receive.denyCurrentBranch warn |
| 892 | ) && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 893 | git push testrepo main 2>stderr && |
Junio C Hamano | 3d95d92 | 2009-01-31 17:34:05 -0800 | [diff] [blame] | 894 | grep "warning: updating the current branch" stderr |
Jeff King | 986e823 | 2008-11-08 20:49:27 -0500 | [diff] [blame] | 895 | ' |
| 896 | |
| 897 | test_expect_success 'deny push to HEAD of non-bare repository' ' |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 898 | mk_test testrepo heads/main && |
Jay Soffian | d4785cd | 2010-04-19 18:08:31 -0400 | [diff] [blame] | 899 | ( |
| 900 | cd testrepo && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 901 | git checkout main && |
Jay Soffian | d4785cd | 2010-04-19 18:08:31 -0400 | [diff] [blame] | 902 | git config receive.denyCurrentBranch true |
| 903 | ) && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 904 | test_must_fail git push testrepo main |
Jeff King | 986e823 | 2008-11-08 20:49:27 -0500 | [diff] [blame] | 905 | ' |
| 906 | |
| 907 | test_expect_success 'allow push to HEAD of bare repository (bare)' ' |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 908 | mk_test testrepo heads/main && |
Jay Soffian | d4785cd | 2010-04-19 18:08:31 -0400 | [diff] [blame] | 909 | ( |
| 910 | cd testrepo && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 911 | git checkout main && |
Jeff King | 986e823 | 2008-11-08 20:49:27 -0500 | [diff] [blame] | 912 | git config receive.denyCurrentBranch true && |
Jay Soffian | d4785cd | 2010-04-19 18:08:31 -0400 | [diff] [blame] | 913 | git config core.bare true |
| 914 | ) && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 915 | git push testrepo main 2>stderr && |
Junio C Hamano | 3d95d92 | 2009-01-31 17:34:05 -0800 | [diff] [blame] | 916 | ! grep "warning: updating the current branch" stderr |
Jeff King | 986e823 | 2008-11-08 20:49:27 -0500 | [diff] [blame] | 917 | ' |
| 918 | |
| 919 | test_expect_success 'allow push to HEAD of non-bare repository (config)' ' |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 920 | mk_test testrepo heads/main && |
Jay Soffian | d4785cd | 2010-04-19 18:08:31 -0400 | [diff] [blame] | 921 | ( |
| 922 | cd testrepo && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 923 | git checkout main && |
Jeff King | 986e823 | 2008-11-08 20:49:27 -0500 | [diff] [blame] | 924 | git config receive.denyCurrentBranch false |
| 925 | ) && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 926 | git push testrepo main 2>stderr && |
Junio C Hamano | 3d95d92 | 2009-01-31 17:34:05 -0800 | [diff] [blame] | 927 | ! grep "warning: updating the current branch" stderr |
Jeff King | 986e823 | 2008-11-08 20:49:27 -0500 | [diff] [blame] | 928 | ' |
| 929 | |
Martin Koegler | 18afe10 | 2008-11-10 22:47:11 +0100 | [diff] [blame] | 930 | test_expect_success 'fetch with branches' ' |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 931 | mk_empty testrepo && |
Martin Koegler | 18afe10 | 2008-11-10 22:47:11 +0100 | [diff] [blame] | 932 | git branch second $the_first_commit && |
| 933 | git checkout second && |
| 934 | echo ".." > testrepo/.git/branches/branch1 && |
Jay Soffian | d4785cd | 2010-04-19 18:08:31 -0400 | [diff] [blame] | 935 | ( |
| 936 | cd testrepo && |
Martin Koegler | 18afe10 | 2008-11-10 22:47:11 +0100 | [diff] [blame] | 937 | git fetch branch1 && |
Jonathan Nieder | 848575d | 2013-03-18 16:13:41 -0700 | [diff] [blame] | 938 | echo "$the_commit commit refs/heads/branch1" >expect && |
| 939 | git for-each-ref refs/heads >actual && |
| 940 | test_cmp expect actual |
Martin Koegler | 18afe10 | 2008-11-10 22:47:11 +0100 | [diff] [blame] | 941 | ) && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 942 | git checkout main |
Martin Koegler | 18afe10 | 2008-11-10 22:47:11 +0100 | [diff] [blame] | 943 | ' |
| 944 | |
| 945 | test_expect_success 'fetch with branches containing #' ' |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 946 | mk_empty testrepo && |
Martin Koegler | 18afe10 | 2008-11-10 22:47:11 +0100 | [diff] [blame] | 947 | echo "..#second" > testrepo/.git/branches/branch2 && |
Jay Soffian | d4785cd | 2010-04-19 18:08:31 -0400 | [diff] [blame] | 948 | ( |
| 949 | cd testrepo && |
Martin Koegler | 18afe10 | 2008-11-10 22:47:11 +0100 | [diff] [blame] | 950 | git fetch branch2 && |
Jonathan Nieder | 848575d | 2013-03-18 16:13:41 -0700 | [diff] [blame] | 951 | echo "$the_first_commit commit refs/heads/branch2" >expect && |
| 952 | git for-each-ref refs/heads >actual && |
| 953 | test_cmp expect actual |
Martin Koegler | 18afe10 | 2008-11-10 22:47:11 +0100 | [diff] [blame] | 954 | ) && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 955 | git checkout main |
Martin Koegler | 18afe10 | 2008-11-10 22:47:11 +0100 | [diff] [blame] | 956 | ' |
| 957 | |
| 958 | test_expect_success 'push with branches' ' |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 959 | mk_empty testrepo && |
Martin Koegler | 18afe10 | 2008-11-10 22:47:11 +0100 | [diff] [blame] | 960 | git checkout second && |
| 961 | echo "testrepo" > .git/branches/branch1 && |
| 962 | git push branch1 && |
Jay Soffian | d4785cd | 2010-04-19 18:08:31 -0400 | [diff] [blame] | 963 | ( |
| 964 | cd testrepo && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 965 | echo "$the_first_commit commit refs/heads/main" >expect && |
Jonathan Nieder | 848575d | 2013-03-18 16:13:41 -0700 | [diff] [blame] | 966 | git for-each-ref refs/heads >actual && |
| 967 | test_cmp expect actual |
Martin Koegler | 18afe10 | 2008-11-10 22:47:11 +0100 | [diff] [blame] | 968 | ) |
| 969 | ' |
| 970 | |
| 971 | test_expect_success 'push with branches containing #' ' |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 972 | mk_empty testrepo && |
Martin Koegler | 18afe10 | 2008-11-10 22:47:11 +0100 | [diff] [blame] | 973 | echo "testrepo#branch3" > .git/branches/branch2 && |
| 974 | git push branch2 && |
Jay Soffian | d4785cd | 2010-04-19 18:08:31 -0400 | [diff] [blame] | 975 | ( |
| 976 | cd testrepo && |
Jonathan Nieder | 848575d | 2013-03-18 16:13:41 -0700 | [diff] [blame] | 977 | echo "$the_first_commit commit refs/heads/branch3" >expect && |
| 978 | git for-each-ref refs/heads >actual && |
| 979 | test_cmp expect actual |
Martin Koegler | 18afe10 | 2008-11-10 22:47:11 +0100 | [diff] [blame] | 980 | ) && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 981 | git checkout main |
Martin Koegler | 18afe10 | 2008-11-10 22:47:11 +0100 | [diff] [blame] | 982 | ' |
| 983 | |
Jay Soffian | da3efdb | 2010-04-19 18:19:18 -0400 | [diff] [blame] | 984 | test_expect_success 'push into aliased refs (consistent)' ' |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 985 | mk_test testrepo heads/main && |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 986 | mk_child testrepo child1 && |
| 987 | mk_child testrepo child2 && |
Jay Soffian | da3efdb | 2010-04-19 18:19:18 -0400 | [diff] [blame] | 988 | ( |
| 989 | cd child1 && |
| 990 | git branch foo && |
Eric Sunshine | 51b8547 | 2018-07-01 20:24:01 -0400 | [diff] [blame] | 991 | git symbolic-ref refs/heads/bar refs/heads/foo && |
Jay Soffian | da3efdb | 2010-04-19 18:19:18 -0400 | [diff] [blame] | 992 | git config receive.denyCurrentBranch false |
| 993 | ) && |
| 994 | ( |
| 995 | cd child2 && |
| 996 | >path2 && |
| 997 | git add path2 && |
| 998 | test_tick && |
| 999 | git commit -a -m child2 && |
| 1000 | git branch foo && |
| 1001 | git branch bar && |
| 1002 | git push ../child1 foo bar |
| 1003 | ) |
| 1004 | ' |
| 1005 | |
| 1006 | test_expect_success 'push into aliased refs (inconsistent)' ' |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1007 | mk_test testrepo heads/main && |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 1008 | mk_child testrepo child1 && |
| 1009 | mk_child testrepo child2 && |
Jay Soffian | da3efdb | 2010-04-19 18:19:18 -0400 | [diff] [blame] | 1010 | ( |
| 1011 | cd child1 && |
| 1012 | git branch foo && |
Eric Sunshine | 51b8547 | 2018-07-01 20:24:01 -0400 | [diff] [blame] | 1013 | git symbolic-ref refs/heads/bar refs/heads/foo && |
Jay Soffian | da3efdb | 2010-04-19 18:19:18 -0400 | [diff] [blame] | 1014 | git config receive.denyCurrentBranch false |
| 1015 | ) && |
| 1016 | ( |
| 1017 | cd child2 && |
| 1018 | >path2 && |
| 1019 | git add path2 && |
| 1020 | test_tick && |
| 1021 | git commit -a -m child2 && |
| 1022 | git branch foo && |
| 1023 | >path3 && |
| 1024 | git add path3 && |
| 1025 | test_tick && |
| 1026 | git commit -a -m child2 && |
| 1027 | git branch bar && |
| 1028 | test_must_fail git push ../child1 foo bar 2>stderr && |
| 1029 | grep "refusing inconsistent update" stderr |
| 1030 | ) |
| 1031 | ' |
| 1032 | |
Ævar Arnfjörð Bjarmason | 380efb6 | 2018-07-31 13:07:13 +0000 | [diff] [blame] | 1033 | test_force_push_tag () { |
| 1034 | tag_type_description=$1 |
| 1035 | tag_args=$2 |
Ævar Arnfjörð Bjarmason | 941a7ba | 2018-07-31 13:07:12 +0000 | [diff] [blame] | 1036 | |
Ævar Arnfjörð Bjarmason | f08fb8d | 2018-08-31 20:09:57 +0000 | [diff] [blame] | 1037 | test_expect_success "force pushing required to update $tag_type_description" " |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1038 | mk_test testrepo heads/main && |
Ævar Arnfjörð Bjarmason | 380efb6 | 2018-07-31 13:07:13 +0000 | [diff] [blame] | 1039 | mk_child testrepo child1 && |
| 1040 | mk_child testrepo child2 && |
| 1041 | ( |
| 1042 | cd child1 && |
| 1043 | git tag testTag && |
| 1044 | git push ../child2 testTag && |
| 1045 | >file1 && |
| 1046 | git add file1 && |
| 1047 | git commit -m 'file1' && |
| 1048 | git tag $tag_args testTag && |
| 1049 | test_must_fail git push ../child2 testTag && |
| 1050 | git push --force ../child2 testTag && |
| 1051 | git tag $tag_args testTag HEAD~ && |
| 1052 | test_must_fail git push ../child2 testTag && |
| 1053 | git push --force ../child2 testTag && |
Ævar Arnfjörð Bjarmason | 941a7ba | 2018-07-31 13:07:12 +0000 | [diff] [blame] | 1054 | |
Ævar Arnfjörð Bjarmason | 380efb6 | 2018-07-31 13:07:13 +0000 | [diff] [blame] | 1055 | # Clobbering without + in refspec needs --force |
| 1056 | git tag -f testTag && |
| 1057 | test_must_fail git push ../child2 'refs/tags/*:refs/tags/*' && |
| 1058 | git push --force ../child2 'refs/tags/*:refs/tags/*' && |
Ævar Arnfjörð Bjarmason | 941a7ba | 2018-07-31 13:07:12 +0000 | [diff] [blame] | 1059 | |
Ævar Arnfjörð Bjarmason | 380efb6 | 2018-07-31 13:07:13 +0000 | [diff] [blame] | 1060 | # Clobbering with + in refspec does not need --force |
| 1061 | git tag -f testTag HEAD~ && |
| 1062 | git push ../child2 '+refs/tags/*:refs/tags/*' && |
Ævar Arnfjörð Bjarmason | 941a7ba | 2018-07-31 13:07:12 +0000 | [diff] [blame] | 1063 | |
Ævar Arnfjörð Bjarmason | 380efb6 | 2018-07-31 13:07:13 +0000 | [diff] [blame] | 1064 | # Clobbering with --no-force still obeys + in refspec |
| 1065 | git tag -f testTag && |
| 1066 | git push --no-force ../child2 '+refs/tags/*:refs/tags/*' && |
| 1067 | |
| 1068 | # Clobbering with/without --force and 'tag <name>' format |
| 1069 | git tag -f testTag HEAD~ && |
| 1070 | test_must_fail git push ../child2 tag testTag && |
| 1071 | git push --force ../child2 tag testTag |
| 1072 | ) |
| 1073 | " |
| 1074 | } |
| 1075 | |
| 1076 | test_force_push_tag "lightweight tag" "-f" |
Ævar Arnfjörð Bjarmason | 253b3d4 | 2018-08-31 20:09:58 +0000 | [diff] [blame] | 1077 | test_force_push_tag "annotated tag" "-f -a -m'tag message'" |
Chris Rorvick | dbfeddb | 2012-11-29 19:41:37 -0600 | [diff] [blame] | 1078 | |
Ævar Arnfjörð Bjarmason | 6b0b067 | 2018-08-31 20:09:59 +0000 | [diff] [blame] | 1079 | test_force_fetch_tag () { |
| 1080 | tag_type_description=$1 |
| 1081 | tag_args=$2 |
| 1082 | |
Ævar Arnfjörð Bjarmason | 0bc8d71 | 2018-08-31 20:10:04 +0000 | [diff] [blame] | 1083 | test_expect_success "fetch will not clobber an existing $tag_type_description without --force" " |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1084 | mk_test testrepo heads/main && |
Ævar Arnfjörð Bjarmason | 6b0b067 | 2018-08-31 20:09:59 +0000 | [diff] [blame] | 1085 | mk_child testrepo child1 && |
| 1086 | mk_child testrepo child2 && |
| 1087 | ( |
| 1088 | cd testrepo && |
| 1089 | git tag testTag && |
| 1090 | git -C ../child1 fetch origin tag testTag && |
| 1091 | >file1 && |
| 1092 | git add file1 && |
| 1093 | git commit -m 'file1' && |
| 1094 | git tag $tag_args testTag && |
Ævar Arnfjörð Bjarmason | 0bc8d71 | 2018-08-31 20:10:04 +0000 | [diff] [blame] | 1095 | test_must_fail git -C ../child1 fetch origin tag testTag && |
| 1096 | git -C ../child1 fetch origin '+refs/tags/*:refs/tags/*' |
Ævar Arnfjörð Bjarmason | 6b0b067 | 2018-08-31 20:09:59 +0000 | [diff] [blame] | 1097 | ) |
| 1098 | " |
| 1099 | } |
| 1100 | |
| 1101 | test_force_fetch_tag "lightweight tag" "-f" |
| 1102 | test_force_fetch_tag "annotated tag" "-f -a -m'tag message'" |
Larry D'Anna | fbe4f44 | 2010-02-26 23:52:16 -0500 | [diff] [blame] | 1103 | |
Larry D'Anna | fbe4f44 | 2010-02-26 23:52:16 -0500 | [diff] [blame] | 1104 | test_expect_success 'push --porcelain' ' |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 1105 | mk_empty testrepo && |
Larry D'Anna | fbe4f44 | 2010-02-26 23:52:16 -0500 | [diff] [blame] | 1106 | echo >.git/foo "To testrepo" && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1107 | echo >>.git/foo "* refs/heads/main:refs/remotes/origin/main [new reference]" && |
Larry D'Anna | fbe4f44 | 2010-02-26 23:52:16 -0500 | [diff] [blame] | 1108 | echo >>.git/foo "Done" && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1109 | git push >.git/bar --porcelain testrepo refs/heads/main:refs/remotes/origin/main && |
Larry D'Anna | fbe4f44 | 2010-02-26 23:52:16 -0500 | [diff] [blame] | 1110 | ( |
| 1111 | cd testrepo && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1112 | echo "$the_commit commit refs/remotes/origin/main" >expect && |
Jonathan Nieder | 848575d | 2013-03-18 16:13:41 -0700 | [diff] [blame] | 1113 | git for-each-ref refs/remotes/origin >actual && |
| 1114 | test_cmp expect actual |
Larry D'Anna | fbe4f44 | 2010-02-26 23:52:16 -0500 | [diff] [blame] | 1115 | ) && |
| 1116 | test_cmp .git/foo .git/bar |
| 1117 | ' |
| 1118 | |
| 1119 | test_expect_success 'push --porcelain bad url' ' |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 1120 | mk_empty testrepo && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1121 | test_must_fail git push >.git/bar --porcelain asdfasdfasd refs/heads/main:refs/remotes/origin/main && |
Pranit Bauva | c7cf956 | 2017-01-04 01:27:07 +0530 | [diff] [blame] | 1122 | ! grep -q Done .git/bar |
Larry D'Anna | fbe4f44 | 2010-02-26 23:52:16 -0500 | [diff] [blame] | 1123 | ' |
| 1124 | |
| 1125 | test_expect_success 'push --porcelain rejected' ' |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 1126 | mk_empty testrepo && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1127 | git push testrepo refs/heads/main:refs/remotes/origin/main && |
Larry D'Anna | fbe4f44 | 2010-02-26 23:52:16 -0500 | [diff] [blame] | 1128 | (cd testrepo && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1129 | git reset --hard origin/main^ && |
Larry D'Anna | fbe4f44 | 2010-02-26 23:52:16 -0500 | [diff] [blame] | 1130 | git config receive.denyCurrentBranch true) && |
| 1131 | |
| 1132 | echo >.git/foo "To testrepo" && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1133 | echo >>.git/foo "! refs/heads/main:refs/heads/main [remote rejected] (branch is currently checked out)" && |
Jiang Xin | 7dcbeaa | 2020-04-17 05:45:32 -0400 | [diff] [blame] | 1134 | echo >>.git/foo "Done" && |
Larry D'Anna | fbe4f44 | 2010-02-26 23:52:16 -0500 | [diff] [blame] | 1135 | |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1136 | test_must_fail git push >.git/bar --porcelain testrepo refs/heads/main:refs/heads/main && |
Junio C Hamano | c296134 | 2010-03-11 21:51:57 -0800 | [diff] [blame] | 1137 | test_cmp .git/foo .git/bar |
Larry D'Anna | fbe4f44 | 2010-02-26 23:52:16 -0500 | [diff] [blame] | 1138 | ' |
| 1139 | |
| 1140 | test_expect_success 'push --porcelain --dry-run rejected' ' |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 1141 | mk_empty testrepo && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1142 | git push testrepo refs/heads/main:refs/remotes/origin/main && |
Larry D'Anna | fbe4f44 | 2010-02-26 23:52:16 -0500 | [diff] [blame] | 1143 | (cd testrepo && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1144 | git reset --hard origin/main && |
Larry D'Anna | fbe4f44 | 2010-02-26 23:52:16 -0500 | [diff] [blame] | 1145 | git config receive.denyCurrentBranch true) && |
| 1146 | |
| 1147 | echo >.git/foo "To testrepo" && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1148 | echo >>.git/foo "! refs/heads/main^:refs/heads/main [rejected] (non-fast-forward)" && |
Larry D'Anna | fbe4f44 | 2010-02-26 23:52:16 -0500 | [diff] [blame] | 1149 | echo >>.git/foo "Done" && |
| 1150 | |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1151 | test_must_fail git push >.git/bar --porcelain --dry-run testrepo refs/heads/main^:refs/heads/main && |
Junio C Hamano | c296134 | 2010-03-11 21:51:57 -0800 | [diff] [blame] | 1152 | test_cmp .git/foo .git/bar |
Larry D'Anna | fbe4f44 | 2010-02-26 23:52:16 -0500 | [diff] [blame] | 1153 | ' |
| 1154 | |
Felipe Contreras | 6ddba5e | 2012-02-23 00:43:41 +0200 | [diff] [blame] | 1155 | test_expect_success 'push --prune' ' |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1156 | mk_test testrepo heads/main heads/second heads/foo heads/bar && |
Junio C Hamano | 0a42ac0 | 2013-01-04 16:08:26 -0800 | [diff] [blame] | 1157 | git push --prune testrepo : && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1158 | check_push_result testrepo $the_commit heads/main && |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 1159 | check_push_result testrepo $the_first_commit heads/second && |
| 1160 | ! check_push_result testrepo $the_first_commit heads/foo heads/bar |
Felipe Contreras | 6ddba5e | 2012-02-23 00:43:41 +0200 | [diff] [blame] | 1161 | ' |
| 1162 | |
| 1163 | test_expect_success 'push --prune refspec' ' |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1164 | mk_test testrepo tmp/main tmp/second tmp/foo tmp/bar && |
Felipe Contreras | 6ddba5e | 2012-02-23 00:43:41 +0200 | [diff] [blame] | 1165 | git push --prune testrepo "refs/heads/*:refs/tmp/*" && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1166 | check_push_result testrepo $the_commit tmp/main && |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 1167 | check_push_result testrepo $the_first_commit tmp/second && |
| 1168 | ! check_push_result testrepo $the_first_commit tmp/foo tmp/bar |
Felipe Contreras | 6ddba5e | 2012-02-23 00:43:41 +0200 | [diff] [blame] | 1169 | ' |
| 1170 | |
Junio C Hamano | daebaa7 | 2013-01-18 16:08:30 -0800 | [diff] [blame] | 1171 | for configsection in transfer receive |
| 1172 | do |
| 1173 | test_expect_success "push to update a ref hidden by $configsection.hiderefs" ' |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1174 | mk_test testrepo heads/main hidden/one hidden/two hidden/three && |
Junio C Hamano | daebaa7 | 2013-01-18 16:08:30 -0800 | [diff] [blame] | 1175 | ( |
| 1176 | cd testrepo && |
| 1177 | git config $configsection.hiderefs refs/hidden |
| 1178 | ) && |
| 1179 | |
| 1180 | # push to unhidden ref succeeds normally |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1181 | git push testrepo main:refs/heads/main && |
| 1182 | check_push_result testrepo $the_commit heads/main && |
Junio C Hamano | daebaa7 | 2013-01-18 16:08:30 -0800 | [diff] [blame] | 1183 | |
| 1184 | # push to update a hidden ref should fail |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1185 | test_must_fail git push testrepo main:refs/hidden/one && |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 1186 | check_push_result testrepo $the_first_commit hidden/one && |
Junio C Hamano | daebaa7 | 2013-01-18 16:08:30 -0800 | [diff] [blame] | 1187 | |
| 1188 | # push to delete a hidden ref should fail |
| 1189 | test_must_fail git push testrepo :refs/hidden/two && |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 1190 | check_push_result testrepo $the_first_commit hidden/two && |
Junio C Hamano | daebaa7 | 2013-01-18 16:08:30 -0800 | [diff] [blame] | 1191 | |
| 1192 | # idempotent push to update a hidden ref should fail |
| 1193 | test_must_fail git push testrepo $the_first_commit:refs/hidden/three && |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 1194 | check_push_result testrepo $the_first_commit hidden/three |
Junio C Hamano | daebaa7 | 2013-01-18 16:08:30 -0800 | [diff] [blame] | 1195 | ' |
| 1196 | done |
| 1197 | |
Junio C Hamano | 6e7b66e | 2013-01-29 14:02:15 -0800 | [diff] [blame] | 1198 | test_expect_success 'fetch exact SHA1' ' |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1199 | mk_test testrepo heads/main hidden/one && |
| 1200 | git push testrepo main:refs/hidden/one && |
Junio C Hamano | 6e7b66e | 2013-01-29 14:02:15 -0800 | [diff] [blame] | 1201 | ( |
| 1202 | cd testrepo && |
| 1203 | git config transfer.hiderefs refs/hidden |
| 1204 | ) && |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 1205 | check_push_result testrepo $the_commit hidden/one && |
Junio C Hamano | 6e7b66e | 2013-01-29 14:02:15 -0800 | [diff] [blame] | 1206 | |
Jeff King | 2e433b7 | 2013-04-02 13:10:31 +0530 | [diff] [blame] | 1207 | mk_child testrepo child && |
Junio C Hamano | 6e7b66e | 2013-01-29 14:02:15 -0800 | [diff] [blame] | 1208 | ( |
| 1209 | cd child && |
| 1210 | |
| 1211 | # make sure $the_commit does not exist here |
| 1212 | git repack -a -d && |
| 1213 | git prune && |
| 1214 | test_must_fail git cat-file -t $the_commit && |
| 1215 | |
Jonathan Tan | ab0c5f5 | 2019-02-25 13:54:08 -0800 | [diff] [blame] | 1216 | # Some protocol versions (e.g. 2) support fetching |
| 1217 | # unadvertised objects, so restrict this test to v0. |
| 1218 | |
Junio C Hamano | 6e7b66e | 2013-01-29 14:02:15 -0800 | [diff] [blame] | 1219 | # fetching the hidden object should fail by default |
Jonathan Nieder | 8a1b097 | 2019-12-23 17:01:10 -0800 | [diff] [blame] | 1220 | test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \ |
Jonathan Tan | ab0c5f5 | 2019-02-25 13:54:08 -0800 | [diff] [blame] | 1221 | git fetch -v ../testrepo $the_commit:refs/heads/copy 2>err && |
Matt McCutchen | d56583d | 2017-02-22 11:05:57 -0500 | [diff] [blame] | 1222 | test_i18ngrep "Server does not allow request for unadvertised object" err && |
Junio C Hamano | 6e7b66e | 2013-01-29 14:02:15 -0800 | [diff] [blame] | 1223 | test_must_fail git rev-parse --verify refs/heads/copy && |
| 1224 | |
| 1225 | # the server side can allow it to succeed |
| 1226 | ( |
| 1227 | cd ../testrepo && |
| 1228 | git config uploadpack.allowtipsha1inwant true |
| 1229 | ) && |
| 1230 | |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1231 | git fetch -v ../testrepo $the_commit:refs/heads/copy main:refs/heads/extra && |
Jeff King | c3c17bf | 2015-03-19 16:37:09 -0400 | [diff] [blame] | 1232 | cat >expect <<-EOF && |
| 1233 | $the_commit |
| 1234 | $the_first_commit |
| 1235 | EOF |
| 1236 | { |
| 1237 | git rev-parse --verify refs/heads/copy && |
| 1238 | git rev-parse --verify refs/heads/extra |
| 1239 | } >actual && |
| 1240 | test_cmp expect actual |
Junio C Hamano | 6e7b66e | 2013-01-29 14:02:15 -0800 | [diff] [blame] | 1241 | ) |
| 1242 | ' |
| 1243 | |
Jonathan Nieder | 6c301ad | 2018-05-31 00:23:39 -0700 | [diff] [blame] | 1244 | test_expect_success 'fetch exact SHA1 in protocol v2' ' |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1245 | mk_test testrepo heads/main hidden/one && |
| 1246 | git push testrepo main:refs/hidden/one && |
Jonathan Nieder | 6c301ad | 2018-05-31 00:23:39 -0700 | [diff] [blame] | 1247 | git -C testrepo config transfer.hiderefs refs/hidden && |
| 1248 | check_push_result testrepo $the_commit hidden/one && |
| 1249 | |
| 1250 | mk_child testrepo child && |
| 1251 | git -C child config protocol.version 2 && |
| 1252 | |
| 1253 | # make sure $the_commit does not exist here |
| 1254 | git -C child repack -a -d && |
| 1255 | git -C child prune && |
| 1256 | test_must_fail git -C child cat-file -t $the_commit && |
| 1257 | |
| 1258 | # fetching the hidden object succeeds by default |
| 1259 | # NEEDSWORK: should this match the v0 behavior instead? |
| 1260 | git -C child fetch -v ../testrepo $the_commit:refs/heads/copy |
| 1261 | ' |
| 1262 | |
Fredrik Medley | 68ee628 | 2015-05-21 22:23:39 +0200 | [diff] [blame] | 1263 | for configallowtipsha1inwant in true false |
| 1264 | do |
| 1265 | test_expect_success "shallow fetch reachable SHA1 (but not a ref), allowtipsha1inwant=$configallowtipsha1inwant" ' |
| 1266 | mk_empty testrepo && |
| 1267 | ( |
| 1268 | cd testrepo && |
| 1269 | git config uploadpack.allowtipsha1inwant $configallowtipsha1inwant && |
| 1270 | git commit --allow-empty -m foo && |
| 1271 | git commit --allow-empty -m bar |
| 1272 | ) && |
| 1273 | SHA1=$(git --git-dir=testrepo/.git rev-parse HEAD^) && |
| 1274 | mk_empty shallow && |
| 1275 | ( |
| 1276 | cd shallow && |
Jonathan Tan | ab0c5f5 | 2019-02-25 13:54:08 -0800 | [diff] [blame] | 1277 | # Some protocol versions (e.g. 2) support fetching |
| 1278 | # unadvertised objects, so restrict this test to v0. |
Jonathan Nieder | 8a1b097 | 2019-12-23 17:01:10 -0800 | [diff] [blame] | 1279 | test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \ |
Jonathan Tan | ab0c5f5 | 2019-02-25 13:54:08 -0800 | [diff] [blame] | 1280 | git fetch --depth=1 ../testrepo/.git $SHA1 && |
Fredrik Medley | 68ee628 | 2015-05-21 22:23:39 +0200 | [diff] [blame] | 1281 | git --git-dir=../testrepo/.git config uploadpack.allowreachablesha1inwant true && |
| 1282 | git fetch --depth=1 ../testrepo/.git $SHA1 && |
| 1283 | git cat-file commit $SHA1 |
| 1284 | ) |
| 1285 | ' |
| 1286 | |
| 1287 | test_expect_success "deny fetch unreachable SHA1, allowtipsha1inwant=$configallowtipsha1inwant" ' |
| 1288 | mk_empty testrepo && |
| 1289 | ( |
| 1290 | cd testrepo && |
| 1291 | git config uploadpack.allowtipsha1inwant $configallowtipsha1inwant && |
| 1292 | git commit --allow-empty -m foo && |
| 1293 | git commit --allow-empty -m bar && |
| 1294 | git commit --allow-empty -m xyz |
| 1295 | ) && |
| 1296 | SHA1_1=$(git --git-dir=testrepo/.git rev-parse HEAD^^) && |
| 1297 | SHA1_2=$(git --git-dir=testrepo/.git rev-parse HEAD^) && |
| 1298 | SHA1_3=$(git --git-dir=testrepo/.git rev-parse HEAD) && |
| 1299 | ( |
| 1300 | cd testrepo && |
| 1301 | git reset --hard $SHA1_2 && |
| 1302 | git cat-file commit $SHA1_1 && |
| 1303 | git cat-file commit $SHA1_3 |
| 1304 | ) && |
| 1305 | mk_empty shallow && |
| 1306 | ( |
| 1307 | cd shallow && |
Jonathan Tan | ab0c5f5 | 2019-02-25 13:54:08 -0800 | [diff] [blame] | 1308 | # Some protocol versions (e.g. 2) support fetching |
| 1309 | # unadvertised objects, so restrict this test to v0. |
Jonathan Nieder | 8a1b097 | 2019-12-23 17:01:10 -0800 | [diff] [blame] | 1310 | test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \ |
Jonathan Tan | ab0c5f5 | 2019-02-25 13:54:08 -0800 | [diff] [blame] | 1311 | git fetch ../testrepo/.git $SHA1_3 && |
Jonathan Nieder | 8a1b097 | 2019-12-23 17:01:10 -0800 | [diff] [blame] | 1312 | test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \ |
Jonathan Tan | ab0c5f5 | 2019-02-25 13:54:08 -0800 | [diff] [blame] | 1313 | git fetch ../testrepo/.git $SHA1_1 && |
Fredrik Medley | 68ee628 | 2015-05-21 22:23:39 +0200 | [diff] [blame] | 1314 | git --git-dir=../testrepo/.git config uploadpack.allowreachablesha1inwant true && |
| 1315 | git fetch ../testrepo/.git $SHA1_1 && |
| 1316 | git cat-file commit $SHA1_1 && |
| 1317 | test_must_fail git cat-file commit $SHA1_2 && |
| 1318 | git fetch ../testrepo/.git $SHA1_2 && |
| 1319 | git cat-file commit $SHA1_2 && |
Jonathan Nieder | 8a1b097 | 2019-12-23 17:01:10 -0800 | [diff] [blame] | 1320 | test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \ |
Junio C Hamano | 57a6b93 | 2019-04-25 16:41:23 +0900 | [diff] [blame] | 1321 | git fetch ../testrepo/.git $SHA1_3 2>err && |
Jeff King | acaabcf | 2021-01-09 22:23:09 -0500 | [diff] [blame] | 1322 | # ideally we would insist this be on a "remote error:" |
| 1323 | # line, but it is racy; see the commit message |
| 1324 | test_i18ngrep "not our ref.*$SHA1_3\$" err |
Fredrik Medley | 68ee628 | 2015-05-21 22:23:39 +0200 | [diff] [blame] | 1325 | ) |
| 1326 | ' |
| 1327 | done |
| 1328 | |
Junio C Hamano | c2aba15 | 2013-03-04 12:09:50 -0800 | [diff] [blame] | 1329 | test_expect_success 'fetch follows tags by default' ' |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1330 | mk_test testrepo heads/main && |
Junio C Hamano | c2aba15 | 2013-03-04 12:09:50 -0800 | [diff] [blame] | 1331 | rm -fr src dst && |
| 1332 | git init src && |
| 1333 | ( |
| 1334 | cd src && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1335 | git pull ../testrepo main && |
Junio C Hamano | c2aba15 | 2013-03-04 12:09:50 -0800 | [diff] [blame] | 1336 | git tag -m "annotated" tag && |
| 1337 | git for-each-ref >tmp1 && |
| 1338 | ( |
| 1339 | cat tmp1 |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1340 | sed -n "s|refs/heads/main$|refs/remotes/origin/main|p" tmp1 |
Junio C Hamano | c2aba15 | 2013-03-04 12:09:50 -0800 | [diff] [blame] | 1341 | ) | |
| 1342 | sort -k 3 >../expect |
| 1343 | ) && |
| 1344 | git init dst && |
| 1345 | ( |
| 1346 | cd dst && |
| 1347 | git remote add origin ../src && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1348 | git config branch.main.remote origin && |
| 1349 | git config branch.main.merge refs/heads/main && |
Junio C Hamano | c2aba15 | 2013-03-04 12:09:50 -0800 | [diff] [blame] | 1350 | git pull && |
| 1351 | git for-each-ref >../actual |
| 1352 | ) && |
| 1353 | test_cmp expect actual |
| 1354 | ' |
| 1355 | |
Jeff King | 34066f0 | 2019-04-13 01:57:37 -0400 | [diff] [blame] | 1356 | test_expect_success 'peeled advertisements are not considered ref tips' ' |
| 1357 | mk_empty testrepo && |
| 1358 | git -C testrepo commit --allow-empty -m one && |
| 1359 | git -C testrepo commit --allow-empty -m two && |
| 1360 | git -C testrepo tag -m foo mytag HEAD^ && |
| 1361 | oid=$(git -C testrepo rev-parse mytag^{commit}) && |
Jonathan Nieder | 8a1b097 | 2019-12-23 17:01:10 -0800 | [diff] [blame] | 1362 | test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \ |
Jeff King | 34066f0 | 2019-04-13 01:57:37 -0400 | [diff] [blame] | 1363 | git fetch testrepo $oid 2>err && |
| 1364 | test_i18ngrep "Server does not allow request for unadvertised object" err |
| 1365 | ' |
| 1366 | |
Junio C Hamano | ca02465 | 2013-12-03 15:41:15 -0800 | [diff] [blame] | 1367 | test_expect_success 'pushing a specific ref applies remote.$name.push as refmap' ' |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1368 | mk_test testrepo heads/main && |
Junio C Hamano | ca02465 | 2013-12-03 15:41:15 -0800 | [diff] [blame] | 1369 | rm -fr src dst && |
| 1370 | git init src && |
| 1371 | git init --bare dst && |
| 1372 | ( |
| 1373 | cd src && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1374 | git pull ../testrepo main && |
Junio C Hamano | ca02465 | 2013-12-03 15:41:15 -0800 | [diff] [blame] | 1375 | git branch next && |
| 1376 | git config remote.dst.url ../dst && |
| 1377 | git config remote.dst.push "+refs/heads/*:refs/remotes/src/*" && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1378 | git push dst main && |
| 1379 | git show-ref refs/heads/main | |
Junio C Hamano | ca02465 | 2013-12-03 15:41:15 -0800 | [diff] [blame] | 1380 | sed -e "s|refs/heads/|refs/remotes/src/|" >../dst/expect |
| 1381 | ) && |
| 1382 | ( |
| 1383 | cd dst && |
| 1384 | test_must_fail git show-ref refs/heads/next && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1385 | test_must_fail git show-ref refs/heads/main && |
| 1386 | git show-ref refs/remotes/src/main >actual |
Junio C Hamano | ca02465 | 2013-12-03 15:41:15 -0800 | [diff] [blame] | 1387 | ) && |
| 1388 | test_cmp dst/expect dst/actual |
| 1389 | ' |
| 1390 | |
| 1391 | test_expect_success 'with no remote.$name.push, it is not used as refmap' ' |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1392 | mk_test testrepo heads/main && |
Junio C Hamano | ca02465 | 2013-12-03 15:41:15 -0800 | [diff] [blame] | 1393 | rm -fr src dst && |
| 1394 | git init src && |
| 1395 | git init --bare dst && |
| 1396 | ( |
| 1397 | cd src && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1398 | git pull ../testrepo main && |
Junio C Hamano | ca02465 | 2013-12-03 15:41:15 -0800 | [diff] [blame] | 1399 | git branch next && |
| 1400 | git config remote.dst.url ../dst && |
Junio C Hamano | fc9261c | 2013-12-03 16:23:35 -0800 | [diff] [blame] | 1401 | git config push.default matching && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1402 | git push dst main && |
| 1403 | git show-ref refs/heads/main >../dst/expect |
Junio C Hamano | ca02465 | 2013-12-03 15:41:15 -0800 | [diff] [blame] | 1404 | ) && |
| 1405 | ( |
| 1406 | cd dst && |
| 1407 | test_must_fail git show-ref refs/heads/next && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1408 | git show-ref refs/heads/main >actual |
Junio C Hamano | ca02465 | 2013-12-03 15:41:15 -0800 | [diff] [blame] | 1409 | ) && |
| 1410 | test_cmp dst/expect dst/actual |
| 1411 | ' |
| 1412 | |
Junio C Hamano | fc9261c | 2013-12-03 16:23:35 -0800 | [diff] [blame] | 1413 | test_expect_success 'with no remote.$name.push, upstream mapping is used' ' |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1414 | mk_test testrepo heads/main && |
Junio C Hamano | fc9261c | 2013-12-03 16:23:35 -0800 | [diff] [blame] | 1415 | rm -fr src dst && |
| 1416 | git init src && |
| 1417 | git init --bare dst && |
| 1418 | ( |
| 1419 | cd src && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1420 | git pull ../testrepo main && |
Junio C Hamano | fc9261c | 2013-12-03 16:23:35 -0800 | [diff] [blame] | 1421 | git branch next && |
| 1422 | git config remote.dst.url ../dst && |
| 1423 | git config remote.dst.fetch "+refs/heads/*:refs/remotes/dst/*" && |
| 1424 | git config push.default upstream && |
| 1425 | |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1426 | git config branch.main.merge refs/heads/trunk && |
| 1427 | git config branch.main.remote dst && |
Junio C Hamano | fc9261c | 2013-12-03 16:23:35 -0800 | [diff] [blame] | 1428 | |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1429 | git push dst main && |
| 1430 | git show-ref refs/heads/main | |
| 1431 | sed -e "s|refs/heads/main|refs/heads/trunk|" >../dst/expect |
Junio C Hamano | fc9261c | 2013-12-03 16:23:35 -0800 | [diff] [blame] | 1432 | ) && |
| 1433 | ( |
| 1434 | cd dst && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1435 | test_must_fail git show-ref refs/heads/main && |
Junio C Hamano | fc9261c | 2013-12-03 16:23:35 -0800 | [diff] [blame] | 1436 | test_must_fail git show-ref refs/heads/next && |
| 1437 | git show-ref refs/heads/trunk >actual |
| 1438 | ) && |
| 1439 | test_cmp dst/expect dst/actual |
| 1440 | ' |
| 1441 | |
Junio C Hamano | c2aba15 | 2013-03-04 12:09:50 -0800 | [diff] [blame] | 1442 | test_expect_success 'push does not follow tags by default' ' |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1443 | mk_test testrepo heads/main && |
Junio C Hamano | c2aba15 | 2013-03-04 12:09:50 -0800 | [diff] [blame] | 1444 | rm -fr src dst && |
| 1445 | git init src && |
| 1446 | git init --bare dst && |
| 1447 | ( |
| 1448 | cd src && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1449 | git pull ../testrepo main && |
Junio C Hamano | c2aba15 | 2013-03-04 12:09:50 -0800 | [diff] [blame] | 1450 | git tag -m "annotated" tag && |
| 1451 | git checkout -b another && |
| 1452 | git commit --allow-empty -m "future commit" && |
| 1453 | git tag -m "future" future && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1454 | git checkout main && |
| 1455 | git for-each-ref refs/heads/main >../expect && |
| 1456 | git push ../dst main |
Junio C Hamano | c2aba15 | 2013-03-04 12:09:50 -0800 | [diff] [blame] | 1457 | ) && |
| 1458 | ( |
| 1459 | cd dst && |
| 1460 | git for-each-ref >../actual |
| 1461 | ) && |
| 1462 | test_cmp expect actual |
| 1463 | ' |
| 1464 | |
Johannes Schindelin | f6188dc | 2019-03-25 11:14:21 -0700 | [diff] [blame] | 1465 | test_expect_success 'push --follow-tags only pushes relevant tags' ' |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1466 | mk_test testrepo heads/main && |
Junio C Hamano | c2aba15 | 2013-03-04 12:09:50 -0800 | [diff] [blame] | 1467 | rm -fr src dst && |
| 1468 | git init src && |
| 1469 | git init --bare dst && |
| 1470 | ( |
| 1471 | cd src && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1472 | git pull ../testrepo main && |
Junio C Hamano | c2aba15 | 2013-03-04 12:09:50 -0800 | [diff] [blame] | 1473 | git tag -m "annotated" tag && |
| 1474 | git checkout -b another && |
| 1475 | git commit --allow-empty -m "future commit" && |
| 1476 | git tag -m "future" future && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1477 | git checkout main && |
| 1478 | git for-each-ref refs/heads/main refs/tags/tag >../expect && |
| 1479 | git push --follow-tags ../dst main |
Junio C Hamano | c2aba15 | 2013-03-04 12:09:50 -0800 | [diff] [blame] | 1480 | ) && |
| 1481 | ( |
| 1482 | cd dst && |
| 1483 | git for-each-ref >../actual |
| 1484 | ) && |
| 1485 | test_cmp expect actual |
| 1486 | ' |
| 1487 | |
Nguyễn Thái Ngọc Duy | f7c815c | 2013-08-12 20:55:55 +0700 | [diff] [blame] | 1488 | test_expect_success 'push --no-thin must produce non-thin pack' ' |
| 1489 | cat >>path1 <<\EOF && |
| 1490 | keep base version of path1 big enough, compared to the new changes |
| 1491 | later, in order to pass size heuristics in |
| 1492 | builtin/pack-objects.c:try_delta() |
| 1493 | EOF |
| 1494 | git commit -am initial && |
| 1495 | git init no-thin && |
| 1496 | git --git-dir=no-thin/.git config receive.unpacklimit 0 && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1497 | git push no-thin/.git refs/heads/main:refs/heads/foo && |
Nguyễn Thái Ngọc Duy | f7c815c | 2013-08-12 20:55:55 +0700 | [diff] [blame] | 1498 | echo modified >> path1 && |
| 1499 | git commit -am modified && |
| 1500 | git repack -adf && |
| 1501 | rcvpck="git receive-pack --reject-thin-pack-for-testing" && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1502 | git push --no-thin --receive-pack="$rcvpck" no-thin/.git refs/heads/main:refs/heads/foo |
Nguyễn Thái Ngọc Duy | f7c815c | 2013-08-12 20:55:55 +0700 | [diff] [blame] | 1503 | ' |
| 1504 | |
Jeff King | 458a7e5 | 2014-10-16 20:03:41 -0400 | [diff] [blame] | 1505 | test_expect_success 'pushing a tag pushes the tagged object' ' |
| 1506 | rm -rf dst.git && |
| 1507 | blob=$(echo unreferenced | git hash-object -w --stdin) && |
| 1508 | git tag -m foo tag-of-blob $blob && |
| 1509 | git init --bare dst.git && |
| 1510 | git push dst.git tag-of-blob && |
| 1511 | # the receiving index-pack should have noticed |
| 1512 | # any problems, but we double check |
| 1513 | echo unreferenced >expect && |
| 1514 | git --git-dir=dst.git cat-file blob tag-of-blob >actual && |
| 1515 | test_cmp expect actual |
| 1516 | ' |
| 1517 | |
Jeff King | 72549df | 2014-11-04 08:11:19 -0500 | [diff] [blame] | 1518 | test_expect_success 'push into bare respects core.logallrefupdates' ' |
| 1519 | rm -rf dst.git && |
| 1520 | git init --bare dst.git && |
| 1521 | git -C dst.git config core.logallrefupdates true && |
| 1522 | |
| 1523 | # double push to test both with and without |
| 1524 | # the actual pack transfer |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1525 | git push dst.git main:one && |
Jeff King | 72549df | 2014-11-04 08:11:19 -0500 | [diff] [blame] | 1526 | echo "one@{0} push" >expect && |
| 1527 | git -C dst.git log -g --format="%gd %gs" one >actual && |
| 1528 | test_cmp expect actual && |
| 1529 | |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1530 | git push dst.git main:two && |
Jeff King | 72549df | 2014-11-04 08:11:19 -0500 | [diff] [blame] | 1531 | echo "two@{0} push" >expect && |
| 1532 | git -C dst.git log -g --format="%gd %gs" two >actual && |
| 1533 | test_cmp expect actual |
| 1534 | ' |
| 1535 | |
| 1536 | test_expect_success 'fetch into bare respects core.logallrefupdates' ' |
| 1537 | rm -rf dst.git && |
| 1538 | git init --bare dst.git && |
| 1539 | ( |
| 1540 | cd dst.git && |
| 1541 | git config core.logallrefupdates true && |
| 1542 | |
| 1543 | # as above, we double-fetch to test both |
| 1544 | # with and without pack transfer |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1545 | git fetch .. main:one && |
| 1546 | echo "one@{0} fetch .. main:one: storing head" >expect && |
Jeff King | 72549df | 2014-11-04 08:11:19 -0500 | [diff] [blame] | 1547 | git log -g --format="%gd %gs" one >actual && |
| 1548 | test_cmp expect actual && |
| 1549 | |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1550 | git fetch .. main:two && |
| 1551 | echo "two@{0} fetch .. main:two: storing head" >expect && |
Jeff King | 72549df | 2014-11-04 08:11:19 -0500 | [diff] [blame] | 1552 | git log -g --format="%gd %gs" two >actual && |
| 1553 | test_cmp expect actual |
| 1554 | ) |
| 1555 | ' |
| 1556 | |
Johannes Schindelin | 1404bcb | 2014-11-26 23:44:16 +0100 | [diff] [blame] | 1557 | test_expect_success 'receive.denyCurrentBranch = updateInstead' ' |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1558 | git push testrepo main && |
Junio C Hamano | 4d7a5ce | 2014-11-30 17:54:30 -0800 | [diff] [blame] | 1559 | ( |
| 1560 | cd testrepo && |
Johannes Schindelin | 1404bcb | 2014-11-26 23:44:16 +0100 | [diff] [blame] | 1561 | git reset --hard && |
| 1562 | git config receive.denyCurrentBranch updateInstead |
| 1563 | ) && |
| 1564 | test_commit third path2 && |
Junio C Hamano | 4d7a5ce | 2014-11-30 17:54:30 -0800 | [diff] [blame] | 1565 | |
| 1566 | # Try pushing into a repository with pristine working tree |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1567 | git push testrepo main && |
Junio C Hamano | 4d7a5ce | 2014-11-30 17:54:30 -0800 | [diff] [blame] | 1568 | ( |
| 1569 | cd testrepo && |
Johannes Schindelin | 1404bcb | 2014-11-26 23:44:16 +0100 | [diff] [blame] | 1570 | git update-index -q --refresh && |
| 1571 | git diff-files --quiet -- && |
| 1572 | git diff-index --quiet --cached HEAD -- && |
Junio C Hamano | 4d7a5ce | 2014-11-30 17:54:30 -0800 | [diff] [blame] | 1573 | test third = "$(cat path2)" && |
| 1574 | test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD) |
Johannes Schindelin | 1404bcb | 2014-11-26 23:44:16 +0100 | [diff] [blame] | 1575 | ) && |
Junio C Hamano | 4d7a5ce | 2014-11-30 17:54:30 -0800 | [diff] [blame] | 1576 | |
| 1577 | # Try pushing into a repository with working tree needing a refresh |
| 1578 | ( |
| 1579 | cd testrepo && |
| 1580 | git reset --hard HEAD^ && |
| 1581 | test $(git -C .. rev-parse HEAD^) = $(git rev-parse HEAD) && |
Nguyễn Thái Ngọc Duy | 0e49649 | 2018-03-24 08:44:31 +0100 | [diff] [blame] | 1582 | test-tool chmtime +100 path1 |
Junio C Hamano | 4d7a5ce | 2014-11-30 17:54:30 -0800 | [diff] [blame] | 1583 | ) && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1584 | git push testrepo main && |
Junio C Hamano | 4d7a5ce | 2014-11-30 17:54:30 -0800 | [diff] [blame] | 1585 | ( |
| 1586 | cd testrepo && |
| 1587 | git update-index -q --refresh && |
| 1588 | git diff-files --quiet -- && |
| 1589 | git diff-index --quiet --cached HEAD -- && |
| 1590 | test_cmp ../path1 path1 && |
| 1591 | test third = "$(cat path2)" && |
| 1592 | test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD) |
| 1593 | ) && |
| 1594 | |
| 1595 | # Update what is to be pushed |
Johannes Schindelin | 1404bcb | 2014-11-26 23:44:16 +0100 | [diff] [blame] | 1596 | test_commit fourth path2 && |
Junio C Hamano | 4d7a5ce | 2014-11-30 17:54:30 -0800 | [diff] [blame] | 1597 | |
| 1598 | # Try pushing into a repository with a dirty working tree |
| 1599 | # (1) the working tree updated |
| 1600 | ( |
| 1601 | cd testrepo && |
| 1602 | echo changed >path1 |
| 1603 | ) && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1604 | test_must_fail git push testrepo main && |
Junio C Hamano | 4d7a5ce | 2014-11-30 17:54:30 -0800 | [diff] [blame] | 1605 | ( |
| 1606 | cd testrepo && |
| 1607 | test $(git -C .. rev-parse HEAD^) = $(git rev-parse HEAD) && |
| 1608 | git diff --quiet --cached && |
| 1609 | test changed = "$(cat path1)" |
| 1610 | ) && |
| 1611 | |
| 1612 | # (2) the index updated |
| 1613 | ( |
| 1614 | cd testrepo && |
| 1615 | echo changed >path1 && |
| 1616 | git add path1 |
| 1617 | ) && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1618 | test_must_fail git push testrepo main && |
Junio C Hamano | 4d7a5ce | 2014-11-30 17:54:30 -0800 | [diff] [blame] | 1619 | ( |
| 1620 | cd testrepo && |
| 1621 | test $(git -C .. rev-parse HEAD^) = $(git rev-parse HEAD) && |
Johannes Schindelin | 1404bcb | 2014-11-26 23:44:16 +0100 | [diff] [blame] | 1622 | git diff --quiet && |
Junio C Hamano | 4d7a5ce | 2014-11-30 17:54:30 -0800 | [diff] [blame] | 1623 | test changed = "$(cat path1)" |
| 1624 | ) && |
| 1625 | |
| 1626 | # Introduce a new file in the update |
| 1627 | test_commit fifth path3 && |
| 1628 | |
| 1629 | # (3) the working tree has an untracked file that would interfere |
| 1630 | ( |
| 1631 | cd testrepo && |
| 1632 | git reset --hard && |
| 1633 | echo changed >path3 |
| 1634 | ) && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1635 | test_must_fail git push testrepo main && |
Junio C Hamano | 4d7a5ce | 2014-11-30 17:54:30 -0800 | [diff] [blame] | 1636 | ( |
| 1637 | cd testrepo && |
| 1638 | test $(git -C .. rev-parse HEAD^^) = $(git rev-parse HEAD) && |
| 1639 | git diff --quiet && |
| 1640 | git diff --quiet --cached && |
| 1641 | test changed = "$(cat path3)" |
| 1642 | ) && |
| 1643 | |
| 1644 | # (4) the target changes to what gets pushed but it still is a change |
| 1645 | ( |
| 1646 | cd testrepo && |
| 1647 | git reset --hard && |
| 1648 | echo fifth >path3 && |
| 1649 | git add path3 |
| 1650 | ) && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1651 | test_must_fail git push testrepo main && |
Junio C Hamano | 4d7a5ce | 2014-11-30 17:54:30 -0800 | [diff] [blame] | 1652 | ( |
| 1653 | cd testrepo && |
| 1654 | test $(git -C .. rev-parse HEAD^^) = $(git rev-parse HEAD) && |
| 1655 | git diff --quiet && |
| 1656 | test fifth = "$(cat path3)" |
Junio C Hamano | 1a51b52 | 2015-03-31 23:15:45 -0700 | [diff] [blame] | 1657 | ) && |
Junio C Hamano | 4d7a5ce | 2014-11-30 17:54:30 -0800 | [diff] [blame] | 1658 | |
Junio C Hamano | 1a51b52 | 2015-03-31 23:15:45 -0700 | [diff] [blame] | 1659 | # (5) push into void |
| 1660 | rm -fr void && |
| 1661 | git init void && |
| 1662 | ( |
| 1663 | cd void && |
| 1664 | git config receive.denyCurrentBranch updateInstead |
| 1665 | ) && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1666 | git push void main && |
Junio C Hamano | 1a51b52 | 2015-03-31 23:15:45 -0700 | [diff] [blame] | 1667 | ( |
| 1668 | cd void && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1669 | test $(git -C .. rev-parse main) = $(git rev-parse HEAD) && |
Junio C Hamano | 1a51b52 | 2015-03-31 23:15:45 -0700 | [diff] [blame] | 1670 | git diff --quiet && |
| 1671 | git diff --cached --quiet |
Junio C Hamano | b072a25 | 2018-10-19 13:57:35 +0900 | [diff] [blame] | 1672 | ) && |
| 1673 | |
| 1674 | # (6) updateInstead intervened by fast-forward check |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1675 | test_must_fail git push void main^:main && |
| 1676 | test $(git -C void rev-parse HEAD) = $(git rev-parse main) && |
Junio C Hamano | b072a25 | 2018-10-19 13:57:35 +0900 | [diff] [blame] | 1677 | git -C void diff --quiet && |
| 1678 | git -C void diff --cached --quiet |
Johannes Schindelin | 1404bcb | 2014-11-26 23:44:16 +0100 | [diff] [blame] | 1679 | ' |
| 1680 | |
Junio C Hamano | 0855331 | 2014-12-01 15:29:54 -0800 | [diff] [blame] | 1681 | test_expect_success 'updateInstead with push-to-checkout hook' ' |
| 1682 | rm -fr testrepo && |
| 1683 | git init testrepo && |
| 1684 | ( |
| 1685 | cd testrepo && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1686 | git pull .. main && |
Junio C Hamano | 0855331 | 2014-12-01 15:29:54 -0800 | [diff] [blame] | 1687 | git reset --hard HEAD^^ && |
| 1688 | git tag initial && |
| 1689 | git config receive.denyCurrentBranch updateInstead && |
| 1690 | write_script .git/hooks/push-to-checkout <<-\EOF |
| 1691 | echo >&2 updating from $(git rev-parse HEAD) |
| 1692 | echo >&2 updating to "$1" |
| 1693 | |
| 1694 | git update-index -q --refresh && |
| 1695 | git read-tree -u -m HEAD "$1" || { |
| 1696 | status=$? |
| 1697 | echo >&2 read-tree failed |
| 1698 | exit $status |
| 1699 | } |
| 1700 | EOF |
| 1701 | ) && |
| 1702 | |
| 1703 | # Try pushing into a pristine |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1704 | git push testrepo main && |
Junio C Hamano | 0855331 | 2014-12-01 15:29:54 -0800 | [diff] [blame] | 1705 | ( |
| 1706 | cd testrepo && |
| 1707 | git diff --quiet && |
| 1708 | git diff HEAD --quiet && |
| 1709 | test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD) |
| 1710 | ) && |
| 1711 | |
| 1712 | # Try pushing into a repository with conflicting change |
| 1713 | ( |
| 1714 | cd testrepo && |
| 1715 | git reset --hard initial && |
| 1716 | echo conflicting >path2 |
| 1717 | ) && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1718 | test_must_fail git push testrepo main && |
Junio C Hamano | 0855331 | 2014-12-01 15:29:54 -0800 | [diff] [blame] | 1719 | ( |
| 1720 | cd testrepo && |
| 1721 | test $(git rev-parse initial) = $(git rev-parse HEAD) && |
| 1722 | test conflicting = "$(cat path2)" && |
| 1723 | git diff-index --quiet --cached HEAD |
| 1724 | ) && |
| 1725 | |
| 1726 | # Try pushing into a repository with unrelated change |
| 1727 | ( |
| 1728 | cd testrepo && |
| 1729 | git reset --hard initial && |
| 1730 | echo unrelated >path1 && |
| 1731 | echo irrelevant >path5 && |
| 1732 | git add path5 |
| 1733 | ) && |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1734 | git push testrepo main && |
Junio C Hamano | 0855331 | 2014-12-01 15:29:54 -0800 | [diff] [blame] | 1735 | ( |
| 1736 | cd testrepo && |
| 1737 | test "$(cat path1)" = unrelated && |
| 1738 | test "$(cat path5)" = irrelevant && |
| 1739 | test "$(git diff --name-only --cached HEAD)" = path5 && |
| 1740 | test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD) |
Junio C Hamano | 1a51b52 | 2015-03-31 23:15:45 -0700 | [diff] [blame] | 1741 | ) && |
| 1742 | |
| 1743 | # push into void |
| 1744 | rm -fr void && |
| 1745 | git init void && |
| 1746 | ( |
| 1747 | cd void && |
| 1748 | git config receive.denyCurrentBranch updateInstead && |
| 1749 | write_script .git/hooks/push-to-checkout <<-\EOF |
| 1750 | if git rev-parse --quiet --verify HEAD |
| 1751 | then |
| 1752 | has_head=yes |
| 1753 | echo >&2 updating from $(git rev-parse HEAD) |
| 1754 | else |
| 1755 | has_head=no |
| 1756 | echo >&2 pushing into void |
| 1757 | fi |
| 1758 | echo >&2 updating to "$1" |
| 1759 | |
| 1760 | git update-index -q --refresh && |
| 1761 | case "$has_head" in |
| 1762 | yes) |
| 1763 | git read-tree -u -m HEAD "$1" ;; |
| 1764 | no) |
| 1765 | git read-tree -u -m "$1" ;; |
| 1766 | esac || { |
| 1767 | status=$? |
| 1768 | echo >&2 read-tree failed |
| 1769 | exit $status |
| 1770 | } |
| 1771 | EOF |
| 1772 | ) && |
| 1773 | |
Johannes Schindelin | bc925ce | 2020-11-18 23:44:32 +0000 | [diff] [blame] | 1774 | git push void main && |
Junio C Hamano | 1a51b52 | 2015-03-31 23:15:45 -0700 | [diff] [blame] | 1775 | ( |
| 1776 | cd void && |
| 1777 | git diff --quiet && |
| 1778 | git diff --cached --quiet && |
| 1779 | test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD) |
Junio C Hamano | 0855331 | 2014-12-01 15:29:54 -0800 | [diff] [blame] | 1780 | ) |
| 1781 | ' |
| 1782 | |
Hariom Verma | 4ef3464 | 2020-02-23 18:57:10 +0000 | [diff] [blame] | 1783 | test_expect_success 'denyCurrentBranch and worktrees' ' |
| 1784 | git worktree add new-wt && |
| 1785 | git clone . cloned && |
| 1786 | test_commit -C cloned first && |
| 1787 | test_config receive.denyCurrentBranch refuse && |
| 1788 | test_must_fail git -C cloned push origin HEAD:new-wt && |
| 1789 | test_config receive.denyCurrentBranch updateInstead && |
| 1790 | git -C cloned push origin HEAD:new-wt && |
| 1791 | test_must_fail git -C cloned push --delete origin new-wt |
| 1792 | ' |
Junio C Hamano | bcdb34f | 2007-06-08 00:43:22 -0700 | [diff] [blame] | 1793 | test_done |