t / t1500-rev-parse.shon commit t6044: replace seq by test_seq (3f215b0)
   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        test_expect_success "$name: git-dir" \
  31        "test '$1' = \"\$(git rev-parse --git-dir)\""
  32        shift
  33        [ $# -eq 0 ] && return
  34}
  35
  36# label is-bare is-inside-git is-inside-work prefix git-dir
  37
  38ROOT=$(pwd)
  39
  40test_rev_parse toplevel false false true '' .git
  41
  42cd .git || exit 1
  43test_rev_parse .git/ false true false '' .
  44cd objects || exit 1
  45test_rev_parse .git/objects/ false true false '' "$ROOT/.git"
  46cd ../.. || exit 1
  47
  48mkdir -p sub/dir || exit 1
  49cd sub/dir || exit 1
  50test_rev_parse subdirectory false false true sub/dir/ "$ROOT/.git"
  51cd ../.. || exit 1
  52
  53git config core.bare true
  54test_rev_parse 'core.bare = true' true false false
  55
  56git config --unset core.bare
  57test_rev_parse 'core.bare undefined' false false true
  58
  59mkdir work || exit 1
  60cd work || exit 1
  61GIT_DIR=../.git
  62GIT_CONFIG="$(pwd)"/../.git/config
  63export GIT_DIR GIT_CONFIG
  64
  65git config core.bare false
  66test_rev_parse 'GIT_DIR=../.git, core.bare = false' false false true ''
  67
  68git config core.bare true
  69test_rev_parse 'GIT_DIR=../.git, core.bare = true' true false false ''
  70
  71git config --unset core.bare
  72test_rev_parse 'GIT_DIR=../.git, core.bare undefined' false false true ''
  73
  74mv ../.git ../repo.git || exit 1
  75GIT_DIR=../repo.git
  76GIT_CONFIG="$(pwd)"/../repo.git/config
  77
  78git config core.bare false
  79test_rev_parse 'GIT_DIR=../repo.git, core.bare = false' false false true ''
  80
  81git config core.bare true
  82test_rev_parse 'GIT_DIR=../repo.git, core.bare = true' true false false ''
  83
  84git config --unset core.bare
  85test_rev_parse 'GIT_DIR=../repo.git, core.bare undefined' false false true ''
  86
  87test_done