]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5606-clone-options.sh
Merge branch 'es/maintenance-of-bare-repositories'
[thirdparty/git.git] / t / t5606-clone-options.sh
CommitLineData
ecaa0cff
JK
1#!/bin/sh
2
3test_description='basic clone options'
95cf2c01 4GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
5export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
6
ecaa0cff
JK
7. ./test-lib.sh
8
9test_expect_success 'setup' '
10
11 mkdir parent &&
12 (cd parent && git init &&
13 echo one >file && git add file &&
14 git commit -m one)
15
16'
17
18test_expect_success 'clone -o' '
19
20 git clone -o foo parent clone-o &&
95cf2c01 21 git -C clone-o rev-parse --verify refs/remotes/foo/main
349cff76
SB
22
23'
24
de9ed3ef
SB
25test_expect_success 'rejects invalid -o/--origin' '
26
27 test_must_fail git clone -o "bad...name" parent clone-bad-name 2>err &&
28 test_i18ngrep "'\''bad...name'\'' is not a valid remote name" err
29
30'
31
349cff76
SB
32test_expect_success 'disallows --bare with --origin' '
33
34 test_must_fail git clone -o foo --bare parent clone-bare-o 2>err &&
35 test_debug "cat err" &&
36 test_i18ngrep -e "--bare and --origin foo options are incompatible" err
37
38'
39
40test_expect_success 'disallows --bare with --separate-git-dir' '
41
42 test_must_fail git clone --bare --separate-git-dir dot-git-destiation parent clone-bare-sgd 2>err &&
43 test_debug "cat err" &&
44 test_i18ngrep -e "--bare and --separate-git-dir are incompatible" err
45
46'
47
48test_expect_success 'uses "origin" for default remote name' '
49
50 git clone parent clone-default-origin &&
95cf2c01 51 git -C clone-default-origin rev-parse --verify refs/remotes/origin/main
349cff76
SB
52
53'
54
55test_expect_success 'prefers --template config over normal config' '
56
57 template="$TRASH_DIRECTORY/template-with-config" &&
58 mkdir "$template" &&
59 git config --file "$template/config" foo.bar from_template &&
60 test_config_global foo.bar from_global &&
61 git clone "--template=$template" parent clone-template-config &&
62 test "$(git -C clone-template-config config --local foo.bar)" = "from_template"
63
64'
65
66test_expect_success 'prefers -c config over --template config' '
67
68 template="$TRASH_DIRECTORY/template-with-ignored-config" &&
69 mkdir "$template" &&
70 git config --file "$template/config" foo.bar from_template &&
71 git clone "--template=$template" -c foo.bar=inline parent clone-template-inline-config &&
72 test "$(git -C clone-template-inline-config config --local foo.bar)" = "inline"
ecaa0cff
JK
73
74'
75
de9ed3ef
SB
76test_expect_success 'prefers config "clone.defaultRemoteName" over default' '
77
78 test_config_global clone.defaultRemoteName from_config &&
79 git clone parent clone-config-origin &&
95cf2c01 80 git -C clone-config-origin rev-parse --verify refs/remotes/from_config/main
de9ed3ef
SB
81
82'
83
84test_expect_success 'prefers --origin over -c config' '
85
86 git clone -c clone.defaultRemoteName=inline --origin from_option parent clone-o-and-inline-config &&
95cf2c01 87 git -C clone-o-and-inline-config rev-parse --verify refs/remotes/from_option/main
de9ed3ef
SB
88
89'
90
68b939b2 91test_expect_success 'redirected clone does not show progress' '
21188b1e
MV
92
93 git clone "file://$(pwd)/parent" clone-redirected >out 2>err &&
2856cbf0
JK
94 ! grep % err &&
95 test_i18ngrep ! "Checking connectivity" err
21188b1e
MV
96
97'
68b939b2
JK
98
99test_expect_success 'redirected clone -v does show progress' '
21188b1e 100
5a518ad4
TRC
101 git clone --progress "file://$(pwd)/parent" clone-redirected-progress \
102 >out 2>err &&
68b939b2 103 grep % err
21188b1e
MV
104
105'
106
0cc1b475 107test_expect_success 'chooses correct default initial branch name' '
4f37d457
JT
108 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \
109 git -c init.defaultBranch=foo init --bare empty &&
110 test_config -C empty lsrefs.unborn advertise &&
704fed9e 111 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \
0cc1b475 112 git -c init.defaultBranch=up clone empty whats-up &&
4f37d457
JT
113 test refs/heads/foo = $(git -C whats-up symbolic-ref HEAD) &&
114 test refs/heads/foo = $(git -C whats-up config branch.foo.merge)
0cc1b475
JS
115'
116
117test_expect_success 'guesses initial branch name correctly' '
118 git init --initial-branch=guess initial-branch &&
119 test_commit -C initial-branch no-spoilers &&
120 git -C initial-branch branch abc guess &&
121 git clone initial-branch is-it &&
a471214b
JS
122 test refs/heads/guess = $(git -C is-it symbolic-ref HEAD) &&
123
124 git -c init.defaultBranch=none init --bare no-head &&
125 git -C initial-branch push ../no-head guess abc &&
704fed9e 126 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \
a471214b
JS
127 git clone no-head is-it2 &&
128 test_must_fail git -C is-it2 symbolic-ref refs/remotes/origin/HEAD &&
129 git -C no-head update-ref --no-deref HEAD refs/heads/guess &&
704fed9e 130 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \
a471214b
JS
131 git -c init.defaultBranch=guess clone no-head is-it3 &&
132 test refs/remotes/origin/guess = \
133 $(git -C is-it3 symbolic-ref refs/remotes/origin/HEAD)
0cc1b475
JS
134'
135
ecaa0cff 136test_done