]>
Commit | Line | Data |
---|---|---|
7a4ee28f JK |
1 | #!/bin/sh |
2 | ||
3 | test_description='clone --branch option' | |
95cf2c01 | 4 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
5 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
6 | ||
9081a421 | 7 | TEST_PASSES_SANITIZE_LEAK=true |
7a4ee28f JK |
8 | . ./test-lib.sh |
9 | ||
10 | check_HEAD() { | |
11 | echo refs/heads/"$1" >expect && | |
12 | git symbolic-ref HEAD >actual && | |
13 | test_cmp expect actual | |
14 | } | |
15 | ||
16 | check_file() { | |
17 | echo "$1" >expect && | |
18 | test_cmp expect file | |
19 | } | |
20 | ||
21 | test_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 | ||
32 | test_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 | ||
40 | test_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 | ||
48 | test_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 | ||
58 | test_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 |
66 | test_expect_success 'clone -b with bogus branch' ' |
67 | test_must_fail git clone -b bogus parent clone-bogus | |
7a4ee28f JK |
68 | ' |
69 | ||
a3552aba RT |
70 | test_expect_success 'clone -b not allowed with empty repos' ' |
71 | test_must_fail git clone -b branch empty clone-branch-empty | |
72 | ' | |
73 | ||
7a4ee28f | 74 | test_done |