t / t1500-rev-parse.shon commit t9600: require cvsps 2.1 to perform tests (dcbcb70)
   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
  31# label is-bare is-inside-git is-inside-work prefix
  32
  33test_rev_parse toplevel false false true ''
  34
  35cd .git || exit 1
  36test_rev_parse .git/ true true false ''
  37cd objects || exit 1
  38test_rev_parse .git/objects/ true true false ''
  39cd ../.. || exit 1
  40
  41mkdir -p sub/dir || exit 1
  42cd sub/dir || exit 1
  43test_rev_parse subdirectory false false true sub/dir/
  44cd ../.. || exit 1
  45
  46git config core.bare true
  47test_rev_parse 'core.bare = true' true false false
  48
  49git config --unset core.bare
  50test_rev_parse 'core.bare undefined' false false true
  51
  52mkdir work || exit 1
  53cd work || exit 1
  54export GIT_DIR=../.git
  55export GIT_CONFIG="$(pwd)"/../.git/config
  56
  57git config core.bare false
  58test_rev_parse 'GIT_DIR=../.git, core.bare = false' false false true ''
  59
  60git config core.bare true
  61test_rev_parse 'GIT_DIR=../.git, core.bare = true' true false false ''
  62
  63git config --unset core.bare
  64test_rev_parse 'GIT_DIR=../.git, core.bare undefined' false false true ''
  65
  66mv ../.git ../repo.git || exit 1
  67export GIT_DIR=../repo.git
  68export GIT_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