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