t / t1500-rev-parse.shon commit Merge branch 'pb/gitweb-tagcloud' into pb/gitweb (3e3d4ee)
   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/ false true false ''
  37cd objects || exit 1
  38test_rev_parse .git/objects/ false 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
  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
  67mv ../.git ../repo.git || exit 1
  68GIT_DIR=../repo.git
  69GIT_CONFIG="$(pwd)"/../repo.git/config
  70
  71git config core.bare false
  72test_rev_parse 'GIT_DIR=../repo.git, core.bare = false' false false true ''
  73
  74git config core.bare true
  75test_rev_parse 'GIT_DIR=../repo.git, core.bare = true' true false false ''
  76
  77git config --unset core.bare
  78test_rev_parse 'GIT_DIR=../repo.git, core.bare undefined' false false true ''
  79
  80test_done