]> git.ipfire.org Git - thirdparty/git.git/blobdiff - t/t1500-rev-parse.sh
t3905: remove nested git in command substitution
[thirdparty/git.git] / t / t1500-rev-parse.sh
index 408b97d5af9551f91a86e70c6c37b912719bfd15..abdda360d5258daf5c97184c900ace674534537f 100755 (executable)
@@ -1,8 +1,21 @@
 #!/bin/sh
 
 test_description='test git rev-parse'
+GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
+export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+
 . ./test-lib.sh
 
+test_one () {
+       dir="$1" &&
+       expect="$2" &&
+       shift &&
+       shift &&
+       echo "$expect" >expect &&
+       git -C "$dir" rev-parse "$@" >actual &&
+       test_cmp expect actual
+}
+
 # usage: [options] label is-bare is-inside-git is-inside-work prefix git-dir absolute-git-dir
 test_rev_parse () {
        d=
@@ -60,7 +73,13 @@ ROOT=$(pwd)
 
 test_expect_success 'setup' '
        mkdir -p sub/dir work &&
-       cp -R .git repo.git
+       cp -R .git repo.git &&
+       git checkout -B main &&
+       test_commit abc &&
+       git checkout -b side &&
+       test_commit def &&
+       git checkout main &&
+       git worktree add worktree side
 '
 
 test_rev_parse toplevel false false true '' .git "$ROOT/.git"
@@ -88,6 +107,45 @@ test_rev_parse -C work -g ../repo.git -b t 'GIT_DIR=../repo.git, core.bare = tru
 
 test_rev_parse -C work -g ../repo.git -b u 'GIT_DIR=../repo.git, core.bare undefined' false false true ''
 
+test_expect_success 'rev-parse --path-format=absolute' '
+       test_one "." "$ROOT/.git" --path-format=absolute --git-dir &&
+       test_one "." "$ROOT/.git" --path-format=absolute --git-common-dir &&
+       test_one "sub/dir" "$ROOT/.git" --path-format=absolute --git-dir &&
+       test_one "sub/dir" "$ROOT/.git" --path-format=absolute --git-common-dir &&
+       test_one "worktree" "$ROOT/.git/worktrees/worktree" --path-format=absolute --git-dir &&
+       test_one "worktree" "$ROOT/.git" --path-format=absolute --git-common-dir &&
+       test_one "." "$ROOT" --path-format=absolute --show-toplevel &&
+       test_one "." "$ROOT/.git/objects" --path-format=absolute --git-path objects &&
+       test_one "." "$ROOT/.git/objects/foo/bar/baz" --path-format=absolute --git-path objects/foo/bar/baz
+'
+
+test_expect_success 'rev-parse --path-format=relative' '
+       test_one "." ".git" --path-format=relative --git-dir &&
+       test_one "." ".git" --path-format=relative --git-common-dir &&
+       test_one "sub/dir" "../../.git" --path-format=relative --git-dir &&
+       test_one "sub/dir" "../../.git" --path-format=relative --git-common-dir &&
+       test_one "worktree" "../.git/worktrees/worktree" --path-format=relative --git-dir &&
+       test_one "worktree" "../.git" --path-format=relative --git-common-dir &&
+       test_one "." "./" --path-format=relative --show-toplevel &&
+       test_one "." ".git/objects" --path-format=relative --git-path objects &&
+       test_one "." ".git/objects/foo/bar/baz" --path-format=relative --git-path objects/foo/bar/baz
+'
+
+test_expect_success '--path-format=relative does not affect --absolute-git-dir' '
+       git rev-parse --path-format=relative --absolute-git-dir >actual &&
+       echo "$ROOT/.git" >expect &&
+       test_cmp expect actual
+'
+
+test_expect_success '--path-format can change in the middle of the command line' '
+       git rev-parse --path-format=absolute --git-dir --path-format=relative --git-path objects/foo/bar >actual &&
+       cat >expect <<-EOF &&
+       $ROOT/.git
+       .git/objects/foo/bar
+       EOF
+       test_cmp expect actual
+'
+
 test_expect_success 'git-common-dir from worktree root' '
        echo .git >expect &&
        git rev-parse --git-common-dir >actual &&
@@ -174,8 +232,8 @@ test_expect_success 'showing the superproject correctly' '
        test_commit -C super/dir/sub branch1_commit &&
        git -C super add dir/sub &&
        test_commit -C super branch1_commit &&
-       git -C super checkout -b branch2 master &&
-       git -C super/dir/sub checkout -b branch2 master &&
+       git -C super checkout -b branch2 main &&
+       git -C super/dir/sub checkout -b branch2 main &&
        test_commit -C super/dir/sub branch2_commit &&
        git -C super add dir/sub &&
        test_commit -C super branch2_commit &&