t / t5611-clone-config.shon commit t3306: abstract away SHA-1-specific constants (b99bfc7)
   1#!/bin/sh
   2
   3test_description='tests for git clone -c key=value'
   4. ./test-lib.sh
   5
   6test_expect_success 'clone -c sets config in cloned repo' '
   7        rm -rf child &&
   8        git clone -c core.foo=bar . child &&
   9        echo bar >expect &&
  10        git --git-dir=child/.git config core.foo >actual &&
  11        test_cmp expect actual
  12'
  13
  14test_expect_success 'clone -c can set multi-keys' '
  15        rm -rf child &&
  16        git clone -c core.foo=bar -c core.foo=baz . child &&
  17        { echo bar; echo baz; } >expect &&
  18        git --git-dir=child/.git config --get-all core.foo >actual &&
  19        test_cmp expect actual
  20'
  21
  22test_expect_success 'clone -c can set multi-keys, including some empty' '
  23        rm -rf child &&
  24        git clone -c credential.helper= -c credential.helper=hi . child &&
  25        printf "%s\n" "" hi >expect &&
  26        git --git-dir=child/.git config --get-all credential.helper >actual &&
  27        test_cmp expect actual
  28'
  29
  30test_expect_success 'clone -c without a value is boolean true' '
  31        rm -rf child &&
  32        git clone -c core.foo . child &&
  33        echo true >expect &&
  34        git --git-dir=child/.git config --bool core.foo >actual &&
  35        test_cmp expect actual
  36'
  37
  38test_expect_success 'clone -c config is available during clone' '
  39        echo content >file &&
  40        git add file &&
  41        git commit -m one &&
  42        rm -rf child &&
  43        git clone -c core.autocrlf . child &&
  44        printf "content\\r\\n" >expect &&
  45        test_cmp expect child/file
  46'
  47
  48test_expect_success 'clone -c remote.origin.fetch=<refspec> works' '
  49        rm -rf child &&
  50        git update-ref refs/grab/it refs/heads/master &&
  51        git update-ref refs/leave/out refs/heads/master &&
  52        git clone -c "remote.origin.fetch=+refs/grab/*:refs/grab/*" . child &&
  53        git -C child for-each-ref --format="%(refname)" >actual &&
  54
  55        cat >expect <<-\EOF &&
  56        refs/grab/it
  57        refs/heads/master
  58        refs/remotes/origin/HEAD
  59        refs/remotes/origin/master
  60        EOF
  61        test_cmp expect actual
  62'
  63
  64test_expect_success 'git -c remote.origin.fetch=<refspec> clone works' '
  65        rm -rf child &&
  66        git -c "remote.origin.fetch=+refs/grab/*:refs/grab/*" clone . child &&
  67        git -C child for-each-ref --format="%(refname)" >actual &&
  68
  69        cat >expect <<-\EOF &&
  70        refs/grab/it
  71        refs/heads/master
  72        refs/remotes/origin/HEAD
  73        refs/remotes/origin/master
  74        EOF
  75        test_cmp expect actual
  76'
  77
  78test_expect_success 'clone -c remote.<remote>.fetch=<refspec> --origin=<name>' '
  79        rm -rf child &&
  80        git clone --origin=upstream \
  81                  -c "remote.upstream.fetch=+refs/grab/*:refs/grab/*" \
  82                  -c "remote.origin.fetch=+refs/leave/*:refs/leave/*" \
  83                  . child &&
  84        git -C child for-each-ref --format="%(refname)" >actual &&
  85
  86        cat >expect <<-\EOF &&
  87        refs/grab/it
  88        refs/heads/master
  89        refs/remotes/upstream/HEAD
  90        refs/remotes/upstream/master
  91        EOF
  92        test_cmp expect actual
  93'
  94
  95# Tests for the hidden file attribute on windows
  96is_hidden () {
  97        # Use the output of `attrib`, ignore the absolute path
  98        case "$(attrib "$1")" in *H*?:*) return 0;; esac
  99        return 1
 100}
 101
 102test_expect_success MINGW 'clone -c core.hideDotFiles' '
 103        test_commit attributes .gitattributes "" &&
 104        rm -rf child &&
 105        git clone -c core.hideDotFiles=false . child &&
 106        ! is_hidden child/.gitattributes &&
 107        rm -rf child &&
 108        git clone -c core.hideDotFiles=dotGitOnly . child &&
 109        ! is_hidden child/.gitattributes &&
 110        rm -rf child &&
 111        git clone -c core.hideDotFiles=true . child &&
 112        is_hidden child/.gitattributes
 113'
 114
 115test_done