3 test_description='clone --branch option'
4 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
5 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10 echo refs/heads/"$1" >expect &&
11 git symbolic-ref HEAD >actual &&
12 test_cmp expect actual
20 test_expect_success 'setup' '
22 (cd parent && git init &&
23 echo one >file && git add file && git commit -m one &&
24 git checkout -b two &&
25 echo two >file && git add file && git commit -m two &&
28 (cd empty && git init)
31 test_expect_success 'vanilla clone chooses HEAD' '
32 git clone parent clone &&
39 test_expect_success 'clone -b chooses specified branch' '
40 git clone -b two parent clone-two &&
47 test_expect_success 'clone -b sets up tracking' '
49 echo origin >expect &&
50 git config branch.two.remote >actual &&
51 echo refs/heads/two >>expect &&
52 git config branch.two.merge >>actual &&
53 test_cmp expect actual
57 test_expect_success 'clone -b does not munge remotes/origin/HEAD' '
59 echo refs/remotes/origin/main >expect &&
60 git symbolic-ref refs/remotes/origin/HEAD >actual &&
61 test_cmp expect actual
65 test_expect_success 'clone -b with bogus branch' '
66 test_must_fail git clone -b bogus parent clone-bogus
69 test_expect_success 'clone -b not allowed with empty repos' '
70 test_must_fail git clone -b branch empty clone-branch-empty