]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5609-clone-branch.sh
Merge branch 'js/range-diff-wo-dotdot'
[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
7a4ee28f
JK
7. ./test-lib.sh
8
9check_HEAD() {
10 echo refs/heads/"$1" >expect &&
11 git symbolic-ref HEAD >actual &&
12 test_cmp expect actual
13}
14
15check_file() {
16 echo "$1" >expect &&
17 test_cmp expect file
18}
19
20test_expect_success 'setup' '
21 mkdir parent &&
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 &&
95cf2c01 26 git checkout main) &&
a3552aba
RT
27 mkdir empty &&
28 (cd empty && git init)
7a4ee28f
JK
29'
30
31test_expect_success 'vanilla clone chooses HEAD' '
32 git clone parent clone &&
33 (cd clone &&
95cf2c01 34 check_HEAD main &&
7a4ee28f
JK
35 check_file one
36 )
37'
38
39test_expect_success 'clone -b chooses specified branch' '
40 git clone -b two parent clone-two &&
41 (cd clone-two &&
42 check_HEAD two &&
43 check_file two
44 )
45'
46
47test_expect_success 'clone -b sets up tracking' '
48 (cd clone-two &&
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
54 )
55'
56
57test_expect_success 'clone -b does not munge remotes/origin/HEAD' '
58 (cd clone-two &&
95cf2c01 59 echo refs/remotes/origin/main >expect &&
7a4ee28f
JK
60 git symbolic-ref refs/remotes/origin/HEAD >actual &&
61 test_cmp expect actual
62 )
63'
64
920b691f
NTND
65test_expect_success 'clone -b with bogus branch' '
66 test_must_fail git clone -b bogus parent clone-bogus
7a4ee28f
JK
67'
68
a3552aba
RT
69test_expect_success 'clone -b not allowed with empty repos' '
70 test_must_fail git clone -b branch empty clone-branch-empty
71'
72
7a4ee28f 73test_done