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