Matthias Lederhofer | dace6e4 | 2007-06-06 09:01:21 +0200 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='test git rev-parse' |
| 4 | . ./test-lib.sh |
| 5 | |
SZEDER Gábor | a2f5a87 | 2017-02-03 03:48:23 +0100 | [diff] [blame] | 6 | # usage: [options] label is-bare is-inside-git is-inside-work prefix git-dir absolute-git-dir |
Eric Sunshine | 12f7526 | 2016-05-18 16:15:42 -0400 | [diff] [blame] | 7 | test_rev_parse () { |
Eric Sunshine | 1e043cf | 2016-05-18 16:15:43 -0400 | [diff] [blame] | 8 | d= |
Eric Sunshine | 1dea0dc | 2016-05-18 16:15:44 -0400 | [diff] [blame] | 9 | bare= |
Eric Sunshine | e6273f4 | 2016-05-18 16:15:45 -0400 | [diff] [blame] | 10 | gitdir= |
Eric Sunshine | 1e043cf | 2016-05-18 16:15:43 -0400 | [diff] [blame] | 11 | while : |
| 12 | do |
| 13 | case "$1" in |
| 14 | -C) d="$2"; shift; shift ;; |
Eric Sunshine | 1dea0dc | 2016-05-18 16:15:44 -0400 | [diff] [blame] | 15 | -b) case "$2" in |
| 16 | [tfu]*) bare="$2"; shift; shift ;; |
| 17 | *) error "test_rev_parse: bogus core.bare value '$2'" ;; |
| 18 | esac ;; |
Eric Sunshine | e6273f4 | 2016-05-18 16:15:45 -0400 | [diff] [blame] | 19 | -g) gitdir="$2"; shift; shift ;; |
Eric Sunshine | 1e043cf | 2016-05-18 16:15:43 -0400 | [diff] [blame] | 20 | -*) error "test_rev_parse: unrecognized option '$1'" ;; |
| 21 | *) break ;; |
| 22 | esac |
| 23 | done |
| 24 | |
Matthias Lederhofer | dace6e4 | 2007-06-06 09:01:21 +0200 | [diff] [blame] | 25 | name=$1 |
| 26 | shift |
| 27 | |
Eric Sunshine | 12f7526 | 2016-05-18 16:15:42 -0400 | [diff] [blame] | 28 | for o in --is-bare-repository \ |
| 29 | --is-inside-git-dir \ |
| 30 | --is-inside-work-tree \ |
| 31 | --show-prefix \ |
SZEDER Gábor | a2f5a87 | 2017-02-03 03:48:23 +0100 | [diff] [blame] | 32 | --git-dir \ |
| 33 | --absolute-git-dir |
Eric Sunshine | 12f7526 | 2016-05-18 16:15:42 -0400 | [diff] [blame] | 34 | do |
| 35 | test $# -eq 0 && break |
| 36 | expect="$1" |
| 37 | test_expect_success "$name: $o" ' |
Eric Sunshine | e6273f4 | 2016-05-18 16:15:45 -0400 | [diff] [blame] | 38 | if test -n "$gitdir" |
| 39 | then |
| 40 | test_when_finished "unset GIT_DIR" && |
| 41 | GIT_DIR="$gitdir" && |
| 42 | export GIT_DIR |
| 43 | fi && |
| 44 | |
Eric Sunshine | 1dea0dc | 2016-05-18 16:15:44 -0400 | [diff] [blame] | 45 | case "$bare" in |
| 46 | t*) test_config ${d:+-C} ${d:+"$d"} core.bare true ;; |
| 47 | f*) test_config ${d:+-C} ${d:+"$d"} core.bare false ;; |
| 48 | u*) test_unconfig ${d:+-C} ${d:+"$d"} core.bare ;; |
| 49 | esac && |
| 50 | |
Eric Sunshine | 12f7526 | 2016-05-18 16:15:42 -0400 | [diff] [blame] | 51 | echo "$expect" >expect && |
Eric Sunshine | 1e043cf | 2016-05-18 16:15:43 -0400 | [diff] [blame] | 52 | git ${d:+-C} ${d:+"$d"} rev-parse $o >actual && |
Eric Sunshine | 12f7526 | 2016-05-18 16:15:42 -0400 | [diff] [blame] | 53 | test_cmp expect actual |
| 54 | ' |
| 55 | shift |
| 56 | done |
Matthias Lederhofer | dace6e4 | 2007-06-06 09:01:21 +0200 | [diff] [blame] | 57 | } |
| 58 | |
SZEDER Gábor | 8fb3c00 | 2009-02-14 17:16:28 +0100 | [diff] [blame] | 59 | ROOT=$(pwd) |
Johannes Schindelin | 7efeb8f | 2007-08-05 14:12:53 +0100 | [diff] [blame] | 60 | |
Eric Sunshine | d66f68f | 2016-05-17 15:36:26 -0400 | [diff] [blame] | 61 | test_expect_success 'setup' ' |
| 62 | mkdir -p sub/dir work && |
| 63 | cp -R .git repo.git |
| 64 | ' |
| 65 | |
SZEDER Gábor | a2f5a87 | 2017-02-03 03:48:23 +0100 | [diff] [blame] | 66 | test_rev_parse toplevel false false true '' .git "$ROOT/.git" |
Matthias Lederhofer | dace6e4 | 2007-06-06 09:01:21 +0200 | [diff] [blame] | 67 | |
SZEDER Gábor | a2f5a87 | 2017-02-03 03:48:23 +0100 | [diff] [blame] | 68 | test_rev_parse -C .git .git/ false true false '' . "$ROOT/.git" |
| 69 | test_rev_parse -C .git/objects .git/objects/ false true false '' "$ROOT/.git" "$ROOT/.git" |
Matthias Lederhofer | dace6e4 | 2007-06-06 09:01:21 +0200 | [diff] [blame] | 70 | |
SZEDER Gábor | a2f5a87 | 2017-02-03 03:48:23 +0100 | [diff] [blame] | 71 | test_rev_parse -C sub/dir subdirectory false false true sub/dir/ "$ROOT/.git" "$ROOT/.git" |
Matthias Lederhofer | dace6e4 | 2007-06-06 09:01:21 +0200 | [diff] [blame] | 72 | |
Eric Sunshine | 1dea0dc | 2016-05-18 16:15:44 -0400 | [diff] [blame] | 73 | test_rev_parse -b t 'core.bare = true' true false false |
Matthias Lederhofer | dace6e4 | 2007-06-06 09:01:21 +0200 | [diff] [blame] | 74 | |
Eric Sunshine | 1dea0dc | 2016-05-18 16:15:44 -0400 | [diff] [blame] | 75 | test_rev_parse -b u 'core.bare undefined' false false true |
Matthias Lederhofer | dace6e4 | 2007-06-06 09:01:21 +0200 | [diff] [blame] | 76 | |
Matthias Lederhofer | dace6e4 | 2007-06-06 09:01:21 +0200 | [diff] [blame] | 77 | |
SZEDER Gábor | a2f5a87 | 2017-02-03 03:48:23 +0100 | [diff] [blame] | 78 | test_rev_parse -C work -g ../.git -b f 'GIT_DIR=../.git, core.bare = false' false false true '' "../.git" "$ROOT/.git" |
Matthias Lederhofer | dace6e4 | 2007-06-06 09:01:21 +0200 | [diff] [blame] | 79 | |
Eric Sunshine | e6273f4 | 2016-05-18 16:15:45 -0400 | [diff] [blame] | 80 | test_rev_parse -C work -g ../.git -b t 'GIT_DIR=../.git, core.bare = true' true false false '' |
Matthias Lederhofer | dace6e4 | 2007-06-06 09:01:21 +0200 | [diff] [blame] | 81 | |
Eric Sunshine | e6273f4 | 2016-05-18 16:15:45 -0400 | [diff] [blame] | 82 | test_rev_parse -C work -g ../.git -b u 'GIT_DIR=../.git, core.bare undefined' false false true '' |
Matthias Lederhofer | dace6e4 | 2007-06-06 09:01:21 +0200 | [diff] [blame] | 83 | |
Matthias Lederhofer | dace6e4 | 2007-06-06 09:01:21 +0200 | [diff] [blame] | 84 | |
SZEDER Gábor | a2f5a87 | 2017-02-03 03:48:23 +0100 | [diff] [blame] | 85 | test_rev_parse -C work -g ../repo.git -b f 'GIT_DIR=../repo.git, core.bare = false' false false true '' "../repo.git" "$ROOT/repo.git" |
Matthias Lederhofer | dace6e4 | 2007-06-06 09:01:21 +0200 | [diff] [blame] | 86 | |
Eric Sunshine | e6273f4 | 2016-05-18 16:15:45 -0400 | [diff] [blame] | 87 | test_rev_parse -C work -g ../repo.git -b t 'GIT_DIR=../repo.git, core.bare = true' true false false '' |
Matthias Lederhofer | dace6e4 | 2007-06-06 09:01:21 +0200 | [diff] [blame] | 88 | |
Eric Sunshine | e6273f4 | 2016-05-18 16:15:45 -0400 | [diff] [blame] | 89 | test_rev_parse -C work -g ../repo.git -b u 'GIT_DIR=../repo.git, core.bare undefined' false false true '' |
Matthias Lederhofer | dace6e4 | 2007-06-06 09:01:21 +0200 | [diff] [blame] | 90 | |
Michael Rappazzo | 5de8a54 | 2017-02-17 17:59:02 +0100 | [diff] [blame] | 91 | test_expect_success 'git-common-dir from worktree root' ' |
| 92 | echo .git >expect && |
| 93 | git rev-parse --git-common-dir >actual && |
| 94 | test_cmp expect actual |
| 95 | ' |
| 96 | |
Johannes Schindelin | 098aa86 | 2017-02-17 17:59:06 +0100 | [diff] [blame] | 97 | test_expect_success 'git-common-dir inside sub-dir' ' |
Michael Rappazzo | 5de8a54 | 2017-02-17 17:59:02 +0100 | [diff] [blame] | 98 | mkdir -p path/to/child && |
| 99 | test_when_finished "rm -rf path" && |
| 100 | echo "$(git -C path/to/child rev-parse --show-cdup).git" >expect && |
| 101 | git -C path/to/child rev-parse --git-common-dir >actual && |
| 102 | test_cmp expect actual |
| 103 | ' |
| 104 | |
| 105 | test_expect_success 'git-path from worktree root' ' |
| 106 | echo .git/objects >expect && |
| 107 | git rev-parse --git-path objects >actual && |
| 108 | test_cmp expect actual |
| 109 | ' |
| 110 | |
Johannes Schindelin | 098aa86 | 2017-02-17 17:59:06 +0100 | [diff] [blame] | 111 | test_expect_success 'git-path inside sub-dir' ' |
Michael Rappazzo | 5de8a54 | 2017-02-17 17:59:02 +0100 | [diff] [blame] | 112 | mkdir -p path/to/child && |
| 113 | test_when_finished "rm -rf path" && |
| 114 | echo "$(git -C path/to/child rev-parse --show-cdup).git/objects" >expect && |
| 115 | git -C path/to/child rev-parse --git-path objects >actual && |
| 116 | test_cmp expect actual |
| 117 | ' |
| 118 | |
Øystein Walle | 417abfd | 2017-09-18 19:04:29 +0200 | [diff] [blame] | 119 | test_expect_success 'rev-parse --is-shallow-repository in shallow repo' ' |
| 120 | test_commit test_commit && |
| 121 | echo true >expect && |
| 122 | git clone --depth 1 --no-local . shallow && |
| 123 | test_when_finished "rm -rf shallow" && |
| 124 | git -C shallow rev-parse --is-shallow-repository >actual && |
| 125 | test_cmp expect actual |
| 126 | ' |
| 127 | |
| 128 | test_expect_success 'rev-parse --is-shallow-repository in non-shallow repo' ' |
| 129 | echo false >expect && |
| 130 | git rev-parse --is-shallow-repository >actual && |
| 131 | test_cmp expect actual |
| 132 | ' |
| 133 | |
Stefan Beller | bf0231c | 2017-03-08 15:07:42 -0800 | [diff] [blame] | 134 | test_expect_success 'showing the superproject correctly' ' |
| 135 | git rev-parse --show-superproject-working-tree >out && |
| 136 | test_must_be_empty out && |
| 137 | |
| 138 | test_create_repo super && |
| 139 | test_commit -C super test_commit && |
| 140 | test_create_repo sub && |
| 141 | test_commit -C sub test_commit && |
| 142 | git -C super submodule add ../sub dir/sub && |
| 143 | echo $(pwd)/super >expect && |
| 144 | git -C super/dir/sub rev-parse --show-superproject-working-tree >out && |
Sam McKelvie | c5cbb27 | 2018-09-27 11:10:54 -0700 | [diff] [blame] | 145 | test_cmp expect out && |
| 146 | |
| 147 | test_commit -C super submodule_add && |
| 148 | git -C super checkout -b branch1 && |
| 149 | git -C super/dir/sub checkout -b branch1 && |
| 150 | test_commit -C super/dir/sub branch1_commit && |
| 151 | git -C super add dir/sub && |
| 152 | test_commit -C super branch1_commit && |
| 153 | git -C super checkout -b branch2 master && |
| 154 | git -C super/dir/sub checkout -b branch2 master && |
| 155 | test_commit -C super/dir/sub branch2_commit && |
| 156 | git -C super add dir/sub && |
| 157 | test_commit -C super branch2_commit && |
| 158 | test_must_fail git -C super merge branch1 && |
| 159 | |
| 160 | git -C super/dir/sub rev-parse --show-superproject-working-tree >out && |
Stefan Beller | bf0231c | 2017-03-08 15:07:42 -0800 | [diff] [blame] | 161 | test_cmp expect out |
| 162 | ' |
| 163 | |
Matthias Lederhofer | dace6e4 | 2007-06-06 09:01:21 +0200 | [diff] [blame] | 164 | test_done |