1#!/bin/sh
2
3test_description='clone --branch option'
4. ./test-lib.sh
5
6check_HEAD() {
7 echo refs/heads/"$1" >expect &&
8 git symbolic-ref HEAD >actual &&
9 test_cmp expect actual
10}
11
12check_file() {
13 echo "$1" >expect &&
14 test_cmp expect file
15}
16
17test_expect_success 'setup' '
18 mkdir parent &&
19 (cd parent && git init &&
20 echo one >file && git add file && git commit -m one &&
21 git checkout -b two &&
22 echo two >file && git add file && git commit -m two &&
23 git checkout master) &&
24 mkdir empty &&
25 (cd empty && git init)
26'
27
28test_expect_success 'vanilla clone chooses HEAD' '
29 git clone parent clone &&
30 (cd clone &&
31 check_HEAD master &&
32 check_file one
33 )
34'
35
36test_expect_success 'clone -b chooses specified branch' '
37 git clone -b two parent clone-two &&
38 (cd clone-two &&
39 check_HEAD two &&
40 check_file two
41 )
42'
43
44test_expect_success 'clone -b sets up tracking' '
45 (cd clone-two &&
46 echo origin >expect &&
47 git config branch.two.remote >actual &&
48 echo refs/heads/two >>expect &&
49 git config branch.two.merge >>actual &&
50 test_cmp expect actual
51 )
52'
53
54test_expect_success 'clone -b does not munge remotes/origin/HEAD' '
55 (cd clone-two &&
56 echo refs/remotes/origin/master >expect &&
57 git symbolic-ref refs/remotes/origin/HEAD >actual &&
58 test_cmp expect actual
59 )
60'
61
62test_expect_success 'clone -b with bogus branch' '
63 test_must_fail git clone -b bogus parent clone-bogus
64'
65
66test_expect_success 'clone -b not allowed with empty repos' '
67 test_must_fail git clone -b branch empty clone-branch-empty
68'
69
70test_done