t / t1500-rev-parse.shon commit Merge branch 'jk/parseopt-usage-msg-opt' into maint (5bc5edb)
   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        bare=
  10        gitdir=
  11        while :
  12        do
  13                case "$1" in
  14                -C) d="$2"; shift; shift ;;
  15                -b) case "$2" in
  16                    [tfu]*) bare="$2"; shift; shift ;;
  17                    *) error "test_rev_parse: bogus core.bare value '$2'" ;;
  18                    esac ;;
  19                -g) gitdir="$2"; shift; shift ;;
  20                -*) error "test_rev_parse: unrecognized option '$1'" ;;
  21                *) break ;;
  22                esac
  23        done
  24
  25        name=$1
  26        shift
  27
  28        for o in --is-bare-repository \
  29                 --is-inside-git-dir \
  30                 --is-inside-work-tree \
  31                 --show-prefix \
  32                 --git-dir
  33        do
  34                test $# -eq 0 && break
  35                expect="$1"
  36                test_expect_success "$name: $o" '
  37                        if test -n "$gitdir"
  38                        then
  39                                test_when_finished "unset GIT_DIR" &&
  40                                GIT_DIR="$gitdir" &&
  41                                export GIT_DIR
  42                        fi &&
  43
  44                        case "$bare" in
  45                        t*) test_config ${d:+-C} ${d:+"$d"} core.bare true ;;
  46                        f*) test_config ${d:+-C} ${d:+"$d"} core.bare false ;;
  47                        u*) test_unconfig ${d:+-C} ${d:+"$d"} core.bare ;;
  48                        esac &&
  49
  50                        echo "$expect" >expect &&
  51                        git ${d:+-C} ${d:+"$d"} rev-parse $o >actual &&
  52                        test_cmp expect actual
  53                '
  54                shift
  55        done
  56}
  57
  58ROOT=$(pwd)
  59
  60test_expect_success 'setup' '
  61        mkdir -p sub/dir work &&
  62        cp -R .git repo.git
  63'
  64
  65test_rev_parse toplevel false false true '' .git
  66
  67test_rev_parse -C .git .git/ false true false '' .
  68test_rev_parse -C .git/objects .git/objects/ false true false '' "$ROOT/.git"
  69
  70test_rev_parse -C sub/dir subdirectory false false true sub/dir/ "$ROOT/.git"
  71
  72test_rev_parse -b t 'core.bare = true' true false false
  73
  74test_rev_parse -b u 'core.bare undefined' false false true
  75
  76
  77test_rev_parse -C work -g ../.git -b f 'GIT_DIR=../.git, core.bare = false' false false true ''
  78
  79test_rev_parse -C work -g ../.git -b t 'GIT_DIR=../.git, core.bare = true' true false false ''
  80
  81test_rev_parse -C work -g ../.git -b u 'GIT_DIR=../.git, core.bare undefined' false false true ''
  82
  83
  84test_rev_parse -C work -g ../repo.git -b f 'GIT_DIR=../repo.git, core.bare = false' false false true ''
  85
  86test_rev_parse -C work -g ../repo.git -b t 'GIT_DIR=../repo.git, core.bare = true' true false false ''
  87
  88test_rev_parse -C work -g ../repo.git -b u 'GIT_DIR=../repo.git, core.bare undefined' false false true ''
  89
  90test_done