t / t1500-rev-parse.shon commit t1500: avoid changing working directory outside of tests (1e043cf)
   1#!/bin/sh
   2
   3test_description='test git rev-parse'
   4. ./test-lib.sh
   5
   6# usage: [options] label is-bare is-inside-git is-inside-work prefix git-dir
   7test_rev_parse () {
   8        d=
   9        while :
  10        do
  11                case "$1" in
  12                -C) d="$2"; shift; shift ;;
  13                -*) error "test_rev_parse: unrecognized option '$1'" ;;
  14                *) break ;;
  15                esac
  16        done
  17
  18        name=$1
  19        shift
  20
  21        for o in --is-bare-repository \
  22                 --is-inside-git-dir \
  23                 --is-inside-work-tree \
  24                 --show-prefix \
  25                 --git-dir
  26        do
  27                test $# -eq 0 && break
  28                expect="$1"
  29                test_expect_success "$name: $o" '
  30                        echo "$expect" >expect &&
  31                        git ${d:+-C} ${d:+"$d"} rev-parse $o >actual &&
  32                        test_cmp expect actual
  33                '
  34                shift
  35        done
  36}
  37
  38ROOT=$(pwd)
  39
  40test_expect_success 'setup' '
  41        mkdir -p sub/dir work &&
  42        cp -R .git repo.git
  43'
  44
  45test_rev_parse toplevel false false true '' .git
  46
  47test_rev_parse -C .git .git/ false true false '' .
  48test_rev_parse -C .git/objects .git/objects/ false true false '' "$ROOT/.git"
  49
  50test_rev_parse -C sub/dir subdirectory false false true sub/dir/ "$ROOT/.git"
  51
  52git config core.bare true
  53test_rev_parse 'core.bare = true' true false false
  54
  55git config --unset core.bare
  56test_rev_parse 'core.bare undefined' false false true
  57
  58GIT_DIR=../.git
  59GIT_CONFIG="$(pwd)/work/../.git/config"
  60export GIT_DIR GIT_CONFIG
  61
  62git config core.bare false
  63test_rev_parse -C work 'GIT_DIR=../.git, core.bare = false' false false true ''
  64
  65git config core.bare true
  66test_rev_parse -C work 'GIT_DIR=../.git, core.bare = true' true false false ''
  67
  68git config --unset core.bare
  69test_rev_parse -C work 'GIT_DIR=../.git, core.bare undefined' false false true ''
  70
  71GIT_DIR=../repo.git
  72GIT_CONFIG="$(pwd)/work/../repo.git/config"
  73
  74git config core.bare false
  75test_rev_parse -C work 'GIT_DIR=../repo.git, core.bare = false' false false true ''
  76
  77git config core.bare true
  78test_rev_parse -C work 'GIT_DIR=../repo.git, core.bare = true' true false false ''
  79
  80git config --unset core.bare
  81test_rev_parse -C work 'GIT_DIR=../repo.git, core.bare undefined' false false true ''
  82
  83test_done