]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5609-clone-branch.sh
Start the 2.46 cycle
[thirdparty/git.git] / t / t5609-clone-branch.sh
CommitLineData
7a4ee28f
JK
1#!/bin/sh
2
3test_description='clone --branch option'
95cf2c01 4GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
5export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
6
9081a421 7TEST_PASSES_SANITIZE_LEAK=true
7a4ee28f
JK
8. ./test-lib.sh
9
10check_HEAD() {
11 echo refs/heads/"$1" >expect &&
12 git symbolic-ref HEAD >actual &&
13 test_cmp expect actual
14}
15
16check_file() {
17 echo "$1" >expect &&
18 test_cmp expect file
19}
20
21test_expect_success 'setup' '
22 mkdir parent &&
23 (cd parent && git init &&
24 echo one >file && git add file && git commit -m one &&
25 git checkout -b two &&
26 echo two >file && git add file && git commit -m two &&
95cf2c01 27 git checkout main) &&
a3552aba
RT
28 mkdir empty &&
29 (cd empty && git init)
7a4ee28f
JK
30'
31
32test_expect_success 'vanilla clone chooses HEAD' '
33 git clone parent clone &&
34 (cd clone &&
95cf2c01 35 check_HEAD main &&
7a4ee28f
JK
36 check_file one
37 )
38'
39
40test_expect_success 'clone -b chooses specified branch' '
41 git clone -b two parent clone-two &&
42 (cd clone-two &&
43 check_HEAD two &&
44 check_file two
45 )
46'
47
48test_expect_success 'clone -b sets up tracking' '
49 (cd clone-two &&
50 echo origin >expect &&
51 git config branch.two.remote >actual &&
52 echo refs/heads/two >>expect &&
53 git config branch.two.merge >>actual &&
54 test_cmp expect actual
55 )
56'
57
58test_expect_success 'clone -b does not munge remotes/origin/HEAD' '
59 (cd clone-two &&
95cf2c01 60 echo refs/remotes/origin/main >expect &&
7a4ee28f
JK
61 git symbolic-ref refs/remotes/origin/HEAD >actual &&
62 test_cmp expect actual
63 )
64'
65
920b691f
NTND
66test_expect_success 'clone -b with bogus branch' '
67 test_must_fail git clone -b bogus parent clone-bogus
7a4ee28f
JK
68'
69
a3552aba
RT
70test_expect_success 'clone -b not allowed with empty repos' '
71 test_must_fail git clone -b branch empty clone-branch-empty
72'
73
7a4ee28f 74test_done