ecc575ba1de0b791708ba9196bced52ca3b42f21
   1#!/bin/sh
   2
   3test_description='test git rev-parse'
   4. ./test-lib.sh
   5
   6# usage: label is-bare is-inside-git is-inside-work prefix git-dir
   7test_rev_parse () {
   8        name=$1
   9        shift
  10
  11        for o in --is-bare-repository \
  12                 --is-inside-git-dir \
  13                 --is-inside-work-tree \
  14                 --show-prefix \
  15                 --git-dir
  16        do
  17                test $# -eq 0 && break
  18                expect="$1"
  19                test_expect_success "$name: $o" '
  20                        echo "$expect" >expect &&
  21                        git rev-parse $o >actual &&
  22                        test_cmp expect actual
  23                '
  24                shift
  25        done
  26}
  27
  28ROOT=$(pwd)
  29
  30test_expect_success 'setup' '
  31        mkdir -p sub/dir work &&
  32        cp -R .git repo.git
  33'
  34
  35test_rev_parse toplevel false false true '' .git
  36
  37cd .git || exit 1
  38test_rev_parse .git/ false true false '' .
  39cd objects || exit 1
  40test_rev_parse .git/objects/ false true false '' "$ROOT/.git"
  41cd ../.. || exit 1
  42
  43cd sub/dir || exit 1
  44test_rev_parse subdirectory false false true sub/dir/ "$ROOT/.git"
  45cd ../.. || exit 1
  46
  47git config core.bare true
  48test_rev_parse 'core.bare = true' true false false
  49
  50git config --unset core.bare
  51test_rev_parse 'core.bare undefined' false false true
  52
  53cd work || exit 1
  54GIT_DIR=../.git
  55GIT_CONFIG="$(pwd)"/../.git/config
  56export GIT_DIR GIT_CONFIG
  57
  58git config core.bare false
  59test_rev_parse 'GIT_DIR=../.git, core.bare = false' false false true ''
  60
  61git config core.bare true
  62test_rev_parse 'GIT_DIR=../.git, core.bare = true' true false false ''
  63
  64git config --unset core.bare
  65test_rev_parse 'GIT_DIR=../.git, core.bare undefined' false false true ''
  66
  67GIT_DIR=../repo.git
  68GIT_CONFIG="$(pwd)"/../repo.git/config
  69
  70git config core.bare false
  71test_rev_parse 'GIT_DIR=../repo.git, core.bare = false' false false true ''
  72
  73git config core.bare true
  74test_rev_parse 'GIT_DIR=../repo.git, core.bare = true' true false false ''
  75
  76git config --unset core.bare
  77test_rev_parse 'GIT_DIR=../repo.git, core.bare undefined' false false true ''
  78
  79test_done