Jeff King | ecaa0cf | 2007-12-19 10:43:50 -0500 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='basic clone options' |
Johannes Schindelin | 95cf2c0 | 2020-11-18 23:44:35 +0000 | [diff] [blame] | 4 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
Johannes Schindelin | 334afbc | 2020-11-18 23:44:19 +0000 | [diff] [blame] | 5 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 6 | |
Jeff King | ecaa0cf | 2007-12-19 10:43:50 -0500 | [diff] [blame] | 7 | . ./test-lib.sh |
| 8 | |
| 9 | test_expect_success 'setup' ' |
| 10 | |
| 11 | mkdir parent && |
| 12 | (cd parent && git init && |
| 13 | echo one >file && git add file && |
Li Linchao | 4fe788b | 2021-04-01 10:46:59 +0000 | [diff] [blame] | 14 | git commit -m one) && |
| 15 | git clone --depth=1 --no-local parent shallow-repo |
Jeff King | ecaa0cf | 2007-12-19 10:43:50 -0500 | [diff] [blame] | 16 | |
| 17 | ' |
| 18 | |
| 19 | test_expect_success 'clone -o' ' |
| 20 | |
| 21 | git clone -o foo parent clone-o && |
Johannes Schindelin | 95cf2c0 | 2020-11-18 23:44:35 +0000 | [diff] [blame] | 22 | git -C clone-o rev-parse --verify refs/remotes/foo/main |
Sean Barag | 349cff7 | 2020-09-29 03:36:49 +0000 | [diff] [blame] | 23 | |
| 24 | ' |
| 25 | |
Sean Barag | de9ed3e | 2020-10-01 03:46:16 +0000 | [diff] [blame] | 26 | test_expect_success 'rejects invalid -o/--origin' ' |
| 27 | |
| 28 | test_must_fail git clone -o "bad...name" parent clone-bad-name 2>err && |
| 29 | test_i18ngrep "'\''bad...name'\'' is not a valid remote name" err |
| 30 | |
| 31 | ' |
| 32 | |
Sean Barag | 349cff7 | 2020-09-29 03:36:49 +0000 | [diff] [blame] | 33 | test_expect_success 'disallows --bare with --origin' ' |
| 34 | |
| 35 | test_must_fail git clone -o foo --bare parent clone-bare-o 2>err && |
| 36 | test_debug "cat err" && |
| 37 | test_i18ngrep -e "--bare and --origin foo options are incompatible" err |
| 38 | |
| 39 | ' |
| 40 | |
| 41 | test_expect_success 'disallows --bare with --separate-git-dir' ' |
| 42 | |
| 43 | test_must_fail git clone --bare --separate-git-dir dot-git-destiation parent clone-bare-sgd 2>err && |
| 44 | test_debug "cat err" && |
| 45 | test_i18ngrep -e "--bare and --separate-git-dir are incompatible" err |
| 46 | |
| 47 | ' |
| 48 | |
Li Linchao | 4fe788b | 2021-04-01 10:46:59 +0000 | [diff] [blame] | 49 | test_expect_success 'reject cloning shallow repository' ' |
| 50 | test_when_finished "rm -rf repo" && |
| 51 | test_must_fail git clone --reject-shallow shallow-repo out 2>err && |
| 52 | test_i18ngrep -e "source repository is shallow, reject to clone." err && |
| 53 | |
| 54 | git clone --no-reject-shallow shallow-repo repo |
| 55 | ' |
| 56 | |
| 57 | test_expect_success 'reject cloning non-local shallow repository' ' |
| 58 | test_when_finished "rm -rf repo" && |
| 59 | test_must_fail git clone --reject-shallow --no-local shallow-repo out 2>err && |
| 60 | test_i18ngrep -e "source repository is shallow, reject to clone." err && |
| 61 | |
| 62 | git clone --no-reject-shallow --no-local shallow-repo repo |
| 63 | ' |
| 64 | |
| 65 | test_expect_success 'succeed cloning normal repository' ' |
| 66 | test_when_finished "rm -rf chilad1 child2 child3 child4 " && |
| 67 | git clone --reject-shallow parent child1 && |
| 68 | git clone --reject-shallow --no-local parent child2 && |
| 69 | git clone --no-reject-shallow parent child3 && |
| 70 | git clone --no-reject-shallow --no-local parent child4 |
| 71 | ' |
| 72 | |
Sean Barag | 349cff7 | 2020-09-29 03:36:49 +0000 | [diff] [blame] | 73 | test_expect_success 'uses "origin" for default remote name' ' |
| 74 | |
| 75 | git clone parent clone-default-origin && |
Johannes Schindelin | 95cf2c0 | 2020-11-18 23:44:35 +0000 | [diff] [blame] | 76 | git -C clone-default-origin rev-parse --verify refs/remotes/origin/main |
Sean Barag | 349cff7 | 2020-09-29 03:36:49 +0000 | [diff] [blame] | 77 | |
| 78 | ' |
| 79 | |
| 80 | test_expect_success 'prefers --template config over normal config' ' |
| 81 | |
| 82 | template="$TRASH_DIRECTORY/template-with-config" && |
| 83 | mkdir "$template" && |
| 84 | git config --file "$template/config" foo.bar from_template && |
| 85 | test_config_global foo.bar from_global && |
| 86 | git clone "--template=$template" parent clone-template-config && |
| 87 | test "$(git -C clone-template-config config --local foo.bar)" = "from_template" |
| 88 | |
| 89 | ' |
| 90 | |
| 91 | test_expect_success 'prefers -c config over --template config' ' |
| 92 | |
| 93 | template="$TRASH_DIRECTORY/template-with-ignored-config" && |
| 94 | mkdir "$template" && |
| 95 | git config --file "$template/config" foo.bar from_template && |
| 96 | git clone "--template=$template" -c foo.bar=inline parent clone-template-inline-config && |
| 97 | test "$(git -C clone-template-inline-config config --local foo.bar)" = "inline" |
Jeff King | ecaa0cf | 2007-12-19 10:43:50 -0500 | [diff] [blame] | 98 | |
| 99 | ' |
| 100 | |
Sean Barag | de9ed3e | 2020-10-01 03:46:16 +0000 | [diff] [blame] | 101 | test_expect_success 'prefers config "clone.defaultRemoteName" over default' ' |
| 102 | |
| 103 | test_config_global clone.defaultRemoteName from_config && |
| 104 | git clone parent clone-config-origin && |
Johannes Schindelin | 95cf2c0 | 2020-11-18 23:44:35 +0000 | [diff] [blame] | 105 | git -C clone-config-origin rev-parse --verify refs/remotes/from_config/main |
Sean Barag | de9ed3e | 2020-10-01 03:46:16 +0000 | [diff] [blame] | 106 | |
| 107 | ' |
| 108 | |
| 109 | test_expect_success 'prefers --origin over -c config' ' |
| 110 | |
| 111 | git clone -c clone.defaultRemoteName=inline --origin from_option parent clone-o-and-inline-config && |
Johannes Schindelin | 95cf2c0 | 2020-11-18 23:44:35 +0000 | [diff] [blame] | 112 | git -C clone-o-and-inline-config rev-parse --verify refs/remotes/from_option/main |
Sean Barag | de9ed3e | 2020-10-01 03:46:16 +0000 | [diff] [blame] | 113 | |
| 114 | ' |
| 115 | |
Jeff King | 68b939b | 2013-09-18 16:05:13 -0400 | [diff] [blame] | 116 | test_expect_success 'redirected clone does not show progress' ' |
Miklos Vajna | 21188b1 | 2008-10-09 01:40:32 +0200 | [diff] [blame] | 117 | |
| 118 | git clone "file://$(pwd)/parent" clone-redirected >out 2>err && |
Jeff King | 2856cbf | 2013-09-18 16:06:50 -0400 | [diff] [blame] | 119 | ! grep % err && |
| 120 | test_i18ngrep ! "Checking connectivity" err |
Miklos Vajna | 21188b1 | 2008-10-09 01:40:32 +0200 | [diff] [blame] | 121 | |
| 122 | ' |
Jeff King | 68b939b | 2013-09-18 16:05:13 -0400 | [diff] [blame] | 123 | |
| 124 | test_expect_success 'redirected clone -v does show progress' ' |
Miklos Vajna | 21188b1 | 2008-10-09 01:40:32 +0200 | [diff] [blame] | 125 | |
Tay Ray Chuan | 5a518ad | 2009-12-26 01:12:06 +0800 | [diff] [blame] | 126 | git clone --progress "file://$(pwd)/parent" clone-redirected-progress \ |
| 127 | >out 2>err && |
Jeff King | 68b939b | 2013-09-18 16:05:13 -0400 | [diff] [blame] | 128 | grep % err |
Miklos Vajna | 21188b1 | 2008-10-09 01:40:32 +0200 | [diff] [blame] | 129 | |
| 130 | ' |
| 131 | |
brian m. carlson | 7555567 | 2021-03-10 01:11:20 +0000 | [diff] [blame] | 132 | test_expect_success 'clone does not segfault with --bare and core.bare=false' ' |
| 133 | test_config_global core.bare false && |
| 134 | git clone --bare parent clone-bare && |
| 135 | echo true >expect && |
| 136 | git -C clone-bare rev-parse --is-bare-repository >actual && |
| 137 | test_cmp expect actual |
| 138 | ' |
| 139 | |
Johannes Schindelin | 0cc1b47 | 2020-06-24 14:46:34 +0000 | [diff] [blame] | 140 | test_expect_success 'chooses correct default initial branch name' ' |
Jonathan Tan | 4f37d45 | 2021-02-05 12:48:49 -0800 | [diff] [blame] | 141 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \ |
| 142 | git -c init.defaultBranch=foo init --bare empty && |
| 143 | test_config -C empty lsrefs.unborn advertise && |
Johannes Schindelin | 704fed9 | 2020-10-23 14:00:00 +0000 | [diff] [blame] | 144 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \ |
Jonathan Tan | 5f70859 | 2021-03-17 08:42:00 -0700 | [diff] [blame] | 145 | git -c init.defaultBranch=up -c protocol.version=2 clone empty whats-up && |
Jonathan Tan | 4f37d45 | 2021-02-05 12:48:49 -0800 | [diff] [blame] | 146 | test refs/heads/foo = $(git -C whats-up symbolic-ref HEAD) && |
| 147 | test refs/heads/foo = $(git -C whats-up config branch.foo.merge) |
Johannes Schindelin | 0cc1b47 | 2020-06-24 14:46:34 +0000 | [diff] [blame] | 148 | ' |
| 149 | |
| 150 | test_expect_success 'guesses initial branch name correctly' ' |
| 151 | git init --initial-branch=guess initial-branch && |
| 152 | test_commit -C initial-branch no-spoilers && |
| 153 | git -C initial-branch branch abc guess && |
| 154 | git clone initial-branch is-it && |
Johannes Schindelin | a471214 | 2020-06-24 14:46:35 +0000 | [diff] [blame] | 155 | test refs/heads/guess = $(git -C is-it symbolic-ref HEAD) && |
| 156 | |
| 157 | git -c init.defaultBranch=none init --bare no-head && |
| 158 | git -C initial-branch push ../no-head guess abc && |
Johannes Schindelin | 704fed9 | 2020-10-23 14:00:00 +0000 | [diff] [blame] | 159 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \ |
Johannes Schindelin | a471214 | 2020-06-24 14:46:35 +0000 | [diff] [blame] | 160 | git clone no-head is-it2 && |
| 161 | test_must_fail git -C is-it2 symbolic-ref refs/remotes/origin/HEAD && |
| 162 | git -C no-head update-ref --no-deref HEAD refs/heads/guess && |
Johannes Schindelin | 704fed9 | 2020-10-23 14:00:00 +0000 | [diff] [blame] | 163 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \ |
Johannes Schindelin | a471214 | 2020-06-24 14:46:35 +0000 | [diff] [blame] | 164 | git -c init.defaultBranch=guess clone no-head is-it3 && |
| 165 | test refs/remotes/origin/guess = \ |
| 166 | $(git -C is-it3 symbolic-ref refs/remotes/origin/HEAD) |
Johannes Schindelin | 0cc1b47 | 2020-06-24 14:46:34 +0000 | [diff] [blame] | 167 | ' |
| 168 | |
Jeff King | ecaa0cf | 2007-12-19 10:43:50 -0500 | [diff] [blame] | 169 | test_done |