#!/bin/sh global test_description := ''clone --branch option'' source ./test-lib.sh proc check_HEAD { echo refs/heads/"$1" >expect && git symbolic-ref HEAD >actual && test_cmp expect actual } proc check_file { echo $1 >expect && test_cmp expect file } test_expect_success 'setup' ' mkdir parent && (cd parent && git init && echo one >file && git add file && git commit -m one && git checkout -b two && echo two >file && git add file && git commit -m two && git checkout master) && mkdir empty && (cd empty && git init) ' test_expect_success 'vanilla clone chooses HEAD' ' git clone parent clone && (cd clone && check_HEAD master && check_file one ) ' test_expect_success 'clone -b chooses specified branch' ' git clone -b two parent clone-two && (cd clone-two && check_HEAD two && check_file two ) ' test_expect_success 'clone -b sets up tracking' ' (cd clone-two && echo origin >expect && git config branch.two.remote >actual && echo refs/heads/two >>expect && git config branch.two.merge >>actual && test_cmp expect actual ) ' test_expect_success 'clone -b does not munge remotes/origin/HEAD' ' (cd clone-two && echo refs/remotes/origin/master >expect && git symbolic-ref refs/remotes/origin/HEAD >actual && test_cmp expect actual ) ' test_expect_success 'clone -b with bogus branch' ' test_must_fail git clone -b bogus parent clone-bogus ' test_expect_success 'clone -b not allowed with empty repos' ' test_must_fail git clone -b branch empty clone-branch-empty ' test_done (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:test_description) op: Equal rhs: {(SQ <"clone --branch option">)} spids: [4] ) ] spids: [4] ) (C {(.)} {(./test-lib.sh)}) (FuncDef name: check_HEAD body: (BraceGroup children: [ (AndOr children: [ (SimpleCommand words: [{(echo)} {(refs/heads/) (DQ ($ VSub_Number "$1"))}] redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(expect)} spids:[28])] ) (AndOr children: [ (SimpleCommand words: [{(git)} {(symbolic-ref)} {(HEAD)}] redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(actual)} spids:[40])] ) (C {(test_cmp)} {(expect)} {(actual)}) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] spids: [18] ) spids: [14 17] ) (FuncDef name: check_file body: (BraceGroup children: [ (AndOr children: [ (SimpleCommand words: [{(echo)} {(DQ ($ VSub_Number "$1"))}] redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(expect)} spids:[68])] ) (C {(test_cmp)} {(expect)} {(file)}) ] op_id: Op_DAmp ) ] spids: [59] ) spids: [55 58] ) (C {(test_expect_success)} {(SQ )} { (SQ <"\n"> <"\tmkdir parent &&\n"> <"\t(cd parent && git init &&\n"> <"\t echo one >file && git add file && git commit -m one &&\n"> <"\t git checkout -b two &&\n"> <"\t echo two >file && git add file && git commit -m two &&\n"> <"\t git checkout master) &&\n"> <"\tmkdir empty &&\n"> <"\t(cd empty && git init)\n"> ) } ) (C {(test_expect_success)} {(SQ <"vanilla clone chooses HEAD">)} { (SQ <"\n"> <"\tgit clone parent clone &&\n"> <"\t(cd clone &&\n"> <"\t check_HEAD master &&\n"> <"\t check_file one\n"> <"\t)\n"> ) } ) (C {(test_expect_success)} {(SQ <"clone -b chooses specified branch">)} { (SQ <"\n"> <"\tgit clone -b two parent clone-two &&\n"> <"\t(cd clone-two &&\n"> <"\t check_HEAD two &&\n"> <"\t check_file two\n"> <"\t)\n"> ) } ) (C {(test_expect_success)} {(SQ <"clone -b sets up tracking">)} { (SQ <"\n"> <"\t(cd clone-two &&\n"> <"\t echo origin >expect &&\n"> <"\t git config branch.two.remote >actual &&\n"> <"\t echo refs/heads/two >>expect &&\n"> <"\t git config branch.two.merge >>actual &&\n"> <"\t test_cmp expect actual\n"> <"\t)\n"> ) } ) (C {(test_expect_success)} {(SQ <"clone -b does not munge remotes/origin/HEAD">)} { (SQ <"\n"> <"\t(cd clone-two &&\n"> <"\t echo refs/remotes/origin/master >expect &&\n"> <"\t git symbolic-ref refs/remotes/origin/HEAD >actual &&\n"> <"\t test_cmp expect actual\n"> <"\t)\n"> ) } ) (C {(test_expect_success)} {(SQ <"clone -b with bogus branch">)} {(SQ <"\n"> <"\ttest_must_fail git clone -b bogus parent clone-bogus\n">)} ) (C {(test_expect_success)} {(SQ <"clone -b not allowed with empty repos">)} {(SQ <"\n"> <"\ttest_must_fail git clone -b branch empty clone-branch-empty\n">)} ) (C {(test_done)}) ] )