t / t1500-rev-parse.shon commit test GIT_WORK_TREE (3ae4a86)
   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: is-inside-work-tree" \
  21        "test '$1' = \"\$(git rev-parse --is-inside-work-tree)\""
  22        shift
  23        [ $# -eq 0 ] && return
  24
  25        test_expect_success "$name: prefix" \
  26        "test '$1' = \"\$(git rev-parse --show-prefix)\""
  27        shift
  28        [ $# -eq 0 ] && return
  29}
  30
  31test_rev_parse toplevel false false true ''
  32
  33cd .git || exit 1
  34test_rev_parse .git/ false true true .git/
  35cd objects || exit 1
  36test_rev_parse .git/objects/ false true true .git/objects/
  37cd ../.. || exit 1
  38
  39mkdir -p sub/dir || exit 1
  40cd sub/dir || exit 1
  41test_rev_parse subdirectory false false true sub/dir/
  42cd ../.. || exit 1
  43
  44git config core.bare true
  45test_rev_parse 'core.bare = true' true false true
  46
  47git config --unset core.bare
  48test_rev_parse 'core.bare undefined' false false true
  49
  50mkdir work || exit 1
  51cd work || exit 1
  52export GIT_DIR=../.git
  53export GIT_CONFIG="$GIT_DIR"/config
  54
  55git config core.bare false
  56test_rev_parse 'GIT_DIR=../.git, core.bare = false' false false true ''
  57
  58git config core.bare true
  59test_rev_parse 'GIT_DIR=../.git, core.bare = true' true false true ''
  60
  61git config --unset core.bare
  62test_rev_parse 'GIT_DIR=../.git, core.bare undefined' false false true ''
  63
  64mv ../.git ../repo.git || exit 1
  65export GIT_DIR=../repo.git
  66export GIT_CONFIG="$GIT_DIR"/config
  67
  68git config core.bare false
  69test_rev_parse 'GIT_DIR=../repo.git, core.bare = false' false false true ''
  70
  71git config core.bare true
  72test_rev_parse 'GIT_DIR=../repo.git, core.bare = true' true false true ''
  73
  74git config --unset core.bare
  75test_rev_parse 'GIT_DIR=../repo.git, core.bare undefined' true false true ''
  76
  77test_done