t / t5706-clone-branch.shon commit Merge branch 'ph/rerere-doc' into maint-1.7.8 (dbdc07f)
   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'
  25
  26test_expect_success 'vanilla clone chooses HEAD' '
  27        git clone parent clone &&
  28        (cd clone &&
  29         check_HEAD master &&
  30         check_file one
  31        )
  32'
  33
  34test_expect_success 'clone -b chooses specified branch' '
  35        git clone -b two parent clone-two &&
  36        (cd clone-two &&
  37         check_HEAD two &&
  38         check_file two
  39        )
  40'
  41
  42test_expect_success 'clone -b sets up tracking' '
  43        (cd clone-two &&
  44         echo origin >expect &&
  45         git config branch.two.remote >actual &&
  46         echo refs/heads/two >>expect &&
  47         git config branch.two.merge >>actual &&
  48         test_cmp expect actual
  49        )
  50'
  51
  52test_expect_success 'clone -b does not munge remotes/origin/HEAD' '
  53        (cd clone-two &&
  54         echo refs/remotes/origin/master >expect &&
  55         git symbolic-ref refs/remotes/origin/HEAD >actual &&
  56         test_cmp expect actual
  57        )
  58'
  59
  60test_expect_success 'clone -b with bogus branch chooses HEAD' '
  61        git clone -b bogus parent clone-bogus &&
  62        (cd clone-bogus &&
  63         check_HEAD master &&
  64         check_file one
  65        )
  66'
  67
  68test_done