From 836597907b7aa2e318fc7db19ff78212121504c7 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 27 Mar 2026 17:41:56 +0100 Subject: [PATCH 01/11] infra: test-lib-functions and test-tool --git-dir --- t/helper/test-tool.c | 8 +++++++- t/test-lib-functions.sh | 31 +++++++++++++++++++++++++++---- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c index a7abc618b3887e..50c66f5b6c2634 100644 --- a/t/helper/test-tool.c +++ b/t/helper/test-tool.c @@ -3,9 +3,10 @@ #include "test-tool-utils.h" #include "trace2.h" #include "parse-options.h" +#include "environment.h" static const char * const test_tool_usage[] = { - "test-tool [-C ] ...]]", + "test-tool [-C ] [--git-dir=] ...]]", NULL }; @@ -107,9 +108,12 @@ static NORETURN void die_usage(void) int cmd_main(int argc, const char **argv) { const char *working_directory = NULL; + const char *git_dir = NULL; struct option options[] = { OPT_STRING('C', NULL, &working_directory, "directory", "change the working directory"), + OPT_STRING(0, "git-dir", &git_dir, "path", + "set the path to the repository"), OPT_END() }; @@ -123,6 +127,8 @@ int cmd_main(int argc, const char **argv) if (working_directory && chdir(working_directory) < 0) die("Could not cd to '%s'", working_directory); + if (git_dir) + setenv(GIT_DIR_ENVIRONMENT, git_dir, 1); for (size_t i = 0; i < ARRAY_SIZE(cmds); i++) { if (!strcmp(cmds[i].name, argv[1])) { diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh index 14e238d24da9ad..985bf8e1efc6ee 100644 --- a/t/test-lib-functions.sh +++ b/t/test-lib-functions.sh @@ -579,13 +579,20 @@ test_modebits () { # Unset a configuration variable, but don't fail if it doesn't exist. test_unconfig () { config_dir= + config_git_dir= if test "$1" = -C then shift config_dir=$1 shift + elif test "$1" = --git-dir + then + shift + config_git_dir=$1 + shift fi - git ${config_dir:+-C "$config_dir"} config --unset-all "$@" + git ${config_git_dir:+--git-dir="$config_git_dir"} \ + ${config_dir:+-C "$config_dir"} config --unset-all "$@" config_status=$? case "$config_status" in 5) # ok, nothing to unset @@ -598,11 +605,17 @@ test_unconfig () { # Set git config, automatically unsetting it after the test is over. test_config () { config_dir= + config_git_dir= if test "$1" = -C then shift config_dir=$1 shift + elif test "$1" = --git-dir + then + shift + config_git_dir=$1 + shift fi # If --worktree is provided, use it to configure/unconfigure @@ -613,8 +626,10 @@ test_config () { shift fi - test_when_finished "test_unconfig ${config_dir:+-C '$config_dir'} ${is_worktree:+--worktree} '$1'" && - git ${config_dir:+-C "$config_dir"} config ${is_worktree:+--worktree} "$@" + test_when_finished "test_unconfig ${config_git_dir:+--git-dir '$config_git_dir'} \ + ${config_dir:+-C '$config_dir'} ${is_worktree:+--worktree} '$1'" && + git ${config_git_dir:+--git-dir="$config_git_dir"} \ + ${config_dir:+-C "$config_dir"} config ${is_worktree:+--worktree} "$@" } test_config_global () { @@ -634,6 +649,8 @@ write_script () { # # -C : # Run all git commands in directory +# --git-dir : +# Use as the git directory (for bare repositories) # --setup # Setup a hook for subsequent tests, i.e. don't remove it in a # "test_when_finished" @@ -651,6 +668,7 @@ test_hook () { disable= && remove= && indir= && + gitdir= && while test $# != 0 do case "$1" in @@ -658,6 +676,10 @@ test_hook () { indir="$2" && shift ;; + --git-dir) + gitdir="$2" && + shift + ;; --setup) setup=t ;; @@ -680,7 +702,8 @@ test_hook () { shift done && - git_dir=$(git -C "$indir" rev-parse --absolute-git-dir) && + git_dir=$(git ${indir:+-C "$indir"} ${gitdir:+--git-dir="$gitdir"} \ + rev-parse --absolute-git-dir) && hook_dir="$git_dir/hooks" && hook_file="$hook_dir/$1" && if test -n "$disable$remove" From 056600276fe5af98356ce78602622071eeb22ca6 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 27 Mar 2026 17:44:47 +0100 Subject: [PATCH 02/11] tests: use `test_hook --git-dir` for bare repositories It is all too easy for an attacker to embed a bare repository with malicious hooks inside a cloned project. Even a seemingly harmless shell prompt calling `git status` would then trigger those hooks via fsmonitor. The `safe.bareRepository` setting, when set to `explicit`, defends against this class of attack, and the test suite should be ready for the day this becomes the default, most likely in Git v3.0. The `test_hook` helper function (which gained `--git-dir` support in a preceding commit) is used throughout the test suite to install hooks into repositories. When the target is a bare repository, `test_hook -C ` fails under `safe.bareRepository=explicit` because the `-C` flag triggers implicit bare repository discovery. Replace all such calls with `test_hook --git-dir `. Some diff hunks also contain adjacent `git -C` to `git --git-dir` conversions for commands like `test_cmp_refs`, `git config`, or `git update-ref` that happen to appear in the same hunk as the `test_hook` change. These are the same kind of fix and would be difficult to separate into individual hunks. This commit was produced with the help of Claude Opus 4.6 acting as a sophisticated keyboard. It was told to replace every `test_hook -C` with `test_hook --git-dir` (and likewise for `git -C` and `test_cmp_refs -C` in the same hunks). The dominant pattern can be verified: git show HEAD | sed 's/test_hook --git-dir/test_hook -C/g' | sed -ne '/^diff/,/@@/d' -e 's/^[-+]//p' | uniq -u Any residual output consists of the adjacent `git -C` to `--git-dir` conversions mentioned above. Assisted-by: Claude Opus 4.6 Signed-off-by: Johannes Schindelin --- t/t1416-ref-transaction-hooks.sh | 4 +-- t/t2400-worktree-add.sh | 2 +- t/t5411/once-0010-report-status-v1.sh | 4 +-- t/t5411/test-0002-pre-receive-declined.sh | 2 +- ...st-0003-pre-receive-declined--porcelain.sh | 2 +- t/t5411/test-0013-bad-protocol.sh | 34 +++++++++---------- t/t5411/test-0014-bad-protocol--porcelain.sh | 34 +++++++++---------- t/t5411/test-0020-report-ng.sh | 6 ++-- t/t5411/test-0021-report-ng--porcelain.sh | 6 ++-- t/t5411/test-0022-report-unexpect-ref.sh | 2 +- ...est-0023-report-unexpect-ref--porcelain.sh | 2 +- t/t5411/test-0024-report-unknown-ref.sh | 2 +- ...test-0025-report-unknown-ref--porcelain.sh | 2 +- t/t5411/test-0026-push-options.sh | 14 ++++---- t/t5411/test-0027-push-options--porcelain.sh | 14 ++++---- t/t5411/test-0030-report-ok.sh | 2 +- t/t5411/test-0031-report-ok--porcelain.sh | 2 +- t/t5411/test-0032-report-with-options.sh | 14 ++++---- ...est-0033-report-with-options--porcelain.sh | 14 ++++---- t/t5411/test-0034-report-ft.sh | 2 +- t/t5411/test-0035-report-ft--porcelain.sh | 2 +- ...t-0036-report-multi-rewrite-for-one-ref.sh | 6 ++-- ...rt-multi-rewrite-for-one-ref--porcelain.sh | 10 +++--- t/t5411/test-0038-report-mixed-refs.sh | 2 +- .../test-0039-report-mixed-refs--porcelain.sh | 2 +- t/t5411/test-0040-process-all-refs.sh | 2 +- .../test-0041-process-all-refs--porcelain.sh | 2 +- ...t-0050-proc-receive-refs-with-modifiers.sh | 4 +-- t/t5510-fetch.sh | 2 +- t/t5547-push-quarantine.sh | 4 +-- 30 files changed, 100 insertions(+), 100 deletions(-) diff --git a/t/t1416-ref-transaction-hooks.sh b/t/t1416-ref-transaction-hooks.sh index d91dd3a3b55e46..1ce76160ba628d 100755 --- a/t/t1416-ref-transaction-hooks.sh +++ b/t/t1416-ref-transaction-hooks.sh @@ -110,11 +110,11 @@ test_expect_success 'interleaving hook calls succeed' ' git init --bare target-repo.git && - test_hook -C target-repo.git reference-transaction <<-\EOF && + test_hook --git-dir target-repo.git reference-transaction <<-\EOF && echo $0 "$@" >>actual EOF - test_hook -C target-repo.git update <<-\EOF && + test_hook --git-dir target-repo.git update <<-\EOF && echo $0 "$@" >>actual EOF diff --git a/t/t2400-worktree-add.sh b/t/t2400-worktree-add.sh index 023e1301c8e68e..4e670f53c4aedd 100755 --- a/t/t2400-worktree-add.sh +++ b/t/t2400-worktree-add.sh @@ -1075,7 +1075,7 @@ done post_checkout_hook () { test_when_finished "rm -rf .git/hooks" && mkdir .git/hooks && - test_hook -C "$1" post-checkout <<-\EOF + test_hook "$@" post-checkout <<-\EOF { echo $* git rev-parse --git-dir --show-toplevel diff --git a/t/t5411/once-0010-report-status-v1.sh b/t/t5411/once-0010-report-status-v1.sh index f9ffb01e50997a..42e2b0435574b5 100644 --- a/t/t5411/once-0010-report-status-v1.sh +++ b/t/t5411/once-0010-report-status-v1.sh @@ -1,9 +1,9 @@ test_expect_success "setup receive.procReceiveRefs" ' - git -C "$upstream" config --add receive.procReceiveRefs refs/for + git --git-dir="$upstream" config --add receive.procReceiveRefs refs/for ' test_expect_success "setup proc-receive hook" ' - test_hook -C "$upstream" --clobber proc-receive <<-EOF + test_hook --git-dir "$upstream" --clobber proc-receive <<-EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/for/main/topic1" \ diff --git a/t/t5411/test-0002-pre-receive-declined.sh b/t/t5411/test-0002-pre-receive-declined.sh index 98a9d13041a05d..f6abfab69da7d1 100644 --- a/t/t5411/test-0002-pre-receive-declined.sh +++ b/t/t5411/test-0002-pre-receive-declined.sh @@ -1,6 +1,6 @@ test_expect_success "setup pre-receive hook ($PROTOCOL)" ' mv "$upstream/hooks/pre-receive" "$upstream/hooks/pre-receive.ok" && - test_hook -C "$upstream" --clobber pre-receive <<-\EOF + test_hook --git-dir "$upstream" --clobber pre-receive <<-\EOF exit 1 EOF ' diff --git a/t/t5411/test-0003-pre-receive-declined--porcelain.sh b/t/t5411/test-0003-pre-receive-declined--porcelain.sh index 67ca6dc4f8f232..98b746013b2248 100644 --- a/t/t5411/test-0003-pre-receive-declined--porcelain.sh +++ b/t/t5411/test-0003-pre-receive-declined--porcelain.sh @@ -1,6 +1,6 @@ test_expect_success "setup pre-receive hook ($PROTOCOL/porcelain)" ' mv "$upstream/hooks/pre-receive" "$upstream/hooks/pre-receive.ok" && - test_hook -C "$upstream" --clobber pre-receive <<-\EOF + test_hook --git-dir "$upstream" --clobber pre-receive <<-\EOF exit 1 EOF ' diff --git a/t/t5411/test-0013-bad-protocol.sh b/t/t5411/test-0013-bad-protocol.sh index 8d22e17aee31a5..562650a96db963 100644 --- a/t/t5411/test-0013-bad-protocol.sh +++ b/t/t5411/test-0013-bad-protocol.sh @@ -1,5 +1,5 @@ test_expect_success "setup proc-receive hook (unknown version, $PROTOCOL)" ' - test_hook -C "$upstream" --clobber proc-receive <<-\EOF + test_hook --git-dir "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v --version 2 EOF @@ -34,13 +34,13 @@ test_expect_success "proc-receive: bad protocol (unknown version, $PROTOCOL)" ' EOF test_cmp expect actual-error && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/heads/main EOF ' test_expect_success "setup proc-receive hook (hook --die-read-version, $PROTOCOL)" ' - test_hook -C "$upstream" --clobber proc-receive <<-\EOF + test_hook --git-dir "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v --die-read-version EOF @@ -65,13 +65,13 @@ test_expect_success "proc-receive: bad protocol (hook --die-read-version, $PROTO grep "remote: fatal: die with the --die-read-version option" out-$test_count && grep "remote: error: fail to negotiate version with proc-receive hook" out-$test_count && - test_cmp_refs -C "$upstream" <<-\EOF + test_cmp_refs --git-dir "$upstream" <<-\EOF refs/heads/main EOF ' test_expect_success "setup proc-receive hook (hook --die-write-version, $PROTOCOL)" ' - test_hook -C "$upstream" --clobber proc-receive <<-\EOF + test_hook --git-dir "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v --die-write-version EOF @@ -96,13 +96,13 @@ test_expect_success "proc-receive: bad protocol (hook --die-write-version, $PROT grep "remote: fatal: die with the --die-write-version option" out-$test_count && grep "remote: error: fail to negotiate version with proc-receive hook" out-$test_count && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/heads/main EOF ' test_expect_success "setup proc-receive hook (hook --die-read-commands, $PROTOCOL)" ' - test_hook -C "$upstream" --clobber proc-receive <<-\EOF + test_hook --git-dir "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v --die-read-commands EOF @@ -126,13 +126,13 @@ test_expect_success "proc-receive: bad protocol (hook --die-read-commands, $PROT test_cmp expect actual && grep "remote: fatal: die with the --die-read-commands option" out-$test_count && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/heads/main EOF ' test_expect_success "setup proc-receive hook (hook --die-read-push-options, $PROTOCOL)" ' - test_hook -C "$upstream" --clobber proc-receive <<-\EOF + test_hook --git-dir "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v --die-read-push-options EOF @@ -158,13 +158,13 @@ test_expect_success "proc-receive: bad protocol (hook --die-read-push-options, $ test_cmp expect actual && grep "remote: fatal: die with the --die-read-push-options option" out-$test_count && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/heads/main EOF ' test_expect_success "setup proc-receive hook (hook --die-write-report, $PROTOCOL)" ' - test_hook -C "$upstream" --clobber proc-receive <<-\EOF + test_hook --git-dir "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v --die-write-report EOF @@ -188,13 +188,13 @@ test_expect_success "proc-receive: bad protocol (hook --die-write-report, $PROTO test_cmp expect actual && grep "remote: fatal: die with the --die-write-report option" out-$test_count && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/heads/main EOF ' test_expect_success "setup proc-receive hook (no report, $PROTOCOL)" ' - test_hook -C "$upstream" --clobber proc-receive <<-\EOF + test_hook --git-dir "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v EOF @@ -231,12 +231,12 @@ test_expect_success "proc-receive: bad protocol (no report, $PROTOCOL)" ' # Refs of upstream : main(A) next(A) # Refs of workbench: main(A) tags/v123 test_expect_success "cleanup ($PROTOCOL)" ' - git -C "$upstream" update-ref -d refs/heads/next + git --git-dir="$upstream" update-ref -d refs/heads/next ' test_expect_success "setup proc-receive hook (no ref, $PROTOCOL)" ' - test_hook -C "$upstream" --clobber proc-receive <<-\EOF + test_hook --git-dir "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok" @@ -263,13 +263,13 @@ test_expect_success "proc-receive: bad protocol (no ref, $PROTOCOL)" ' EOF test_cmp expect actual && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/heads/main EOF ' test_expect_success "setup proc-receive hook (unknown status, $PROTOCOL)" ' - test_hook -C "$upstream" --clobber proc-receive <<-\EOF + test_hook --git-dir "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "xx refs/for/main/topic" diff --git a/t/t5411/test-0014-bad-protocol--porcelain.sh b/t/t5411/test-0014-bad-protocol--porcelain.sh index 298a3d1feca1ff..59e8b505559105 100644 --- a/t/t5411/test-0014-bad-protocol--porcelain.sh +++ b/t/t5411/test-0014-bad-protocol--porcelain.sh @@ -1,5 +1,5 @@ test_expect_success "setup proc-receive hook (unknown version, $PROTOCOL/porcelain)" ' - test_hook -C "$upstream" --clobber proc-receive <<-\EOF + test_hook --git-dir "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v --version 2 EOF @@ -34,13 +34,13 @@ test_expect_success "proc-receive: bad protocol (unknown version, $PROTOCOL/porc EOF test_cmp expect actual-error && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/heads/main EOF ' test_expect_success "setup proc-receive hook (hook --die-read-version, $PROTOCOL/porcelain)" ' - test_hook -C "$upstream" --clobber proc-receive <<-EOF + test_hook --git-dir "$upstream" --clobber proc-receive <<-EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v --die-read-version EOF @@ -65,13 +65,13 @@ test_expect_success "proc-receive: bad protocol (hook --die-read-version, $PROTO grep "remote: fatal: die with the --die-read-version option" out-$test_count && grep "remote: error: fail to negotiate version with proc-receive hook" out-$test_count && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/heads/main EOF ' test_expect_success "setup proc-receive hook (hook --die-write-version, $PROTOCOL/porcelain)" ' - test_hook -C "$upstream" --clobber proc-receive <<-\EOF + test_hook --git-dir "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v --die-write-version EOF @@ -96,13 +96,13 @@ test_expect_success "proc-receive: bad protocol (hook --die-write-version, $PROT grep "remote: fatal: die with the --die-write-version option" out-$test_count && grep "remote: error: fail to negotiate version with proc-receive hook" out-$test_count && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/heads/main EOF ' test_expect_success "setup proc-receive hook (hook --die-read-commands, $PROTOCOL/porcelain)" ' - test_hook -C "$upstream" --clobber proc-receive <<-\EOF + test_hook --git-dir "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v --die-read-commands EOF @@ -126,13 +126,13 @@ test_expect_success "proc-receive: bad protocol (hook --die-read-commands, $PROT test_cmp expect actual && grep "remote: fatal: die with the --die-read-commands option" out-$test_count && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/heads/main EOF ' test_expect_success "setup proc-receive hook (hook --die-read-push-options, $PROTOCOL/porcelain)" ' - test_hook -C "$upstream" --clobber proc-receive <<-\EOF + test_hook --git-dir "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v --die-read-push-options EOF @@ -158,13 +158,13 @@ test_expect_success "proc-receive: bad protocol (hook --die-read-push-options, $ test_cmp expect actual && grep "remote: fatal: die with the --die-read-push-options option" out-$test_count && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/heads/main EOF ' test_expect_success "setup proc-receive hook (hook --die-write-report, $PROTOCOL/porcelain)" ' - test_hook -C "$upstream" --clobber proc-receive <<-\EOF + test_hook --git-dir "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v --die-write-report EOF @@ -188,13 +188,13 @@ test_expect_success "proc-receive: bad protocol (hook --die-write-report, $PROTO test_cmp expect actual && grep "remote: fatal: die with the --die-write-report option" out-$test_count && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/heads/main EOF ' test_expect_success "setup proc-receive hook (no report, $PROTOCOL/porcelain)" ' - test_hook -C "$upstream" --clobber proc-receive <<-\EOF + test_hook --git-dir "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v EOF @@ -232,11 +232,11 @@ test_expect_success "proc-receive: bad protocol (no report, $PROTOCOL/porcelain) # Refs of upstream : main(A) next(A) # Refs of workbench: main(A) tags/v123 test_expect_success "cleanup ($PROTOCOL/porcelain)" ' - git -C "$upstream" update-ref -d refs/heads/next + git --git-dir="$upstream" update-ref -d refs/heads/next ' test_expect_success "setup proc-receive hook (no ref, $PROTOCOL/porcelain)" ' - test_hook -C "$upstream" --clobber proc-receive <<-\EOF + test_hook --git-dir "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok" @@ -264,13 +264,13 @@ test_expect_success "proc-receive: bad protocol (no ref, $PROTOCOL/porcelain)" ' EOF test_cmp expect actual && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/heads/main EOF ' test_expect_success "setup proc-receive hook (unknown status, $PROTOCOL/porcelain)" ' - test_hook -C "$upstream" --clobber proc-receive <<-\EOF + test_hook --git-dir "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "xx refs/for/main/topic" diff --git a/t/t5411/test-0020-report-ng.sh b/t/t5411/test-0020-report-ng.sh index 6347c9629b304a..21853c8bd1ba2f 100644 --- a/t/t5411/test-0020-report-ng.sh +++ b/t/t5411/test-0020-report-ng.sh @@ -1,5 +1,5 @@ test_expect_success "setup proc-receive hook (ng, no message, $PROTOCOL)" ' - test_hook -C "$upstream" --clobber proc-receive <<-\EOF + test_hook --git-dir "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ng refs/for/main/topic" @@ -25,13 +25,13 @@ test_expect_success "proc-receive: fail to update (ng, no message, $PROTOCOL)" ' EOF test_cmp expect actual && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/heads/main EOF ' test_expect_success "setup proc-receive hook (ng message, $PROTOCOL)" ' - test_hook -C "$upstream" --clobber proc-receive <<-\EOF + test_hook --git-dir "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ng refs/for/main/topic error msg" diff --git a/t/t5411/test-0021-report-ng--porcelain.sh b/t/t5411/test-0021-report-ng--porcelain.sh index 502b34fe3dd723..507c0836d983c6 100644 --- a/t/t5411/test-0021-report-ng--porcelain.sh +++ b/t/t5411/test-0021-report-ng--porcelain.sh @@ -1,5 +1,5 @@ test_expect_success "setup proc-receive hook (ng, no message, $PROTOCOL/porcelain)" ' - test_hook -C "$upstream" --clobber proc-receive <<-\EOF + test_hook --git-dir "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ng refs/for/main/topic" @@ -26,13 +26,13 @@ test_expect_success "proc-receive: fail to update (ng, no message, $PROTOCOL/por EOF test_cmp expect actual && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/heads/main EOF ' test_expect_success "setup proc-receive hook (ng message, $PROTOCOL/porcelain)" ' - test_hook -C "$upstream" --clobber proc-receive <<-\EOF + test_hook --git-dir "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ng refs/for/main/topic error msg" diff --git a/t/t5411/test-0022-report-unexpect-ref.sh b/t/t5411/test-0022-report-unexpect-ref.sh index 7744392a6262cf..b4fad45eaf6aa7 100644 --- a/t/t5411/test-0022-report-unexpect-ref.sh +++ b/t/t5411/test-0022-report-unexpect-ref.sh @@ -1,5 +1,5 @@ test_expect_success "setup proc-receive hook (unexpected ref, $PROTOCOL)" ' - test_hook -C "$upstream" --clobber proc-receive <<-\EOF + test_hook --git-dir "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/heads/main" diff --git a/t/t5411/test-0023-report-unexpect-ref--porcelain.sh b/t/t5411/test-0023-report-unexpect-ref--porcelain.sh index 6d116ef692c6c2..7bf5c12fd63c4e 100644 --- a/t/t5411/test-0023-report-unexpect-ref--porcelain.sh +++ b/t/t5411/test-0023-report-unexpect-ref--porcelain.sh @@ -1,5 +1,5 @@ test_expect_success "setup proc-receive hook (unexpected ref, $PROTOCOL/porcelain)" ' - test_hook -C "$upstream" --clobber proc-receive <<-\EOF + test_hook --git-dir "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/heads/main" diff --git a/t/t5411/test-0024-report-unknown-ref.sh b/t/t5411/test-0024-report-unknown-ref.sh index 619ca2f421aad5..0c878dfb9e17f2 100644 --- a/t/t5411/test-0024-report-unknown-ref.sh +++ b/t/t5411/test-0024-report-unknown-ref.sh @@ -1,5 +1,5 @@ test_expect_success "setup proc-receive hook (unexpected ref, $PROTOCOL)" ' - test_hook -C "$upstream" --clobber proc-receive <<-\EOF + test_hook --git-dir "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/for/main/topic" diff --git a/t/t5411/test-0025-report-unknown-ref--porcelain.sh b/t/t5411/test-0025-report-unknown-ref--porcelain.sh index 8b3f5d05a3fab6..9d83c46c1248db 100644 --- a/t/t5411/test-0025-report-unknown-ref--porcelain.sh +++ b/t/t5411/test-0025-report-unknown-ref--porcelain.sh @@ -1,5 +1,5 @@ test_expect_success "setup proc-receive hook (unexpected ref, $PROTOCOL/porcelain)" ' - test_hook -C "$upstream" --clobber proc-receive <<-\EOF + test_hook --git-dir "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/for/main/topic" diff --git a/t/t5411/test-0026-push-options.sh b/t/t5411/test-0026-push-options.sh index 510fff38da9cb6..626c1f9688c62a 100644 --- a/t/t5411/test-0026-push-options.sh +++ b/t/t5411/test-0026-push-options.sh @@ -1,6 +1,6 @@ test_expect_success "setup proc-receive hook and disable push-options ($PROTOCOL)" ' - git -C "$upstream" config receive.advertisePushOptions false && - test_hook -C "$upstream" --clobber proc-receive <<-\EOF + git --git-dir="$upstream" config receive.advertisePushOptions false && + test_hook --git-dir "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/for/main/topic" @@ -21,17 +21,17 @@ test_expect_success "proc-receive: not support push options ($PROTOCOL)" ' test_grep "fatal: the receiving end does not support push options" \ actual && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/heads/main EOF ' test_expect_success "enable push options ($PROTOCOL)" ' - git -C "$upstream" config receive.advertisePushOptions true + git --git-dir="$upstream" config receive.advertisePushOptions true ' test_expect_success "setup version=0 for proc-receive hook ($PROTOCOL)" ' - test_hook -C "$upstream" --clobber proc-receive <<-\EOF + test_hook --git-dir "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ --version 0 \ @@ -68,14 +68,14 @@ test_expect_success "proc-receive: ignore push-options for version 0 ($PROTOCOL) EOF test_cmp expect actual && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/heads/main refs/heads/next EOF ' test_expect_success "restore proc-receive hook ($PROTOCOL)" ' - test_hook -C "$upstream" --clobber proc-receive <<-\EOF + test_hook --git-dir "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/for/main/topic" diff --git a/t/t5411/test-0027-push-options--porcelain.sh b/t/t5411/test-0027-push-options--porcelain.sh index 9435457de0cd9b..af8e613f716b1e 100644 --- a/t/t5411/test-0027-push-options--porcelain.sh +++ b/t/t5411/test-0027-push-options--porcelain.sh @@ -1,6 +1,6 @@ test_expect_success "setup proc-receive hook and disable push-options ($PROTOCOL/porcelain)" ' - git -C "$upstream" config receive.advertisePushOptions false && - test_hook -C "$upstream" --clobber proc-receive <<-\EOF + git --git-dir="$upstream" config receive.advertisePushOptions false && + test_hook --git-dir "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/for/main/topic" @@ -22,17 +22,17 @@ test_expect_success "proc-receive: not support push options ($PROTOCOL/porcelain test_grep "fatal: the receiving end does not support push options" \ actual && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/heads/main EOF ' test_expect_success "enable push options ($PROTOCOL/porcelain)" ' - git -C "$upstream" config receive.advertisePushOptions true + git --git-dir="$upstream" config receive.advertisePushOptions true ' test_expect_success "setup version=0 for proc-receive hook ($PROTOCOL/porcelain)" ' - test_hook -C "$upstream" --clobber proc-receive <<-\EOF + test_hook --git-dir "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ --version 0 \ @@ -71,14 +71,14 @@ test_expect_success "proc-receive: ignore push-options for version 0 ($PROTOCOL/ EOF test_cmp expect actual && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/heads/main refs/heads/next EOF ' test_expect_success "restore proc-receive hook ($PROTOCOL/porcelain)" ' - test_hook -C "$upstream" --clobber proc-receive <<-\EOF + test_hook --git-dir "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/for/main/topic" diff --git a/t/t5411/test-0030-report-ok.sh b/t/t5411/test-0030-report-ok.sh index 0f190a6e851697..9a2c3063771601 100644 --- a/t/t5411/test-0030-report-ok.sh +++ b/t/t5411/test-0030-report-ok.sh @@ -1,5 +1,5 @@ test_expect_success "setup proc-receive hook (ok, $PROTOCOL)" ' - test_hook -C "$upstream" --clobber proc-receive <<-\EOF + test_hook --git-dir "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/for/main/topic" diff --git a/t/t5411/test-0031-report-ok--porcelain.sh b/t/t5411/test-0031-report-ok--porcelain.sh index 7ec39812638a87..863c69ec823379 100644 --- a/t/t5411/test-0031-report-ok--porcelain.sh +++ b/t/t5411/test-0031-report-ok--porcelain.sh @@ -1,5 +1,5 @@ test_expect_success "setup proc-receive hook (ok, $PROTOCOL/porcelain)" ' - test_hook -C "$upstream" --clobber proc-receive <<-\EOF + test_hook --git-dir "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/for/main/topic" diff --git a/t/t5411/test-0032-report-with-options.sh b/t/t5411/test-0032-report-with-options.sh index 07733b94b81734..2dddaf19572574 100644 --- a/t/t5411/test-0032-report-with-options.sh +++ b/t/t5411/test-0032-report-with-options.sh @@ -1,5 +1,5 @@ test_expect_success "setup proc-receive hook (option without matching ok, $PROTOCOL)" ' - test_hook -C "$upstream" --clobber proc-receive <<-EOF + test_hook --git-dir "$upstream" --clobber proc-receive <<-EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "option refname refs/pull/123/head" \ @@ -30,7 +30,7 @@ test_expect_success "proc-receive: report option without matching ok ($PROTOCOL) ' test_expect_success "setup proc-receive hook (option refname, $PROTOCOL)" ' - test_hook -C "$upstream" --clobber proc-receive <<-\EOF + test_hook --git-dir "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/for/main/topic" \ @@ -62,7 +62,7 @@ test_expect_success "proc-receive: report option refname ($PROTOCOL)" ' ' test_expect_success "setup proc-receive hook (option refname and forced-update, $PROTOCOL)" ' - test_hook -C "$upstream" --clobber proc-receive <<-\EOF + test_hook --git-dir "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/for/main/topic" \ @@ -95,7 +95,7 @@ test_expect_success "proc-receive: report option refname and forced-update ($PRO ' test_expect_success "setup proc-receive hook (option refname and old-oid, $PROTOCOL)" ' - test_hook -C "$upstream" --clobber proc-receive <<-EOF + test_hook --git-dir "$upstream" --clobber proc-receive <<-EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/for/main/topic" \ @@ -129,7 +129,7 @@ test_expect_success "proc-receive: report option refname and old-oid ($PROTOCOL) ' test_expect_success "setup proc-receive hook (option old-oid, $PROTOCOL)" ' - test_hook -C "$upstream" --clobber proc-receive <<-EOF + test_hook --git-dir "$upstream" --clobber proc-receive <<-EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/for/main/topic" \ @@ -161,7 +161,7 @@ test_expect_success "proc-receive: report option old-oid ($PROTOCOL)" ' ' test_expect_success "setup proc-receive hook (option old-oid and new-oid, $PROTOCOL)" ' - test_hook -C "$upstream" --clobber proc-receive <<-EOF + test_hook --git-dir "$upstream" --clobber proc-receive <<-EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/for/main/topic" \ @@ -195,7 +195,7 @@ test_expect_success "proc-receive: report option old-oid and new-oid ($PROTOCOL) ' test_expect_success "setup proc-receive hook (report with multiple rewrites, $PROTOCOL)" ' - test_hook -C "$upstream" --clobber proc-receive <<-EOF + test_hook --git-dir "$upstream" --clobber proc-receive <<-EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/for/a/b/c/topic" \ diff --git a/t/t5411/test-0033-report-with-options--porcelain.sh b/t/t5411/test-0033-report-with-options--porcelain.sh index 2e1831b104e8a9..f1aaa1e3b5f293 100644 --- a/t/t5411/test-0033-report-with-options--porcelain.sh +++ b/t/t5411/test-0033-report-with-options--porcelain.sh @@ -1,5 +1,5 @@ test_expect_success "setup proc-receive hook (option without matching ok, $PROTOCOL/porcelain)" ' - test_hook -C "$upstream" --clobber proc-receive <<-EOF + test_hook --git-dir "$upstream" --clobber proc-receive <<-EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "option refname refs/pull/123/head" \ @@ -31,7 +31,7 @@ test_expect_success "proc-receive: report option without matching ok ($PROTOCOL/ ' test_expect_success "setup proc-receive hook (option refname, $PROTOCOL/porcelain)" ' - test_hook -C "$upstream" --clobber proc-receive <<-\EOF + test_hook --git-dir "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/for/main/topic" \ @@ -64,7 +64,7 @@ test_expect_success "proc-receive: report option refname ($PROTOCOL/porcelain)" ' test_expect_success "setup proc-receive hook (option refname and forced-update, $PROTOCOL/porcelain)" ' - test_hook -C "$upstream" --clobber proc-receive <<-\EOF + test_hook --git-dir "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/for/main/topic" \ @@ -99,7 +99,7 @@ test_expect_success "proc-receive: report option refname and forced-update ($PRO ' test_expect_success "setup proc-receive hook (option refname and old-oid, $PROTOCOL/porcelain)" ' - test_hook -C "$upstream" --clobber proc-receive <<-EOF + test_hook --git-dir "$upstream" --clobber proc-receive <<-EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/for/main/topic" \ @@ -134,7 +134,7 @@ test_expect_success "proc-receive: report option refname and old-oid ($PROTOCOL/ ' test_expect_success "setup proc-receive hook (option old-oid, $PROTOCOL/porcelain)" ' - test_hook -C "$upstream" --clobber proc-receive <<-EOF + test_hook --git-dir "$upstream" --clobber proc-receive <<-EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/for/main/topic" \ @@ -167,7 +167,7 @@ test_expect_success "proc-receive: report option old-oid ($PROTOCOL/porcelain)" ' test_expect_success "setup proc-receive hook (option old-oid and new-oid, $PROTOCOL/porcelain)" ' - test_hook -C "$upstream" --clobber proc-receive <<-EOF + test_hook --git-dir "$upstream" --clobber proc-receive <<-EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/for/main/topic" \ @@ -202,7 +202,7 @@ test_expect_success "proc-receive: report option old-oid and new-oid ($PROTOCOL/ ' test_expect_success "setup proc-receive hook (report with multiple rewrites, $PROTOCOL/porcelain)" ' - test_hook -C "$upstream" --clobber proc-receive <<-EOF + test_hook --git-dir "$upstream" --clobber proc-receive <<-EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/for/a/b/c/topic" \ diff --git a/t/t5411/test-0034-report-ft.sh b/t/t5411/test-0034-report-ft.sh index 78d0b63876eaf5..ecdc660c21becf 100644 --- a/t/t5411/test-0034-report-ft.sh +++ b/t/t5411/test-0034-report-ft.sh @@ -1,5 +1,5 @@ test_expect_success "setup proc-receive hook (ft, $PROTOCOL)" ' - test_hook -C "$upstream" --clobber proc-receive <<-\EOF + test_hook --git-dir "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/for/main/topic" \ diff --git a/t/t5411/test-0035-report-ft--porcelain.sh b/t/t5411/test-0035-report-ft--porcelain.sh index df5fc212be4081..cea6ceed5ba042 100644 --- a/t/t5411/test-0035-report-ft--porcelain.sh +++ b/t/t5411/test-0035-report-ft--porcelain.sh @@ -1,5 +1,5 @@ test_expect_success "setup proc-receive hook (fall-through, $PROTOCOL/porcelain)" ' - test_hook -C "$upstream" --clobber proc-receive <<-\EOF + test_hook --git-dir "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/for/main/topic" \ diff --git a/t/t5411/test-0036-report-multi-rewrite-for-one-ref.sh b/t/t5411/test-0036-report-multi-rewrite-for-one-ref.sh index 889e97057b8565..6caef35875add0 100644 --- a/t/t5411/test-0036-report-multi-rewrite-for-one-ref.sh +++ b/t/t5411/test-0036-report-multi-rewrite-for-one-ref.sh @@ -14,7 +14,7 @@ test_expect_success "setup git config for remote-tracking of special refs" ' ' test_expect_success "setup proc-receive hook (multiple rewrites for one ref, no refname for the 1st rewrite, $PROTOCOL)" ' - test_hook -C "$upstream" --clobber proc-receive <<-EOF + test_hook --git-dir "$upstream" --clobber proc-receive <<-EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/for/main/topic" \ @@ -87,7 +87,7 @@ test_expect_success "proc-receive: check remote-tracking #1 ($PROTOCOL)" ' ' test_expect_success "setup proc-receive hook (multiple rewrites for one ref, no refname for the 2nd rewrite, $PROTOCOL)" ' - test_hook -C "$upstream" --clobber proc-receive <<-EOF + test_hook --git-dir "$upstream" --clobber proc-receive <<-EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/for/main/topic" \ @@ -162,7 +162,7 @@ test_expect_success "proc-receive: check remote-tracking #2 ($PROTOCOL)" ' ' test_expect_success "setup proc-receive hook (multiple rewrites for one ref, $PROTOCOL)" ' - test_hook -C "$upstream" --clobber proc-receive <<-EOF + test_hook --git-dir "$upstream" --clobber proc-receive <<-EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/for/main/topic" \ diff --git a/t/t5411/test-0037-report-multi-rewrite-for-one-ref--porcelain.sh b/t/t5411/test-0037-report-multi-rewrite-for-one-ref--porcelain.sh index 1e523b1c173c66..9844185b6b938b 100644 --- a/t/t5411/test-0037-report-multi-rewrite-for-one-ref--porcelain.sh +++ b/t/t5411/test-0037-report-multi-rewrite-for-one-ref--porcelain.sh @@ -1,5 +1,5 @@ test_expect_success "setup proc-receive hook (multiple rewrites for one ref, no refname for the 1st rewrite, $PROTOCOL/porcelain)" ' - test_hook -C "$upstream" --clobber proc-receive <<-EOF + test_hook --git-dir "$upstream" --clobber proc-receive <<-EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/for/main/topic" \ @@ -52,13 +52,13 @@ test_expect_success "proc-receive: multiple rewrite for one ref, no refname for EOF test_cmp expect actual && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/heads/main EOF ' test_expect_success "setup proc-receive hook (multiple rewrites for one ref, no refname for the 2nd rewrite, $PROTOCOL/porcelain)" ' - test_hook -C "$upstream" --clobber proc-receive <<-EOF + test_hook --git-dir "$upstream" --clobber proc-receive <<-EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/for/main/topic" \ @@ -113,13 +113,13 @@ test_expect_success "proc-receive: multiple rewrites for one ref, no refname for EOF test_cmp expect actual && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/heads/main EOF ' test_expect_success "setup proc-receive hook (multiple rewrites for one ref, $PROTOCOL/porcelain)" ' - test_hook -C "$upstream" --clobber proc-receive <<-EOF + test_hook --git-dir "$upstream" --clobber proc-receive <<-EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/for/main/topic" \ diff --git a/t/t5411/test-0038-report-mixed-refs.sh b/t/t5411/test-0038-report-mixed-refs.sh index 4c70e84e410144..07235c3c73086f 100644 --- a/t/t5411/test-0038-report-mixed-refs.sh +++ b/t/t5411/test-0038-report-mixed-refs.sh @@ -1,5 +1,5 @@ test_expect_success "setup proc-receive hook ($PROTOCOL)" ' - test_hook -C "$upstream" --clobber proc-receive <<-EOF + test_hook --git-dir "$upstream" --clobber proc-receive <<-EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/for/next/topic2" \ diff --git a/t/t5411/test-0039-report-mixed-refs--porcelain.sh b/t/t5411/test-0039-report-mixed-refs--porcelain.sh index 40f4c5b1afba88..2a989f576bd9d4 100644 --- a/t/t5411/test-0039-report-mixed-refs--porcelain.sh +++ b/t/t5411/test-0039-report-mixed-refs--porcelain.sh @@ -1,5 +1,5 @@ test_expect_success "setup proc-receive hook ($PROTOCOL/porcelain)" ' - test_hook -C "$upstream" --clobber proc-receive <<-EOF + test_hook --git-dir "$upstream" --clobber proc-receive <<-EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/for/next/topic2" \ diff --git a/t/t5411/test-0040-process-all-refs.sh b/t/t5411/test-0040-process-all-refs.sh index 7ae3851efb9231..19f30f6cf6d119 100644 --- a/t/t5411/test-0040-process-all-refs.sh +++ b/t/t5411/test-0040-process-all-refs.sh @@ -17,7 +17,7 @@ test_expect_success "setup upstream branches ($PROTOCOL)" ' ' test_expect_success "setup proc-receive hook ($PROTOCOL)" ' - test_hook -C "$upstream" --clobber proc-receive <<-EOF + test_hook --git-dir "$upstream" --clobber proc-receive <<-EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/heads/main" \ diff --git a/t/t5411/test-0041-process-all-refs--porcelain.sh b/t/t5411/test-0041-process-all-refs--porcelain.sh index 02e1e084d6c9c5..54c2be08c19965 100644 --- a/t/t5411/test-0041-process-all-refs--porcelain.sh +++ b/t/t5411/test-0041-process-all-refs--porcelain.sh @@ -17,7 +17,7 @@ test_expect_success "setup upstream branches ($PROTOCOL/porcelain)" ' ' test_expect_success "setup proc-receive hook ($PROTOCOL/porcelain)" ' - test_hook -C "$upstream" --clobber proc-receive <<-EOF + test_hook --git-dir "$upstream" --clobber proc-receive <<-EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/heads/main" \ diff --git a/t/t5411/test-0050-proc-receive-refs-with-modifiers.sh b/t/t5411/test-0050-proc-receive-refs-with-modifiers.sh index 7efdfe55987225..cd4cc987b8ca56 100644 --- a/t/t5411/test-0050-proc-receive-refs-with-modifiers.sh +++ b/t/t5411/test-0050-proc-receive-refs-with-modifiers.sh @@ -9,7 +9,7 @@ test_expect_success "config receive.procReceiveRefs with modifiers ($PROTOCOL)" ' test_expect_success "setup proc-receive hook ($PROTOCOL)" ' - test_hook -C "$upstream" --clobber proc-receive <<-EOF + test_hook --git-dir "$upstream" --clobber proc-receive <<-EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/heads/main" \ @@ -70,7 +70,7 @@ test_expect_success "setup upstream: create tags/v123 ($PROTOCOL)" ' ' test_expect_success "setup proc-receive hook ($PROTOCOL)" ' - test_hook -C "$upstream" --clobber proc-receive <<-EOF + test_hook --git-dir "$upstream" --clobber proc-receive <<-EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/heads/main" \ diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh index 5dcb4b51a47d88..ba8b47117f8fe6 100755 --- a/t/t5510-fetch.sh +++ b/t/t5510-fetch.sh @@ -510,7 +510,7 @@ test_expect_success 'fetch --atomic aborts all reference updates if hook aborts' EOF rm -f atomic/actual && - test_hook -C atomic/.git reference-transaction <<-\EOF && + test_hook --git-dir atomic/.git reference-transaction <<-\EOF && ( echo "$*" && cat ) >>actual exit 1 EOF diff --git a/t/t5547-push-quarantine.sh b/t/t5547-push-quarantine.sh index 0798ddab02bc8b..7133debc12ce1b 100755 --- a/t/t5547-push-quarantine.sh +++ b/t/t5547-push-quarantine.sh @@ -61,13 +61,13 @@ test_expect_success 'push to repo path with path separator (colon)' ' test_expect_success 'updating a ref from quarantine is forbidden' ' git init --bare update.git && - test_hook -C update.git pre-receive <<-\EOF && + test_hook --git-dir update.git pre-receive <<-\EOF && read old new refname git update-ref refs/heads/unrelated $new exit 1 EOF test_must_fail git push update.git HEAD && - git -C update.git fsck + git --git-dir=update.git fsck ' test_done From e334bff9a73cbd453612a1ad8665fe17e66fc4c0 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 27 Mar 2026 17:44:48 +0100 Subject: [PATCH 03/11] tests: use `test-tool --git-dir` for bare repositories Even if the Git community ultimately decides not to change the default of `safe.bareRepository`, it is good test hygiene to have a test suite that would survive such a change unscathed. A preceding commit taught `test-tool` a `--git-dir` option (mirroring what `git` itself does: setting `GIT_DIR` in the environment). This commit puts it to use. Replace `test-tool -C ` invocations with `test-tool --git-dir=` so that bare repositories are accessed explicitly rather than through implicit discovery. In t1460-refs-migrate.sh, this simplifies the `print_all_reflog_entries` helper considerably: the previous version needed an if/else branch to dispatch between `-C` and a `GIT_DIR=` prefix, whereas now both `test-tool` and `git` accept the same `--git-dir` flag and the helper can pass `$repo_flag` through uniformly. Some diff hunks also contain adjacent `git -C` to `git --git-dir` conversions that share the same hunk as the `test-tool` change. This commit was produced with the help of Claude Opus 4.6 acting as a sophisticated keyboard. It was told to replace `test-tool -C ` with `test-tool --git-dir=` and to simplify the surrounding control flow where the new flag made branching unnecessary. Assisted-by: Claude Opus 4.6 Signed-off-by: Johannes Schindelin --- t/t1460-refs-migrate.sh | 16 ++++++++++++---- t/t3800-mktag.sh | 20 ++++++++++---------- t/t7700-repack.sh | 42 ++++++++++++++++++++--------------------- 3 files changed, 43 insertions(+), 35 deletions(-) diff --git a/t/t1460-refs-migrate.sh b/t/t1460-refs-migrate.sh index 52464680243753..39ddf4d4e58568 100755 --- a/t/t1460-refs-migrate.sh +++ b/t/t1460-refs-migrate.sh @@ -8,24 +8,32 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME . ./test-lib.sh print_all_reflog_entries () { - repo=$1 && - test-tool -C "$repo" ref-store main for-each-reflog >reflogs && + repo_flag=$1 && + repo=$2 && + test-tool "$repo_flag" "$repo" ref-store main for-each-reflog >reflogs && while read reflog do echo "REFLOG: $reflog" && - test-tool -C "$repo" ref-store main for-each-reflog-ent "$reflog" || + test-tool "$repo_flag" "$repo" ref-store main for-each-reflog-ent "$reflog" || return 1 done [ []] +# Usage: test_migration [--git-dir] [ []] +# --git-dir: treat as a git directory (for bare repositories). # is the relative path to the repo to be migrated. # is the ref format to be migrated to. # (default: false) whether to skip reflog verification. # are other options be passed directly to 'git refs migrate'. test_migration () { + repo_flag=-C && + if test "$1" = "--git-dir" + then + repo_flag=--git-dir && + shift + fi && repo=$1 && format=$2 && shift 2 && diff --git a/t/t3800-mktag.sh b/t/t3800-mktag.sh index e3cf0ffbe59c44..31633e5d39bff2 100755 --- a/t/t3800-mktag.sh +++ b/t/t3800-mktag.sh @@ -68,38 +68,38 @@ check_verify_failure () { # The update-ref of the bad content will fail, do it # anyway to see if it segfaults - test_might_fail git -C bad-tag update-ref "$tag_ref" "$bad_tag" && + test_might_fail git --git-dir=bad-tag update-ref "$tag_ref" "$bad_tag" && # Manually create the broken, we cannot do it with # update-ref - test-tool -C bad-tag ref-store main delete-refs 0 msg "$tag_ref" && - test-tool -C bad-tag ref-store main update-ref msg "$tag_ref" $bad_tag $ZERO_OID REF_SKIP_OID_VERIFICATION && + test-tool --git-dir=bad-tag ref-store main delete-refs 0 msg "$tag_ref" && + test-tool --git-dir=bad-tag ref-store main update-ref msg "$tag_ref" $bad_tag $ZERO_OID REF_SKIP_OID_VERIFICATION && # Unlike fsck-ing unreachable content above, this # will always fail. - test_must_fail git -C bad-tag fsck + test_must_fail git --git-dir=bad-tag fsck ' test_expect_success "for-each-ref: $subject" ' # Make sure the earlier test created it for us git rev-parse "$bad_tag" && - test-tool -C bad-tag ref-store main delete-refs 0 msg "$tag_ref" && - test-tool -C bad-tag ref-store main update-ref msg "$tag_ref" $bad_tag $ZERO_OID REF_SKIP_OID_VERIFICATION && + test-tool --git-dir=bad-tag ref-store main delete-refs 0 msg "$tag_ref" && + test-tool --git-dir=bad-tag ref-store main update-ref msg "$tag_ref" $bad_tag $ZERO_OID REF_SKIP_OID_VERIFICATION && printf "%s tag\t%s\n" "$bad_tag" "$tag_ref" >expected && - git -C bad-tag for-each-ref "$tag_ref" >actual && + git --git-dir=bad-tag for-each-ref "$tag_ref" >actual && test_cmp expected actual && - test_must_fail git -C bad-tag for-each-ref --format="%(*objectname)" + test_must_fail git --git-dir=bad-tag for-each-ref --format="%(*objectname)" ' test_expect_success "fast-export & fast-import: $subject" ' # Make sure the earlier test created it for us git rev-parse "$bad_tag" && - test_must_fail git -C bad-tag fast-export --all && - test_must_fail git -C bad-tag fast-export "$bad_tag" + test_must_fail git --git-dir=bad-tag fast-export --all && + test_must_fail git --git-dir=bad-tag fast-export "$bad_tag" ' } diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index 63ef63fc509a1d..58f43d9cf8c866 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -313,42 +313,42 @@ test_expect_success 'no bitmaps created if .keep files present' ' # Disable --name-hash-version test due to stderr comparison. GIT_TEST_NAME_HASH_VERSION=1 \ - git -C bare.git repack -ad 2>stderr && + git --git-dir=bare.git repack -ad 2>stderr && test_must_be_empty stderr && find bare.git/objects/pack/ -type f -name "*.bitmap" >actual && test_must_be_empty actual ' test_expect_success 'auto-bitmaps do not complain if unavailable' ' - test_config -C bare.git pack.packSizeLimit 1M && + test_config --git-dir bare.git pack.packSizeLimit 1M && blob=$(test-tool genrandom big 1m | - git -C bare.git hash-object -w --stdin) && - git -C bare.git update-ref refs/tags/big $blob && + git --git-dir=bare.git hash-object -w --stdin) && + git --git-dir=bare.git update-ref refs/tags/big $blob && # Disable --name-hash-version test due to stderr comparison. GIT_TEST_NAME_HASH_VERSION=1 \ - git -C bare.git repack -ad 2>stderr && + git --git-dir=bare.git repack -ad 2>stderr && test_must_be_empty stderr && find bare.git/objects/pack -type f -name "*.bitmap" >actual && test_must_be_empty actual ' test_expect_success 'repacking with a filter works' ' - git -C bare.git repack -a -d && + git --git-dir=bare.git repack -a -d && test_stdout_line_count = 1 ls bare.git/objects/pack/*.pack && - git -C bare.git -c repack.writebitmaps=false repack -a -d --filter=blob:none && + git --git-dir=bare.git -c repack.writebitmaps=false repack -a -d --filter=blob:none && test_stdout_line_count = 2 ls bare.git/objects/pack/*.pack && - commit_pack=$(test-tool -C bare.git find-pack -c 1 HEAD) && - blob_pack=$(test-tool -C bare.git find-pack -c 1 HEAD:file1) && + commit_pack=$(test-tool --git-dir=bare.git find-pack -c 1 HEAD) && + blob_pack=$(test-tool --git-dir=bare.git find-pack -c 1 HEAD:file1) && test "$commit_pack" != "$blob_pack" && - tree_pack=$(test-tool -C bare.git find-pack -c 1 HEAD^{tree}) && + tree_pack=$(test-tool --git-dir=bare.git find-pack -c 1 HEAD^{tree}) && test "$tree_pack" = "$commit_pack" && - blob_pack2=$(test-tool -C bare.git find-pack -c 1 HEAD:file2) && + blob_pack2=$(test-tool --git-dir=bare.git find-pack -c 1 HEAD:file2) && test "$blob_pack2" = "$blob_pack" ' test_expect_success '--filter fails with --write-bitmap-index' ' - test_must_fail git -C bare.git repack -a -d --write-bitmap-index --filter=blob:none + test_must_fail git --git-dir=bare.git repack -a -d --write-bitmap-index --filter=blob:none ' test_expect_success 'repacking with two filters works' ' @@ -467,25 +467,25 @@ test_expect_success '--filter works with --pack-kept-objects and .keep packs' ' ' test_expect_success '--filter-to stores filtered out objects' ' - git -C bare.git repack -a -d && + git --git-dir=bare.git repack -a -d && test_stdout_line_count = 1 ls bare.git/objects/pack/*.pack && git init --bare filtered.git && - git -C bare.git -c repack.writebitmaps=false repack -a -d \ + git --git-dir=bare.git -c repack.writebitmaps=false repack -a -d \ --filter=blob:none \ - --filter-to=../filtered.git/objects/pack/pack && + --filter-to=filtered.git/objects/pack/pack && test_stdout_line_count = 1 ls bare.git/objects/pack/pack-*.pack && test_stdout_line_count = 1 ls filtered.git/objects/pack/pack-*.pack && - commit_pack=$(test-tool -C bare.git find-pack -c 1 HEAD) && - blob_pack=$(test-tool -C bare.git find-pack -c 0 HEAD:file1) && - blob_hash=$(git -C bare.git rev-parse HEAD:file1) && + commit_pack=$(test-tool --git-dir=bare.git find-pack -c 1 HEAD) && + blob_pack=$(test-tool --git-dir=bare.git find-pack -c 0 HEAD:file1) && + blob_hash=$(git --git-dir=bare.git rev-parse HEAD:file1) && test -n "$blob_hash" && - blob_pack=$(test-tool -C filtered.git find-pack -c 1 $blob_hash) && + blob_pack=$(test-tool --git-dir=filtered.git find-pack -c 1 $blob_hash) && echo $(pwd)/filtered.git/objects >bare.git/objects/info/alternates && - blob_pack=$(test-tool -C bare.git find-pack -c 1 HEAD:file1) && - blob_content=$(git -C bare.git show $blob_hash) && + blob_pack=$(test-tool --git-dir=bare.git find-pack -c 1 HEAD:file1) && + blob_content=$(git --git-dir=bare.git show $blob_hash) && test "$blob_content" = "content1" ' From 33d3a6176205445ca5b093dbfb8568004c346a92 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 27 Mar 2026 17:44:48 +0100 Subject: [PATCH 04/11] tests: use `test_config --git-dir` for bare repositories If the `safe.bareRepository` default were to change to `explicit` one day (as is being discussed for Git v3.0), the test suite must not silently break in places that configure bare repositories via `test_config -C `. The `-C` flag triggers implicit discovery which would then be rejected. A preceding commit taught `test_config` and `test_unconfig` a `--git-dir` option so that bare repository configuration can be set and cleaned up with the same familiar one-liner used everywhere else. This commit converts all call sites. Replace `test_config -C ` with `test_config --git-dir `. The cleanup registered via `test_when_finished` now runs `test_unconfig --git-dir`, which correctly uses `--unset-all` and handles exit code 5 (nothing to unset), matching the robust behavior that `test_unconfig` has always provided. Some diff hunks also contain adjacent `git -C` to `git --git-dir` conversions for commands that appear in the same test and therefore the same hunk as the `test_config` change. This commit was produced with the help of Claude Opus 4.6 acting as a sophisticated keyboard. It was told to replace `test_config -C` with `test_config --git-dir` across bare-repository test sites, and to convert any hand-rolled `test_when_finished` + `git config --unset` pairs back into the `test_config` abstraction. The dominant pattern can be verified: git show HEAD | sed 's/test_config --git-dir/test_config -C/g' | sed -ne '/^diff/,/@@/d' -e 's/^[-+]//p' | uniq -u Residual output consists of adjacent `git -C` to `--git-dir` conversions and, in t1400, a restructured `test_when_finished` that splits config cleanup from reflog deletion. Assisted-by: Claude Opus 4.6 Signed-off-by: Johannes Schindelin --- t/t1400-update-ref.sh | 21 ++++++----- t/t5410-receive-pack.sh | 4 +-- t/t5509-fetch-push-namespaces.sh | 16 ++++----- t/t5606-clone-options.sh | 4 +-- t/t5616-partial-clone.sh | 20 +++++------ t/t5620-backfill.sh | 4 +-- t/t5710-promisor-remote-capability.sh | 52 +++++++++++++-------------- 7 files changed, 60 insertions(+), 61 deletions(-) diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh index b2858a9061a23d..3f2b07a7653cde 100755 --- a/t/t1400-update-ref.sh +++ b/t/t1400-update-ref.sh @@ -124,22 +124,21 @@ test_expect_success 'update-ref creates reflogs with --create-reflog' ' ' test_expect_success 'creates no reflog in bare repository' ' - git -C $bare update-ref $m $bareA && - git -C $bare rev-parse $bareA >expect && - git -C $bare rev-parse $m >actual && + git --git-dir=$bare update-ref $m $bareA && + git --git-dir=$bare rev-parse $bareA >expect && + git --git-dir=$bare rev-parse $m >actual && test_cmp expect actual && - test_must_fail git -C $bare reflog exists $m + test_must_fail git --git-dir=$bare reflog exists $m ' test_expect_success 'core.logAllRefUpdates=true creates reflog in bare repository' ' - test_when_finished "git -C $bare config --unset core.logAllRefUpdates && \ - test-tool ref-store main delete-reflog $m" && - git -C $bare config core.logAllRefUpdates true && - git -C $bare update-ref $m $bareB && - git -C $bare rev-parse $bareB >expect && - git -C $bare rev-parse $m >actual && + test_when_finished "test-tool ref-store main delete-reflog $m" && + test_config --git-dir $bare core.logAllRefUpdates true && + git --git-dir=$bare update-ref $m $bareB && + git --git-dir=$bare rev-parse $bareB >expect && + git --git-dir=$bare rev-parse $m >actual && test_cmp expect actual && - git -C $bare reflog exists $m + git --git-dir=$bare reflog exists $m ' test_expect_success 'core.logAllRefUpdates=true does not create reflog by default' ' diff --git a/t/t5410-receive-pack.sh b/t/t5410-receive-pack.sh index 09d6bfd2a10f5a..aa0b32007dacfc 100755 --- a/t/t5410-receive-pack.sh +++ b/t/t5410-receive-pack.sh @@ -26,7 +26,7 @@ test_expect_success 'with core.alternateRefsCommand' ' --format="%(objectname)" \ refs/heads/public/ EOF - test_config -C fork core.alternateRefsCommand ./alternate-refs && + test_config --git-dir fork core.alternateRefsCommand ./alternate-refs && git rev-parse public/branch >expect && printf "0000" | git receive-pack fork >actual && extract_haves actual.haves && @@ -34,7 +34,7 @@ test_expect_success 'with core.alternateRefsCommand' ' ' test_expect_success 'with core.alternateRefsPrefixes' ' - test_config -C fork core.alternateRefsPrefixes "refs/heads/private" && + test_config --git-dir fork core.alternateRefsPrefixes "refs/heads/private" && git rev-parse private/branch >expect && printf "0000" | git receive-pack fork >actual && extract_haves actual.haves && diff --git a/t/t5509-fetch-push-namespaces.sh b/t/t5509-fetch-push-namespaces.sh index 095df1a7535d57..6b623cfde16a1b 100755 --- a/t/t5509-fetch-push-namespaces.sh +++ b/t/t5509-fetch-push-namespaces.sh @@ -107,32 +107,32 @@ test_expect_success 'check that transfer.hideRefs does not match unstripped refs test_expect_success 'hide full refs with transfer.hideRefs' ' GIT_NAMESPACE=namespace \ - git -C pushee -c transfer.hideRefs="^refs/namespaces/namespace/refs/tags" \ - ls-remote "ext::git %s ." >actual && + git --git-dir=pushee -c transfer.hideRefs="^refs/namespaces/namespace/refs/tags" \ + ls-remote "ext::git %s pushee" >actual && printf "$commit1\trefs/heads/main\n" >expected && test_cmp expected actual ' test_expect_success 'try to update a hidden ref' ' - test_config -C pushee transfer.hideRefs refs/heads/main && + test_config --git-dir pushee transfer.hideRefs refs/heads/main && test_must_fail git -C original push pushee-namespaced main ' test_expect_success 'try to update a ref that is not hidden' ' - test_config -C pushee transfer.hideRefs refs/namespaces/namespace/refs/heads/main && + test_config --git-dir pushee transfer.hideRefs refs/namespaces/namespace/refs/heads/main && git -C original push pushee-namespaced main ' test_expect_success 'git-receive-pack(1) with transfer.hideRefs does not match unstripped refs during advertisement' ' - git -C pushee update-ref refs/namespaces/namespace/refs/heads/foo/1 refs/namespaces/namespace/refs/heads/main && - git -C pushee pack-refs --all && - test_config -C pushee transfer.hideRefs refs/namespaces/namespace/refs/heads/foo && + git --git-dir=pushee update-ref refs/namespaces/namespace/refs/heads/foo/1 refs/namespaces/namespace/refs/heads/main && + git --git-dir=pushee pack-refs --all && + test_config --git-dir pushee transfer.hideRefs refs/namespaces/namespace/refs/heads/foo && GIT_TRACE_PACKET="$(pwd)/trace" git -C original push pushee-namespaced main && test_grep refs/heads/foo/1 trace ' test_expect_success 'try to update a hidden full ref' ' - test_config -C pushee transfer.hideRefs "^refs/namespaces/namespace/refs/heads/main" && + test_config --git-dir pushee transfer.hideRefs "^refs/namespaces/namespace/refs/heads/main" && test_must_fail git -C original push pushee-namespaced main ' diff --git a/t/t5606-clone-options.sh b/t/t5606-clone-options.sh index 8a1523773684bc..96e416642e0d4c 100755 --- a/t/t5606-clone-options.sh +++ b/t/t5606-clone-options.sh @@ -164,14 +164,14 @@ test_expect_success 'clone does not segfault with --bare and core.bare=false' ' test_config_global core.bare false && git clone --bare parent clone-bare && echo true >expect && - git -C clone-bare rev-parse --is-bare-repository >actual && + git --git-dir=clone-bare rev-parse --is-bare-repository >actual && test_cmp expect actual ' test_expect_success 'chooses correct default initial branch name' ' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \ git -c init.defaultBranch=foo init --bare empty && - test_config -C empty lsrefs.unborn advertise && + test_config --git-dir empty lsrefs.unborn advertise && GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \ git -c init.defaultBranch=up -c protocol.version=2 clone empty whats-up && test refs/heads/foo = $(git -C whats-up symbolic-ref HEAD) && diff --git a/t/t5616-partial-clone.sh b/t/t5616-partial-clone.sh index 1c2805accac636..35fa36ef9b3541 100755 --- a/t/t5616-partial-clone.sh +++ b/t/t5616-partial-clone.sh @@ -357,40 +357,40 @@ test_expect_success 'upload-pack complains of bogus filter config' ' ' test_expect_success 'upload-pack fails banned object filters' ' - test_config -C srv.bare uploadpackfilter.blob:none.allow false && + test_config --git-dir srv.bare uploadpackfilter.blob:none.allow false && test_must_fail ok=sigpipe git clone --no-checkout --filter=blob:none \ "file://$(pwd)/srv.bare" pc3 2>err && test_grep "filter '\''blob:none'\'' not supported" err ' test_expect_success 'upload-pack fails banned combine object filters' ' - test_config -C srv.bare uploadpackfilter.allow false && - test_config -C srv.bare uploadpackfilter.combine.allow true && - test_config -C srv.bare uploadpackfilter.tree.allow true && - test_config -C srv.bare uploadpackfilter.blob:none.allow false && + test_config --git-dir srv.bare uploadpackfilter.allow false && + test_config --git-dir srv.bare uploadpackfilter.combine.allow true && + test_config --git-dir srv.bare uploadpackfilter.tree.allow true && + test_config --git-dir srv.bare uploadpackfilter.blob:none.allow false && test_must_fail ok=sigpipe git clone --no-checkout --filter=tree:1 \ --filter=blob:none "file://$(pwd)/srv.bare" pc3 2>err && test_grep "filter '\''blob:none'\'' not supported" err ' test_expect_success 'upload-pack fails banned object filters with fallback' ' - test_config -C srv.bare uploadpackfilter.allow false && + test_config --git-dir srv.bare uploadpackfilter.allow false && test_must_fail ok=sigpipe git clone --no-checkout --filter=blob:none \ "file://$(pwd)/srv.bare" pc3 2>err && test_grep "filter '\''blob:none'\'' not supported" err ' test_expect_success 'upload-pack limits tree depth filters' ' - test_config -C srv.bare uploadpackfilter.allow false && - test_config -C srv.bare uploadpackfilter.tree.allow true && - test_config -C srv.bare uploadpackfilter.tree.maxDepth 0 && + test_config --git-dir srv.bare uploadpackfilter.allow false && + test_config --git-dir srv.bare uploadpackfilter.tree.allow true && + test_config --git-dir srv.bare uploadpackfilter.tree.maxDepth 0 && test_must_fail ok=sigpipe git clone --no-checkout --filter=tree:1 \ "file://$(pwd)/srv.bare" pc3 2>err && test_grep "tree filter allows max depth 0, but got 1" err && git clone --no-checkout --filter=tree:0 "file://$(pwd)/srv.bare" pc4 && - test_config -C srv.bare uploadpackfilter.tree.maxDepth 5 && + git --git-dir=srv.bare config uploadpackfilter.tree.maxDepth 5 && git clone --no-checkout --filter=tree:5 "file://$(pwd)/srv.bare" pc5 && test_must_fail ok=sigpipe git clone --no-checkout --filter=tree:6 \ "file://$(pwd)/srv.bare" pc6 2>err && diff --git a/t/t5620-backfill.sh b/t/t5620-backfill.sh index 58c81556e72c89..8dc4570f7fdb43 100755 --- a/t/t5620-backfill.sh +++ b/t/t5620-backfill.sh @@ -183,8 +183,8 @@ test_expect_success 'create a partial clone over HTTP' ' SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server" && rm -rf "$SERVER" repo && git clone --bare "file://$(pwd)/src" "$SERVER" && - test_config -C "$SERVER" uploadpack.allowfilter 1 && - test_config -C "$SERVER" uploadpack.allowanysha1inwant 1 && + test_config --git-dir "$SERVER" uploadpack.allowfilter 1 && + test_config --git-dir "$SERVER" uploadpack.allowanysha1inwant 1 && git clone --no-checkout --filter=blob:none \ "$HTTPD_URL/smart/server" backfill-http diff --git a/t/t5710-promisor-remote-capability.sh b/t/t5710-promisor-remote-capability.sh index 357822c01a7530..af9f8304a353ef 100755 --- a/t/t5710-promisor-remote-capability.sh +++ b/t/t5710-promisor-remote-capability.sh @@ -296,15 +296,15 @@ test_expect_success "clone with 'KnownUrl' and empty url, so not advertised" ' ' test_expect_success "clone with promisor.sendFields" ' - git -C server config promisor.advertise true && + git --git-dir=server config promisor.advertise true && test_when_finished "rm -rf client" && - git -C server remote add otherLop "https://invalid.invalid" && - git -C server config remote.otherLop.token "fooBar" && - git -C server config remote.otherLop.stuff "baz" && - git -C server config remote.otherLop.partialCloneFilter "blob:limit=10k" && - test_when_finished "git -C server remote remove otherLop" && - test_config -C server promisor.sendFields "partialCloneFilter, token" && + git --git-dir=server remote add otherLop "https://invalid.invalid" && + git --git-dir=server config remote.otherLop.token "fooBar" && + git --git-dir=server config remote.otherLop.stuff "baz" && + git --git-dir=server config remote.otherLop.partialCloneFilter "blob:limit=10k" && + test_when_finished "git --git-dir=server remote remove otherLop" && + test_config --git-dir server promisor.sendFields "partialCloneFilter, token" && test_when_finished "rm trace" && # Clone from server to create a client @@ -327,15 +327,15 @@ test_expect_success "clone with promisor.sendFields" ' ' test_expect_success "clone with promisor.checkFields" ' - git -C server config promisor.advertise true && + git --git-dir=server config promisor.advertise true && test_when_finished "rm -rf client" && - git -C server remote add otherLop "https://invalid.invalid" && - git -C server config remote.otherLop.token "fooBar" && - git -C server config remote.otherLop.stuff "baz" && - git -C server config remote.otherLop.partialCloneFilter "blob:limit=10k" && - test_when_finished "git -C server remote remove otherLop" && - test_config -C server promisor.sendFields "partialCloneFilter, token" && + git --git-dir=server remote add otherLop "https://invalid.invalid" && + git --git-dir=server config remote.otherLop.token "fooBar" && + git --git-dir=server config remote.otherLop.stuff "baz" && + git --git-dir=server config remote.otherLop.partialCloneFilter "blob:limit=10k" && + test_when_finished "git --git-dir=server remote remove otherLop" && + test_config --git-dir server promisor.sendFields "partialCloneFilter, token" && test_when_finished "rm trace" && # Clone from server to create a client @@ -361,19 +361,19 @@ test_expect_success "clone with promisor.checkFields" ' ' test_expect_success "clone with promisor.storeFields=partialCloneFilter" ' - git -C server config promisor.advertise true && + git --git-dir=server config promisor.advertise true && test_when_finished "rm -rf client" && - git -C server remote add otherLop "https://invalid.invalid" && - git -C server config remote.otherLop.token "fooBar" && - git -C server config remote.otherLop.stuff "baz" && - git -C server config remote.otherLop.partialCloneFilter "blob:limit=10k" && - test_when_finished "git -C server remote remove otherLop" && + git --git-dir=server remote add otherLop "https://invalid.invalid" && + git --git-dir=server config remote.otherLop.token "fooBar" && + git --git-dir=server config remote.otherLop.stuff "baz" && + git --git-dir=server config remote.otherLop.partialCloneFilter "blob:limit=10k" && + test_when_finished "git --git-dir=server remote remove otherLop" && - git -C server config remote.lop.token "fooXXX" && - git -C server config remote.lop.partialCloneFilter "blob:limit=8k" && + git --git-dir=server config remote.lop.token "fooXXX" && + git --git-dir=server config remote.lop.partialCloneFilter "blob:limit=8k" && - test_config -C server promisor.sendFields "partialCloneFilter, token" && + test_config --git-dir server promisor.sendFields "partialCloneFilter, token" && test_when_finished "rm trace" && # Clone from server to create a client @@ -424,11 +424,11 @@ test_expect_success "clone with promisor.storeFields=partialCloneFilter" ' ' test_expect_success "clone and fetch with --filter=auto" ' - git -C server config promisor.advertise true && + git --git-dir=server config promisor.advertise true && test_when_finished "rm -rf client trace" && - git -C server config remote.lop.partialCloneFilter "blob:limit=9500" && - test_config -C server promisor.sendFields "partialCloneFilter" && + git --git-dir=server config remote.lop.partialCloneFilter "blob:limit=9500" && + test_config --git-dir server promisor.sendFields "partialCloneFilter" && GIT_TRACE_PACKET="$(pwd)/trace" GIT_NO_LAZY_FETCH=0 git clone \ -c remote.lop.promisor=true \ From c6342d2a4cc0afb44c79b0755e2cb387d8bfbf84 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 27 Mar 2026 17:44:49 +0100 Subject: [PATCH 05/11] tests: use `git --git-dir=` to access bare repositories When a test invokes `git -C `, Git enters the directory and discovers the bare repository implicitly. If `safe.bareRepository` is set to `explicit`, this implicit discovery is refused and the test fails. Regardless of whether the default changes in Git v3.0 or later, it is the right thing to harden Git's own test suite so that it would still pass under the stricter setting: the tests should demonstrate the recommended practice, not rely on the lenient default. Replace `git -C ` with `git --git-dir=` throughout the test suite wherever the target is a bare repository. The `--git-dir` flag tells Git exactly where the repository is, bypassing the discovery mechanism entirely. A handful of hunks additionally collapse subshells that used `cd && git ...` into a single `git --git-dir= ...` invocation, and several shared test helpers (lib-commit-graph.sh, lib-diff-alternative.sh, lib-proto-disable.sh, t5411/common-functions.sh) gain `--bare` or `--git-dir` parameters to pass through to `git` internally. Note that `--git-dir` does not change the working directory the way `-C` does: relative paths in arguments are resolved from the original directory, not from inside the repository. In this commit, no path adjustments were necessary (those are handled in a separate commit). This commit was produced with the help of Claude Opus 4.6 acting as a sophisticated keyboard. It was told to replace every `git -C ` with `git --git-dir=` where the target is known to be a bare repository, and to adjust helper functions in shared test libraries accordingly. Assisted-by: Claude Opus 4.6 Signed-off-by: Johannes Schindelin --- t/lib-commit-graph.sh | 28 +++++-- t/lib-diff-alternative.sh | 4 +- t/lib-proto-disable.sh | 16 ++-- t/t0001-init.sh | 4 +- t/t0003-attributes.sh | 70 +++++++---------- t/t0056-git-C.sh | 6 +- t/t0410-partial-clone.sh | 18 ++--- t/t0600-reffiles-backend.sh | 8 +- t/t1020-subdirectory.sh | 5 +- t/t1022-read-tree-partial-clone.sh | 2 +- t/t1050-large.sh | 4 +- t/t1091-sparse-checkout-builtin.sh | 12 +-- t/t1305-config-include.sh | 4 +- t/t1460-refs-migrate.sh | 14 ++-- t/t1512-rev-parse-disambiguation.sh | 4 +- t/t1900-repo-info.sh | 7 +- t/t2400-worktree-add.sh | 2 +- t/t2402-worktree-list.sh | 2 +- t/t3650-replay-basics.sh | 24 +++--- t/t3800-mktag.sh | 6 +- t/t4018-diff-funcname.sh | 4 +- t/t4067-diff-partial-clone.sh | 16 ++-- t/t5003-archive-zip.sh | 2 +- t/t5300-pack-object.sh | 6 +- t/t5310-pack-bitmaps.sh | 2 +- t/t5318-commit-graph.sh | 12 +-- t/t5351-unpack-large-objects.sh | 16 ++-- t/t5400-send-pack.sh | 2 +- t/t5401-update-hooks.sh | 10 +-- t/t5410-receive-pack.sh | 6 +- t/t5411-proc-receive-hook.sh | 8 +- t/t5411/common-functions.sh | 9 ++- t/t5411/once-0010-report-status-v1.sh | 4 +- t/t5411/test-0000-standard-git-push.sh | 8 +- .../test-0001-standard-git-push--porcelain.sh | 8 +- t/t5411/test-0002-pre-receive-declined.sh | 2 +- ...st-0003-pre-receive-declined--porcelain.sh | 2 +- t/t5411/test-0011-no-hook-error.sh | 6 +- t/t5411/test-0012-no-hook-error--porcelain.sh | 6 +- t/t5411/test-0013-bad-protocol.sh | 6 +- t/t5411/test-0014-bad-protocol--porcelain.sh | 6 +- t/t5411/test-0020-report-ng.sh | 2 +- t/t5411/test-0021-report-ng--porcelain.sh | 2 +- t/t5411/test-0022-report-unexpect-ref.sh | 4 +- ...est-0023-report-unexpect-ref--porcelain.sh | 4 +- t/t5411/test-0024-report-unknown-ref.sh | 2 +- ...test-0025-report-unknown-ref--porcelain.sh | 2 +- t/t5411/test-0026-push-options.sh | 6 +- t/t5411/test-0027-push-options--porcelain.sh | 6 +- t/t5411/test-0030-report-ok.sh | 2 +- t/t5411/test-0031-report-ok--porcelain.sh | 2 +- t/t5411/test-0032-report-with-options.sh | 2 +- ...est-0033-report-with-options--porcelain.sh | 2 +- t/t5411/test-0034-report-ft.sh | 4 +- t/t5411/test-0035-report-ft--porcelain.sh | 4 +- ...t-0036-report-multi-rewrite-for-one-ref.sh | 6 +- ...rt-multi-rewrite-for-one-ref--porcelain.sh | 2 +- t/t5411/test-0038-report-mixed-refs.sh | 2 +- .../test-0039-report-mixed-refs--porcelain.sh | 2 +- t/t5411/test-0040-process-all-refs.sh | 2 +- .../test-0041-process-all-refs--porcelain.sh | 2 +- ...t-0050-proc-receive-refs-with-modifiers.sh | 10 +-- t/t5500-fetch-pack.sh | 4 +- t/t5505-remote.sh | 12 +-- t/t5510-fetch.sh | 20 ++--- t/t5516-fetch-push.sh | 18 ++--- t/t5531-deep-submodule-push.sh | 26 +++---- t/t5544-pack-objects-hook.sh | 4 +- t/t5545-push-options.sh | 4 +- t/t5546-receive-limits.sh | 2 +- t/t5547-push-quarantine.sh | 2 +- t/t5548-push-porcelain.sh | 24 +++--- t/t5570-git-daemon.sh | 2 +- t/t5583-push-branches.sh | 12 +-- t/t5601-clone.sh | 22 +++--- t/t5605-clone-local.sh | 6 +- t/t5606-clone-options.sh | 4 +- t/t5613-info-alternate.sh | 4 +- t/t5615-alternate-env.sh | 4 +- t/t5616-partial-clone.sh | 30 +++---- t/t5617-clone-submodules-remote.sh | 4 +- t/t5619-clone-local-ambiguous-transport.sh | 12 +-- t/t5620-backfill.sh | 4 +- t/t5621-clone-revision.sh | 6 +- t/t5702-protocol-v2.sh | 4 +- t/t5710-promisor-remote-capability.sh | 78 +++++++++---------- t/t5811-proto-disable-git.sh | 2 +- t/t5812-proto-disable-http.sh | 2 +- t/t6020-bundle-misc.sh | 4 +- t/t6500-gc.sh | 4 +- t/t7416-submodule-dash-url.sh | 24 +++--- t/t7417-submodule-path-url.sh | 2 +- t/t7450-bad-git-dotfiles.sh | 12 +-- t/t7519-status-fsmonitor.sh | 6 +- t/t7700-repack.sh | 6 +- 95 files changed, 415 insertions(+), 406 deletions(-) diff --git a/t/lib-commit-graph.sh b/t/lib-commit-graph.sh index 89b26676fbb94b..905a1702479523 100755 --- a/t/lib-commit-graph.sh +++ b/t/lib-commit-graph.sh @@ -22,16 +22,28 @@ graph_git_two_modes() { # NOTE: it is a bug to call this function with containing # any characters in $IFS. graph_git_behavior() { + BARE= + if test "$1" = "--bare" + then + BARE=t + shift + fi MSG=$1 DIR=$2 BRANCH=$3 COMPARE=$4 test_expect_success "check normal git operations: $MSG" ' - graph_git_two_modes "${DIR:+-C $DIR} log --oneline $BRANCH" && - graph_git_two_modes "${DIR:+-C $DIR} log --topo-order $BRANCH" && - graph_git_two_modes "${DIR:+-C $DIR} log --graph $COMPARE..$BRANCH" && - graph_git_two_modes "${DIR:+-C $DIR} branch -vv" && - graph_git_two_modes "${DIR:+-C $DIR} merge-base -a $BRANCH $COMPARE" + if test -n "$BARE" + then + DIR_ARGS="${DIR:+--git-dir=$DIR}" + else + DIR_ARGS="${DIR:+-C $DIR}" + fi && + graph_git_two_modes "$DIR_ARGS log --oneline $BRANCH" && + graph_git_two_modes "$DIR_ARGS log --topo-order $BRANCH" && + graph_git_two_modes "$DIR_ARGS log --graph $COMPARE..$BRANCH" && + graph_git_two_modes "$DIR_ARGS branch -vv" && + graph_git_two_modes "$DIR_ARGS merge-base -a $BRANCH $COMPARE" ' } @@ -39,6 +51,12 @@ graph_read_expect() { OPTIONAL="" NUM_CHUNKS=3 DIR="." + BARE= + if test "$1" = "--bare" + then + BARE=t + shift + fi if test "$1" = -C then shift diff --git a/t/lib-diff-alternative.sh b/t/lib-diff-alternative.sh index c4dc2d46dc1ef4..093c6bdd6e05ea 100644 --- a/t/lib-diff-alternative.sh +++ b/t/lib-diff-alternative.sh @@ -131,14 +131,14 @@ EOF ' test_expect_success "diff from attributes with bare repo with source" ' - git -C bare.git --attr-source=branchA -c diff.driver.algorithm=myers \ + git --git-dir=bare.git --attr-source=branchA -c diff.driver.algorithm=myers \ -c diff.driverA.algorithm=$STRATEGY \ diff HEAD:file1 HEAD:file2 >output && test_cmp expect output ' test_expect_success "diff from attributes with bare repo with invalid source" ' - test_must_fail git -C bare.git --attr-source=invalid-branch diff \ + test_must_fail git --git-dir=bare.git --attr-source=invalid-branch diff \ HEAD:file1 HEAD:file2 ' diff --git a/t/lib-proto-disable.sh b/t/lib-proto-disable.sh index 890622be81642b..22c3fbfb44105a 100644 --- a/t/lib-proto-disable.sh +++ b/t/lib-proto-disable.sh @@ -83,19 +83,19 @@ test_config () { ' test_expect_success "fetch $desc (enabled)" ' - git -C tmp.git -c protocol.$proto.allow=always fetch + git --git-dir=tmp.git -c protocol.$proto.allow=always fetch ' test_expect_success "push $desc (enabled)" ' - git -C tmp.git -c protocol.$proto.allow=always push origin HEAD:pushed + git --git-dir=tmp.git -c protocol.$proto.allow=always push origin HEAD:pushed ' test_expect_success "push $desc (disabled)" ' - test_must_fail git -C tmp.git -c protocol.$proto.allow=never push origin HEAD:pushed + test_must_fail git --git-dir=tmp.git -c protocol.$proto.allow=never push origin HEAD:pushed ' test_expect_success "fetch $desc (disabled)" ' - test_must_fail git -C tmp.git -c protocol.$proto.allow=never fetch + test_must_fail git --git-dir=tmp.git -c protocol.$proto.allow=never fetch ' test_expect_success "clone $desc (disabled)" ' @@ -153,22 +153,22 @@ test_config () { test_expect_success "fetch $desc (enabled)" ' test_config_global protocol.allow always && - git -C tmp.git fetch + git --git-dir=tmp.git fetch ' test_expect_success "push $desc (enabled)" ' test_config_global protocol.allow always && - git -C tmp.git push origin HEAD:pushed + git --git-dir=tmp.git push origin HEAD:pushed ' test_expect_success "push $desc (disabled)" ' test_config_global protocol.allow never && - test_must_fail git -C tmp.git push origin HEAD:pushed + test_must_fail git --git-dir=tmp.git push origin HEAD:pushed ' test_expect_success "fetch $desc (disabled)" ' test_config_global protocol.allow never && - test_must_fail git -C tmp.git fetch + test_must_fail git --git-dir=tmp.git fetch ' test_expect_success "clone $desc (disabled)" ' diff --git a/t/t0001-init.sh b/t/t0001-init.sh index e4d32bb4d259f6..9701a2bcd37fde 100755 --- a/t/t0001-init.sh +++ b/t/t0001-init.sh @@ -20,8 +20,8 @@ check_config () { return 1 fi - bare=$(cd "$1" && git config --bool core.bare) - worktree=$(cd "$1" && git config core.worktree) || + bare=$(git --git-dir="$1" config --bool core.bare) + worktree=$(git --git-dir="$1" config core.worktree) || worktree=unset test "$bare" = "$2" && test "$worktree" = "$3" || { diff --git a/t/t0003-attributes.sh b/t/t0003-attributes.sh index 582e207aa12eb1..76ae5841e004ec 100755 --- a/t/t0003-attributes.sh +++ b/t/t0003-attributes.sh @@ -346,17 +346,14 @@ test_expect_success 'setup bare' ' test_expect_success 'bare repository: check that .gitattribute is ignored' ' ( - cd bare.git && - ( - echo "f test=f" && - echo "a/i test=a/i" - ) >.gitattributes && - attr_check f unspecified && - attr_check a/f unspecified && - attr_check a/c/f unspecified && - attr_check a/i unspecified && - attr_check subdir/a/i unspecified - ) + echo "f test=f" && + echo "a/i test=a/i" + ) >bare.git/.gitattributes && + attr_check f unspecified --git-dir=bare.git && + attr_check a/f unspecified --git-dir=bare.git && + attr_check a/c/f unspecified --git-dir=bare.git && + attr_check a/i unspecified --git-dir=bare.git && + attr_check subdir/a/i unspecified --git-dir=bare.git ' bad_attr_source_err="fatal: bad --attr-source or GIT_ATTR_SOURCE" @@ -404,11 +401,11 @@ test_expect_success 'bare repo no longer defaults to reading .gitattributes from git clone --bare test bare_with_gitattribute && echo "f/path: test: unspecified" >expect && - git -C bare_with_gitattribute check-attr test -- f/path >actual && + git --git-dir=bare_with_gitattribute check-attr test -- f/path >actual && test_cmp expect actual && echo "f/path: test: val" >expect && - git -C bare_with_gitattribute -c attr.tree=HEAD \ + git --git-dir=bare_with_gitattribute -c attr.tree=HEAD \ check-attr test -- f/path >actual && test_cmp expect actual ' @@ -449,41 +446,32 @@ test_expect_success 'diff without repository with attr source' ' ' test_expect_success 'bare repository: with --source' ' - ( - cd bare.git && - attr_check_source foo/bar/f f tag-1 && - attr_check_source foo/bar/a/i n tag-1 && - attr_check_source foo/bar/f unspecified tag-2 && - attr_check_source foo/bar/a/i m tag-2 && - attr_check_source foo/bar/g g tag-2 && - attr_check_source foo/bar/g unspecified tag-1 - ) + attr_check_source foo/bar/f f tag-1 --git-dir=bare.git && + attr_check_source foo/bar/a/i n tag-1 --git-dir=bare.git && + attr_check_source foo/bar/f unspecified tag-2 --git-dir=bare.git && + attr_check_source foo/bar/a/i m tag-2 --git-dir=bare.git && + attr_check_source foo/bar/g g tag-2 --git-dir=bare.git && + attr_check_source foo/bar/g unspecified tag-1 --git-dir=bare.git ' test_expect_success 'bare repository: check that --cached honors index' ' - ( - cd bare.git && - GIT_INDEX_FILE=../.git/index \ - git check-attr --cached --stdin --all <../stdin-all | - sort >actual && - test_cmp ../specified-all actual - ) + GIT_INDEX_FILE=.git/index \ + git --git-dir=bare.git check-attr --cached --stdin --all actual && + test_cmp specified-all actual ' test_expect_success 'bare repository: test info/attributes' ' + mkdir -p bare.git/info && ( - cd bare.git && - mkdir info && - ( - echo "f test=f" && - echo "a/i test=a/i" - ) >info/attributes && - attr_check f f && - attr_check a/f f && - attr_check a/c/f f && - attr_check a/i a/i && - attr_check subdir/a/i unspecified - ) + echo "f test=f" && + echo "a/i test=a/i" + ) >bare.git/info/attributes && + attr_check f f --git-dir=bare.git && + attr_check a/f f --git-dir=bare.git && + attr_check a/c/f f --git-dir=bare.git && + attr_check a/i a/i --git-dir=bare.git && + attr_check subdir/a/i unspecified --git-dir=bare.git ' test_expect_success 'binary macro expanded by -a' ' diff --git a/t/t0056-git-C.sh b/t/t0056-git-C.sh index 2630e756dab732..ff568ae245e4de 100755 --- a/t/t0056-git-C.sh +++ b/t/t0056-git-C.sh @@ -57,13 +57,13 @@ test_expect_success 'Order should not matter: "--git-dir=a.git -C c" is equivale test_expect_success 'Effect on --work-tree option: "-C c/a.git --work-tree=../a" is equivalent to "--work-tree=c/a --git-dir=c/a.git"' ' rm c/a/a.txt && git --git-dir=c/a.git --work-tree=c/a status >expected && - git -C c/a.git --work-tree=../a status >actual && + git -C c/a.git --git-dir=. --work-tree=../a status >actual && test_cmp expected actual ' test_expect_success 'Order should not matter: "--work-tree=../a -C c/a.git" is equivalent to "-C c/a.git --work-tree=../a"' ' - git -C c/a.git --work-tree=../a status >expected && - git --work-tree=../a -C c/a.git status >actual && + git -C c/a.git --git-dir=. --work-tree=../a status >expected && + git --work-tree=../a -C c/a.git --git-dir=. status >actual && test_cmp expected actual ' diff --git a/t/t0410-partial-clone.sh b/t/t0410-partial-clone.sh index 2a5bdbeeb87f6e..a9d407e804be6d 100755 --- a/t/t0410-partial-clone.sh +++ b/t/t0410-partial-clone.sh @@ -643,10 +643,10 @@ test_expect_success 'exact rename does not need to fetch the blob lazily' ' test_config -C repo uploadpack.allowanysha1inwant 1 && git clone --filter=blob:none --bare "file://$(pwd)/repo" partial.git && - git -C partial.git rev-list --objects --missing=print HEAD >out && + git --git-dir=partial.git rev-list --objects --missing=print HEAD >out && grep "[?]$FILE_HASH" out && - git -C partial.git log --follow -- new-file.txt && - git -C partial.git rev-list --objects --missing=print HEAD >out && + git --git-dir=partial.git log --follow -- new-file.txt && + git --git-dir=partial.git rev-list --objects --missing=print HEAD >out && grep "[?]$FILE_HASH" out ' @@ -661,22 +661,22 @@ test_expect_success 'lazy-fetch when accessing object not in the_repository' ' FILE_HASH=$(git -C full rev-parse HEAD:file.txt) && # Sanity check that the file is missing - git -C partial.git rev-list --objects --missing=print HEAD >out && + git --git-dir=partial.git rev-list --objects --missing=print HEAD >out && grep "[?]$FILE_HASH" out && # The no-lazy-fetch mechanism prevents Git from fetching test_must_fail env GIT_NO_LAZY_FETCH=1 \ - git -C partial.git cat-file -e "$FILE_HASH" && + git --git-dir=partial.git cat-file -e "$FILE_HASH" && # The same with command line option to "git" - test_must_fail git --no-lazy-fetch -C partial.git cat-file -e "$FILE_HASH" && + test_must_fail git --no-lazy-fetch --git-dir=partial.git cat-file -e "$FILE_HASH" && # The same, forcing a subprocess via an alias - test_must_fail git --no-lazy-fetch -C partial.git \ + test_must_fail git --no-lazy-fetch --git-dir=partial.git \ -c alias.foo="!git cat-file" foo -e "$FILE_HASH" && # Sanity check that the file is still missing - git -C partial.git rev-list --objects --missing=print HEAD >out && + git --git-dir=partial.git rev-list --objects --missing=print HEAD >out && grep "[?]$FILE_HASH" out && git -C full cat-file -s "$FILE_HASH" >expect && @@ -684,7 +684,7 @@ test_expect_success 'lazy-fetch when accessing object not in the_repository' ' test_cmp expect actual && # Sanity check that the file is now present - git -C partial.git rev-list --objects --missing=print HEAD >out && + git --git-dir=partial.git rev-list --objects --missing=print HEAD >out && ! grep "[?]$FILE_HASH" out ' diff --git a/t/t0600-reffiles-backend.sh b/t/t0600-reffiles-backend.sh index 74bfa2e9ba060d..ffac768d925074 100755 --- a/t/t0600-reffiles-backend.sh +++ b/t/t0600-reffiles-backend.sh @@ -428,14 +428,14 @@ test_expect_success SYMLINKS 'git branch -m with symlinked .git/refs' ' ln -s ../.git/objects subdir/objects && ln -s ../.git/packed-refs subdir/packed-refs && - git -C subdir rev-parse --absolute-git-dir >subdir.dir && + git --git-dir=subdir rev-parse --absolute-git-dir >subdir.dir && git rev-parse --absolute-git-dir >our.dir && ! test_cmp subdir.dir our.dir && - git -C subdir log && - git -C subdir branch rename-src && + git --git-dir=subdir log && + git --git-dir=subdir branch rename-src && git rev-parse rename-src >expect && - git -C subdir branch -m rename-src rename-dest && + git --git-dir=subdir branch -m rename-src rename-dest && git rev-parse rename-dest >actual && test_cmp expect actual && git branch -D rename-dest diff --git a/t/t1020-subdirectory.sh b/t/t1020-subdirectory.sh index 9fdbb2af80e0a8..20d2d306fecdce 100755 --- a/t/t1020-subdirectory.sh +++ b/t/t1020-subdirectory.sh @@ -177,10 +177,7 @@ test_expect_success 'no file/rev ambiguity check inside a bare repo (explicit GI test_expect_success 'no file/rev ambiguity check inside a bare repo' ' test_when_finished "rm -fr foo.git" && git clone -s --bare .git foo.git && - ( - cd foo.git && - git show -s HEAD - ) + git --git-dir=foo.git show -s HEAD ' test_expect_success SYMLINKS 'detection should not be fooled by a symlink' ' diff --git a/t/t1022-read-tree-partial-clone.sh b/t/t1022-read-tree-partial-clone.sh index d390d7d5f857bb..33b9c29d1d6d65 100755 --- a/t/t1022-read-tree-partial-clone.sh +++ b/t/t1022-read-tree-partial-clone.sh @@ -18,7 +18,7 @@ test_expect_success 'read-tree in partial clone prefetches in one batch' ' git -C server config uploadpack.allowfilter 1 && git -C server config uploadpack.allowanysha1inwant 1 && git clone --bare --filter=blob:none "file://$(pwd)/server" client && - GIT_TRACE_PACKET="$(pwd)/trace" git -C client read-tree $TREE $TREE && + GIT_TRACE_PACKET="$(pwd)/trace" git --git-dir=client read-tree $TREE $TREE && # "done" marks the end of negotiation (once per fetch). Expect that # only one fetch occurs. diff --git a/t/t1050-large.sh b/t/t1050-large.sh index 7d40d0852166b5..6ae2c4aadb0faa 100755 --- a/t/t1050-large.sh +++ b/t/t1050-large.sh @@ -28,8 +28,8 @@ test_expect_success 'enter "large" codepath, with small core.bigFileThreshold' ' test_when_finished "rm -rf repo" && git init --bare repo && - echo large | git -C repo hash-object -w --stdin && - git -C repo -c core.bigfilethreshold=4 fsck + echo large | git --git-dir=repo hash-object -w --stdin && + git --git-dir=repo -c core.bigfilethreshold=4 fsck ' # add a large file with different settings diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh index cd0aed9975fe24..a60ec5dd410213 100755 --- a/t/t1091-sparse-checkout-builtin.sh +++ b/t/t1091-sparse-checkout-builtin.sh @@ -951,32 +951,32 @@ test_expect_success 'setup bare repo' ' git clone --bare "file://$(pwd)/repo" bare ' test_expect_success 'list fails outside work tree' ' - test_must_fail git -C bare sparse-checkout list 2>err && + test_must_fail git --git-dir=bare sparse-checkout list 2>err && test_grep "this operation must be run in a work tree" err ' test_expect_success 'add fails outside work tree' ' - test_must_fail git -C bare sparse-checkout add deeper 2>err && + test_must_fail git --git-dir=bare sparse-checkout add deeper 2>err && test_grep "this operation must be run in a work tree" err ' test_expect_success 'set fails outside work tree' ' - test_must_fail git -C bare sparse-checkout set deeper 2>err && + test_must_fail git --git-dir=bare sparse-checkout set deeper 2>err && test_grep "this operation must be run in a work tree" err ' test_expect_success 'init fails outside work tree' ' - test_must_fail git -C bare sparse-checkout init 2>err && + test_must_fail git --git-dir=bare sparse-checkout init 2>err && test_grep "this operation must be run in a work tree" err ' test_expect_success 'reapply fails outside work tree' ' - test_must_fail git -C bare sparse-checkout reapply 2>err && + test_must_fail git --git-dir=bare sparse-checkout reapply 2>err && test_grep "this operation must be run in a work tree" err ' test_expect_success 'disable fails outside work tree' ' - test_must_fail git -C bare sparse-checkout disable 2>err && + test_must_fail git --git-dir=bare sparse-checkout disable 2>err && test_grep "this operation must be run in a work tree" err ' diff --git a/t/t1305-config-include.sh b/t/t1305-config-include.sh index 6e51f892f320bb..8b8f3886074d3e 100755 --- a/t/t1305-config-include.sh +++ b/t/t1305-config-include.sh @@ -350,9 +350,9 @@ test_expect_success 'conditional include, onbranch, implicit /** for /' ' test_expect_success 'include cycles are detected' ' git init --bare cycle && - git -C cycle config include.path cycle && + git --git-dir=cycle config include.path cycle && git config -f cycle/cycle include.path config && - test_must_fail git -C cycle config --get-all test.value 2>stderr && + test_must_fail git --git-dir=cycle config --get-all test.value 2>stderr && grep "exceeded maximum include depth" stderr ' diff --git a/t/t1460-refs-migrate.sh b/t/t1460-refs-migrate.sh index 39ddf4d4e58568..3a7fd427504353 100755 --- a/t/t1460-refs-migrate.sh +++ b/t/t1460-refs-migrate.sh @@ -43,25 +43,25 @@ test_migration () { skip_reflog_verify=$1 shift fi && - git -C "$repo" for-each-ref --include-root-refs \ + git "$repo_flag" "$repo" for-each-ref --include-root-refs \ --format='%(refname) %(objectname) %(symref)' >expect && if ! $skip_reflog_verify then - print_all_reflog_entries "$repo" >expect_logs + print_all_reflog_entries "$repo_flag" "$repo" >expect_logs fi && - git -C "$repo" refs migrate --ref-format="$format" "$@" && + git "$repo_flag" "$repo" refs migrate --ref-format="$format" "$@" && - git -C "$repo" for-each-ref --include-root-refs \ + git "$repo_flag" "$repo" for-each-ref --include-root-refs \ --format='%(refname) %(objectname) %(symref)' >actual && test_cmp expect actual && if ! $skip_reflog_verify then - print_all_reflog_entries "$repo" >actual_logs && + print_all_reflog_entries "$repo_flag" "$repo" >actual_logs && test_cmp expect_logs actual_logs fi && - git -C "$repo" rev-parse --show-ref-format >actual && + git "$repo_flag" "$repo" rev-parse --show-ref-format >actual && echo "$format" >expect && test_cmp expect actual } @@ -152,7 +152,7 @@ do git init --ref-format=$from_format repo && test_commit -C repo initial && git clone --ref-format=$from_format --mirror repo repo.git && - test_migration repo.git "$to_format" + test_migration --git-dir repo.git "$to_format" ' test_expect_success "$from_format -> $to_format: dangling symref" ' diff --git a/t/t1512-rev-parse-disambiguation.sh b/t/t1512-rev-parse-disambiguation.sh index 1a380a418425a4..5d74a2d21ae89a 100755 --- a/t/t1512-rev-parse-disambiguation.sh +++ b/t/t1512-rev-parse-disambiguation.sh @@ -31,7 +31,7 @@ test_cmp_failed_rev_parse () { rev=$2 cat >expect && - test_must_fail git -C "$dir" rev-parse "$rev" 2>actual.raw && + test_must_fail git --git-dir="$dir" rev-parse "$rev" 2>actual.raw && sed "s/\($rev\)[0-9a-f]*/\1.../" actual && test_cmp expect actual } @@ -50,7 +50,7 @@ test_expect_success 'ambiguous blob output' ' echo 1bbfctrkc | git hash-object -w --stdin ) && - test_must_fail git -C blob.prefix rev-parse dead && + test_must_fail git --git-dir=blob.prefix rev-parse dead && test_cmp_failed_rev_parse blob.prefix beef <<-\EOF error: short object ID beef... is ambiguous hint: The candidates are: diff --git a/t/t1900-repo-info.sh b/t/t1900-repo-info.sh index a9eb07abe8aaea..8f363df66aa2c5 100755 --- a/t/t1900-repo-info.sh +++ b/t/t1900-repo-info.sh @@ -20,6 +20,7 @@ test_repo_info () { repo_name=$3 key=$4 expected_value=$5 + repo_flag=${6:--C} test_expect_success "setup: $label" ' eval "$init_command $repo_name" @@ -27,13 +28,13 @@ test_repo_info () { test_expect_success "lines: $label" ' echo "$key=$expected_value" > expect && - git -C "$repo_name" repo info "$key" >actual && + git $repo_flag "$repo_name" repo info "$key" >actual && test_cmp expect actual ' test_expect_success "nul: $label" ' printf "%s\n%s\0" "$key" "$expected_value" >expect && - git -C "$repo_name" repo info --format=nul "$key" >actual && + git $repo_flag "$repo_name" repo info --format=nul "$key" >actual && test_cmp_bin expect actual ' } @@ -48,7 +49,7 @@ test_repo_info 'bare repository = false is retrieved correctly' \ 'git init' 'nonbare' 'layout.bare' 'false' test_repo_info 'bare repository = true is retrieved correctly' \ - 'git init --bare' 'bare' 'layout.bare' 'true' + 'git init --bare' 'bare' 'layout.bare' 'true' '--git-dir' test_repo_info 'shallow repository = false is retrieved correctly' \ 'git init' 'nonshallow' 'layout.shallow' 'false' diff --git a/t/t2400-worktree-add.sh b/t/t2400-worktree-add.sh index 4e670f53c4aedd..d4a685a14f9e83 100755 --- a/t/t2400-worktree-add.sh +++ b/t/t2400-worktree-add.sh @@ -404,7 +404,7 @@ test_expect_success '"add --orphan" with empty repository' ' test_when_finished "rm -rf empty_repo" && echo refs/heads/newbranch >expected && GIT_DIR="empty_repo" git init --bare && - git -C empty_repo worktree add --orphan -b newbranch worktreedir && + git --git-dir=empty_repo worktree add --orphan -b newbranch empty_repo/worktreedir && git -C empty_repo/worktreedir symbolic-ref HEAD >actual && test_cmp expected actual ' diff --git a/t/t2402-worktree-list.sh b/t/t2402-worktree-list.sh index e0c6abd2f58e20..9fca01a2035d21 100755 --- a/t/t2402-worktree-list.sh +++ b/t/t2402-worktree-list.sh @@ -314,7 +314,7 @@ test_expect_success 'linked worktrees with relative paths are shown with absolut test_expect_success 'worktree path when called in .git directory' ' git worktree list >list1 && - git -C .git worktree list >list2 && + git --git-dir=.git worktree list >list2 && test_cmp list1 list2 ' diff --git a/t/t3650-replay-basics.sh b/t/t3650-replay-basics.sh index a03f8f9293eb12..142edb35f79a3a 100755 --- a/t/t3650-replay-basics.sh +++ b/t/t3650-replay-basics.sh @@ -124,7 +124,7 @@ test_expect_success 'using replay to rebase two branches, one on top of other' ' ' test_expect_success 'using replay on bare repo to rebase two branches, one on top of other' ' - git -C bare replay --ref-action=print --onto main topic1..topic2 >result-bare && + git --git-dir=bare replay --ref-action=print --onto main topic1..topic2 >result-bare && test_cmp expect result-bare ' @@ -133,7 +133,7 @@ test_expect_success 'using replay to rebase with a conflict' ' ' test_expect_success 'using replay on bare repo to rebase with a conflict' ' - test_expect_code 1 git -C bare replay --onto topic1 B..conflict + test_expect_code 1 git --git-dir=bare replay --onto topic1 B..conflict ' test_expect_success 'using replay to perform basic cherry-pick' ' @@ -158,7 +158,7 @@ test_expect_success 'using replay to perform basic cherry-pick' ' ' test_expect_success 'using replay on bare repo to perform basic cherry-pick' ' - git -C bare replay --ref-action=print --advance main topic1..topic2 >result-bare && + git --git-dir=bare replay --ref-action=print --advance main topic1..topic2 >result-bare && test_cmp expect result-bare ' @@ -182,7 +182,7 @@ test_expect_success 'commits that become empty are dropped' ' ' test_expect_success 'replay on bare repo fails with both --advance and --onto' ' - test_must_fail git -C bare replay --advance main --onto main topic1..topic2 >result-bare + test_must_fail git --git-dir=bare replay --advance main --onto main topic1..topic2 >result-bare ' test_expect_success 'replay fails when both --advance and --onto are omitted' ' @@ -214,7 +214,7 @@ test_expect_success 'using replay to also rebase a contained branch' ' ' test_expect_success 'using replay on bare repo to also rebase a contained branch' ' - git -C bare replay --ref-action=print --contained --onto main main..topic3 >result-bare && + git --git-dir=bare replay --ref-action=print --contained --onto main main..topic3 >result-bare && test_cmp expect result-bare ' @@ -243,7 +243,7 @@ test_expect_success 'using replay to rebase multiple divergent branches' ' ' test_expect_success 'using replay on bare repo to rebase multiple divergent branches, including contained ones' ' - git -C bare replay --ref-action=print --contained --onto main ^main topic2 topic3 topic4 >result && + git --git-dir=bare replay --ref-action=print --contained --onto main ^main topic2 topic3 topic4 >result && test_line_count = 4 result && cut -f 3 -d " " result >new-branch-tips && @@ -253,7 +253,7 @@ test_expect_success 'using replay on bare repo to rebase multiple divergent bran do printf "update refs/heads/topic$i " >>expect && printf "%s " $(grep topic$i result | cut -f 3 -d " ") >>expect && - git -C bare rev-parse topic$i >>expect || return 1 + git --git-dir=bare rev-parse topic$i >>expect || return 1 done && test_cmp expect result && @@ -265,7 +265,7 @@ test_expect_success 'using replay on bare repo to rebase multiple divergent bran for i in 1 2 3 4 do - git -C bare log --format=%s $(grep topic$i result | cut -f 3 -d " ") >actual && + git --git-dir=bare log --format=%s $(grep topic$i result | cut -f 3 -d " ") >actual && test_cmp expect$i actual || return 1 done ' @@ -324,15 +324,15 @@ test_expect_success 'default atomic behavior updates refs directly' ' test_expect_success 'atomic behavior in bare repository' ' # Store original state for cleanup - START=$(git -C bare rev-parse topic2) && - test_when_finished "git -C bare update-ref refs/heads/topic2 $START" && + START=$(git --git-dir=bare rev-parse topic2) && + test_when_finished "git --git-dir=bare update-ref refs/heads/topic2 $START" && # Test atomic updates work in bare repo - git -C bare replay --onto main topic1..topic2 >output && + git --git-dir=bare replay --onto main topic1..topic2 >output && test_must_be_empty output && # Verify ref was updated in bare repo - git -C bare log --format=%s topic2 >actual && + git --git-dir=bare log --format=%s topic2 >actual && test_write_lines E D M L B A >expect && test_cmp expect actual ' diff --git a/t/t3800-mktag.sh b/t/t3800-mktag.sh index 31633e5d39bff2..e8543f0bd7a736 100755 --- a/t/t3800-mktag.sh +++ b/t/t3800-mktag.sh @@ -50,15 +50,15 @@ check_verify_failure () { rm -rf bad-tag && git init --bare bad-tag && - bad_tag=$(git -C bad-tag hash-object -t tag -w --stdin --literally msg && test_grep ! fatal msg && test_grep ! error msg diff --git a/t/t4067-diff-partial-clone.sh b/t/t4067-diff-partial-clone.sh index 30813109ac044e..6bb46697429dca 100755 --- a/t/t4067-diff-partial-clone.sh +++ b/t/t4067-diff-partial-clone.sh @@ -19,7 +19,7 @@ test_expect_success 'git show batches blobs' ' # Ensure that there is exactly 1 negotiation by checking that there is # only 1 "done" line sent. ("done" marks the end of negotiation.) - GIT_TRACE_PACKET="$(pwd)/trace" git -C client show HEAD && + GIT_TRACE_PACKET="$(pwd)/trace" git --git-dir=client show HEAD && grep "fetch> done" trace >done_lines && test_line_count = 1 done_lines ' @@ -43,7 +43,7 @@ test_expect_success 'diff batches blobs' ' # Ensure that there is exactly 1 negotiation by checking that there is # only 1 "done" line sent. ("done" marks the end of negotiation.) - GIT_TRACE_PACKET="$(pwd)/trace" git -C client diff HEAD^ HEAD && + GIT_TRACE_PACKET="$(pwd)/trace" git --git-dir=client diff HEAD^ HEAD && grep "fetch> done" trace >done_lines && test_line_count = 1 done_lines ' @@ -69,7 +69,7 @@ test_expect_success 'diff skips same-OID blobs' ' echo b | git hash-object --stdin >hash-b && # Ensure that only a and another-a are fetched. - GIT_TRACE_PACKET="$(pwd)/trace" git -C client diff HEAD^ HEAD && + GIT_TRACE_PACKET="$(pwd)/trace" git --git-dir=client diff HEAD^ HEAD && grep "want $(cat hash-old-a)" trace && grep "want $(cat hash-new-a)" trace && ! grep "want $(cat hash-b)" trace @@ -102,7 +102,7 @@ test_expect_success 'when fetching missing objects, diff skips GITLINKs' ' # Ensure that a and another-a are fetched, and check (by successful # execution of the diff) that no invalid OIDs are sent. - GIT_TRACE_PACKET="$(pwd)/trace" git -C client diff HEAD^ HEAD && + GIT_TRACE_PACKET="$(pwd)/trace" git --git-dir=client diff HEAD^ HEAD && grep "want $(cat hash-old-a)" trace && grep "want $(cat hash-new-a)" trace ' @@ -126,7 +126,7 @@ test_expect_success 'diff with rename detection batches blobs' ' # Ensure that there is exactly 1 negotiation by checking that there is # only 1 "done" line sent. ("done" marks the end of negotiation.) - GIT_TRACE_PACKET="$(pwd)/trace" git -C client diff --raw -M HEAD^ HEAD >out && + GIT_TRACE_PACKET="$(pwd)/trace" git --git-dir=client diff --raw -M HEAD^ HEAD >out && grep ":100644 100644.*R[0-9][0-9][0-9].*b.*c" out && grep "fetch> done" trace >done_lines && test_line_count = 1 done_lines @@ -215,7 +215,7 @@ test_expect_success 'diff does not fetch anything if inexact rename detection is git clone --bare --filter=blob:limit=0 "file://$(pwd)/server" client && # Ensure no fetches. - GIT_TRACE_PACKET="$(pwd)/trace" git -C client diff --raw -M HEAD^ HEAD && + GIT_TRACE_PACKET="$(pwd)/trace" git --git-dir=client diff --raw -M HEAD^ HEAD && test_path_is_missing trace ' @@ -235,13 +235,13 @@ test_expect_success 'diff --break-rewrites fetches only if necessary, and batche git clone --bare --filter=blob:limit=0 "file://$(pwd)/server" client && # Ensure no fetches. - GIT_TRACE_PACKET="$(pwd)/trace" git -C client diff --raw -M HEAD^ HEAD && + GIT_TRACE_PACKET="$(pwd)/trace" git --git-dir=client diff --raw -M HEAD^ HEAD && test_path_is_missing trace && # But with --break-rewrites, ensure that there is exactly 1 negotiation # by checking that there is only 1 "done" line sent. ("done" marks the # end of negotiation.) - GIT_TRACE_PACKET="$(pwd)/trace" git -C client diff --break-rewrites --raw -M HEAD^ HEAD && + GIT_TRACE_PACKET="$(pwd)/trace" git --git-dir=client diff --break-rewrites --raw -M HEAD^ HEAD && grep "fetch> done" trace >done_lines && test_line_count = 1 done_lines ' diff --git a/t/t5003-archive-zip.sh b/t/t5003-archive-zip.sh index c8c1c5c06b6037..57668c8e4ab3bb 100755 --- a/t/t5003-archive-zip.sh +++ b/t/t5003-archive-zip.sh @@ -146,7 +146,7 @@ test_expect_success 'create bare clone' ' cp .git/info/attributes bare.git/info/attributes && # Recreate our changes to .git/config rather than just copying it, as # we do not want to clobber core.bare or other settings. - git -C bare.git config diff.custom.binary true + git --git-dir=bare.git config diff.custom.binary true ' test_expect_success \ diff --git a/t/t5300-pack-object.sh b/t/t5300-pack-object.sh index 73445782e74451..0820d6ff2dea15 100755 --- a/t/t5300-pack-object.sh +++ b/t/t5300-pack-object.sh @@ -171,9 +171,9 @@ check_unpack () { test_when_finished "rm -rf git2" && git $git_config init --bare git2 && ( - git $git_config -C git2 unpack-objects -n <"$packname".pack && - git $git_config -C git2 unpack-objects <"$packname".pack && - git $git_config -C git2 cat-file --batch-check="%(objectname)" + git $git_config --git-dir=git2 unpack-objects -n <"$packname".pack && + git $git_config --git-dir=git2 unpack-objects <"$packname".pack && + git $git_config --git-dir=git2 cat-file --batch-check="%(objectname)" ) <"$object_list" >current && cmp "$object_list" current } diff --git a/t/t5310-pack-bitmaps.sh b/t/t5310-pack-bitmaps.sh index f693cb56691988..34ac63acdd0e43 100755 --- a/t/t5310-pack-bitmaps.sh +++ b/t/t5310-pack-bitmaps.sh @@ -247,7 +247,7 @@ test_bitmap_cases () { git commit -m "commit with big file" && git -c pack.packSizeLimit=500k repack -adb && git init --bare no-bitmaps.git && - git -C no-bitmaps.git fetch .. HEAD + git --git-dir=no-bitmaps.git fetch . HEAD ' test_expect_success 'set up reusable pack' ' diff --git a/t/t5318-commit-graph.sh b/t/t5318-commit-graph.sh index 98c69109632c2d..063dacf5293661 100755 --- a/t/t5318-commit-graph.sh +++ b/t/t5318-commit-graph.sh @@ -274,17 +274,17 @@ test_expect_success 'setup bare repo' ' git clone --bare --no-local full bare ' -graph_git_behavior 'bare repo, commit 8 vs merge 1' bare commits/8 merge/1 -graph_git_behavior 'bare repo, commit 8 vs merge 2' bare commits/8 merge/2 +graph_git_behavior --bare 'bare repo, commit 8 vs merge 1' bare commits/8 merge/1 +graph_git_behavior --bare 'bare repo, commit 8 vs merge 2' bare commits/8 merge/2 test_expect_success 'write graph in bare repo' ' - git -C bare commit-graph write && + git --git-dir=bare commit-graph write && test_path_is_file bare/objects/info/commit-graph && - graph_read_expect -C bare 11 "generation_data extra_edges" + graph_read_expect --bare -C bare 11 "generation_data extra_edges" ' -graph_git_behavior 'bare repo with graph, commit 8 vs merge 1' bare commits/8 merge/1 -graph_git_behavior 'bare repo with graph, commit 8 vs merge 2' bare commits/8 merge/2 +graph_git_behavior --bare 'bare repo with graph, commit 8 vs merge 1' bare commits/8 merge/1 +graph_git_behavior --bare 'bare repo with graph, commit 8 vs merge 2' bare commits/8 merge/2 test_expect_success 'perform fast-forward merge in full repo' ' git -C full checkout -b merge-5-to-8 commits/5 && diff --git a/t/t5351-unpack-large-objects.sh b/t/t5351-unpack-large-objects.sh index d76eb4be932eeb..ce52e415d82e14 100755 --- a/t/t5351-unpack-large-objects.sh +++ b/t/t5351-unpack-large-objects.sh @@ -10,7 +10,7 @@ test_description='git unpack-objects with large objects' prepare_dest () { test_when_finished "rm -rf dest.git" && git init --bare dest.git && - git -C dest.git config core.bigFileThreshold "$1" + git --git-dir=dest.git config core.bigFileThreshold "$1" } test_expect_success "create large objects (1.5 MB) and PACK" ' @@ -31,20 +31,20 @@ test_expect_success 'set memory limitation to 1MB' ' test_expect_success 'unpack-objects failed under memory limitation' ' prepare_dest 2m && - test_must_fail git -C dest.git unpack-objects err && + test_must_fail git --git-dir=dest.git unpack-objects err && grep "fatal: attempting to allocate" err ' test_expect_success 'unpack-objects works with memory limitation in dry-run mode' ' prepare_dest 2m && - git -C dest.git unpack-objects -n current && + git --git-dir=dest.git cat-file --batch-check="%(objectname)" current && cmp obj-list current ' test_expect_success 'do not unpack existing large objects' ' prepare_dest 1m && - git -C dest.git index-pack --stdin expect && - git -C all.git for-each-ref refs/heads >actual && + git --git-dir=all.git for-each-ref refs/heads >actual && test_cmp expect actual ' diff --git a/t/t5401-update-hooks.sh b/t/t5401-update-hooks.sh index 44ec875aef88ae..5fc0adf62b9155 100755 --- a/t/t5401-update-hooks.sh +++ b/t/t5401-update-hooks.sh @@ -23,14 +23,14 @@ test_expect_success setup ' git update-ref refs/heads/main $commit1 && git update-ref refs/heads/tofail $commit0 && - test_hook --setup -C victim.git pre-receive <<-\EOF && + test_hook --setup --git-dir victim.git pre-receive <<-\EOF && printf %s "$@" >>$GIT_DIR/pre-receive.args cat - >$GIT_DIR/pre-receive.stdin echo STDOUT pre-receive echo STDERR pre-receive >&2 EOF - test_hook --setup -C victim.git update <<-\EOF && + test_hook --setup --git-dir victim.git update <<-\EOF && echo "$@" >>$GIT_DIR/update.args read x; printf %s "$x" >$GIT_DIR/update.stdin echo STDOUT update $1 @@ -38,14 +38,14 @@ test_expect_success setup ' test "$1" = refs/heads/main || exit EOF - test_hook --setup -C victim.git post-receive <<-\EOF && + test_hook --setup --git-dir victim.git post-receive <<-\EOF && printf %s "$@" >>$GIT_DIR/post-receive.args cat - >$GIT_DIR/post-receive.stdin echo STDOUT post-receive echo STDERR post-receive >&2 EOF - test_hook --setup -C victim.git post-update <<-\EOF + test_hook --setup --git-dir victim.git post-update <<-\EOF echo "$@" >>$GIT_DIR/post-update.args read x; printf %s "$x" >$GIT_DIR/post-update.stdin echo STDOUT post-update @@ -129,7 +129,7 @@ test_expect_success 'send-pack stderr contains hook messages' ' ' test_expect_success 'pre-receive hook that forgets to read its input' ' - test_hook --clobber -C victim.git pre-receive <<-\EOF && + test_hook --clobber --git-dir victim.git pre-receive <<-\EOF && exit 0 EOF rm -f victim.git/hooks/update victim.git/hooks/post-update && diff --git a/t/t5410-receive-pack.sh b/t/t5410-receive-pack.sh index aa0b32007dacfc..896495c5471077 100755 --- a/t/t5410-receive-pack.sh +++ b/t/t5410-receive-pack.sh @@ -71,7 +71,7 @@ test_expect_success TEE_DOES_NOT_HANG \ test_grep "missing necessary objects" actual && test_grep "fatal: Failed to traverse parents" err && - test_must_fail git -C remote.git cat-file -e $(git -C repo rev-parse HEAD) + test_must_fail git --git-dir=remote.git cat-file -e $(git -C repo rev-parse HEAD) ' test_expect_success TEE_DOES_NOT_HANG \ @@ -93,8 +93,8 @@ test_expect_success TEE_DOES_NOT_HANG \ test_grep ! "missing necessary objects" actual && test_must_be_empty err && - git -C remote.git cat-file -e $(git -C repo rev-parse HEAD) && - test_must_fail git -C remote.git rev-list $(git -C repo rev-parse HEAD) + git --git-dir=remote.git cat-file -e $(git -C repo rev-parse HEAD) && + test_must_fail git --git-dir=remote.git rev-list $(git -C repo rev-parse HEAD) ' test_done diff --git a/t/t5411-proc-receive-hook.sh b/t/t5411-proc-receive-hook.sh index 92cf52c6d4a32c..b00568ab8f8427 100755 --- a/t/t5411-proc-receive-hook.sh +++ b/t/t5411-proc-receive-hook.sh @@ -30,13 +30,13 @@ setup_upstream_and_workbench () { git remote add origin ../upstream.git && git push origin main && git update-ref refs/heads/main $A $B && - git -C ../upstream.git update-ref \ + git --git-dir=../upstream.git update-ref \ refs/heads/main $A $B ) && TAG=$(git -C workbench rev-parse v123) && # setup pre-receive hook - test_hook --setup -C upstream.git pre-receive <<-\EOF && + test_hook --setup --git-dir upstream.git pre-receive <<-\EOF && exec >&2 echo "# pre-receive hook" while read old new ref @@ -46,7 +46,7 @@ setup_upstream_and_workbench () { EOF # setup post-receive hook - test_hook --setup -C upstream.git post-receive <<-\EOF && + test_hook --setup --git-dir upstream.git post-receive <<-\EOF && exec >&2 echo "# post-receive hook" while read old new ref @@ -105,7 +105,7 @@ setup_upstream_and_workbench # Refs of upstream : main(A) # Refs of workbench: main(A) tags/v123 test_expect_success "setup for HTTP protocol" ' - git -C upstream.git config http.receivepack true && + git --git-dir=upstream.git config http.receivepack true && upstream="$HTTPD_DOCUMENT_ROOT_PATH/upstream.git" && mv upstream.git "$upstream" && git -C workbench remote set-url origin "$HTTPD_URL/auth-push/smart/upstream.git" && diff --git a/t/t5411/common-functions.sh b/t/t5411/common-functions.sh index 3c747782c1b7fb..83587f029d7326 100644 --- a/t/t5411/common-functions.sh +++ b/t/t5411/common-functions.sh @@ -59,15 +59,20 @@ format_and_save_expect () { test_cmp_refs () { indir= + gitdir= if test "$1" = "-C" then shift indir="$1" shift + elif test "$1" = "--git-dir" + then + shift + gitdir="$1" + shift fi - indir=${indir:+"$indir"/} cat >show-ref.expect && - git ${indir:+ -C "$indir"} show-ref >show-ref.pristine && + git ${indir:+ -C "$indir"} ${gitdir:+ --git-dir="$gitdir"} show-ref >show-ref.pristine && make_user_friendly_and_stable_output show-ref.filtered && test_cmp show-ref.expect show-ref.filtered } diff --git a/t/t5411/once-0010-report-status-v1.sh b/t/t5411/once-0010-report-status-v1.sh index 42e2b0435574b5..f6598bbf564e9b 100644 --- a/t/t5411/once-0010-report-status-v1.sh +++ b/t/t5411/once-0010-report-status-v1.sh @@ -42,7 +42,7 @@ test_expect_success "proc-receive: report status v1" ' printf "%s %s refs/for/main/topic2\n" \ $ZERO_OID $A | packetize && printf 0000 && - printf "" | git -C "$upstream" pack-objects --stdout + printf "" | git --git-dir="$upstream" pack-objects --stdout } | git receive-pack "$upstream" --stateless-rpc \ >out 2>&1 && make_user_friendly_and_stable_output actual && @@ -83,7 +83,7 @@ test_expect_success "proc-receive: report status v1" ' EOF test_cmp expect actual && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/for/main/topic1 refs/heads/foo refs/heads/main diff --git a/t/t5411/test-0000-standard-git-push.sh b/t/t5411/test-0000-standard-git-push.sh index ce64bb660ba2da..8274e00cd9c02e 100644 --- a/t/t5411/test-0000-standard-git-push.sh +++ b/t/t5411/test-0000-standard-git-push.sh @@ -20,7 +20,7 @@ test_expect_success "git-push ($PROTOCOL)" ' EOF test_cmp expect actual && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/heads/main refs/heads/next EOF @@ -45,7 +45,7 @@ test_expect_success "git-push --atomic ($PROTOCOL)" ' EOF test_cmp expect actual && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/heads/main refs/heads/next EOF @@ -74,7 +74,7 @@ test_expect_success "non-fast-forward git-push ($PROTOCOL)" ' EOF test_cmp expect actual && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/heads/main refs/heads/next EOF @@ -114,7 +114,7 @@ test_expect_success "git-push -f ($PROTOCOL)" ' EOF test_cmp expect actual && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/heads/a/b/c refs/heads/main refs/review/main/topic diff --git a/t/t5411/test-0001-standard-git-push--porcelain.sh b/t/t5411/test-0001-standard-git-push--porcelain.sh index 373ec3d865dba3..45c06b4d775158 100644 --- a/t/t5411/test-0001-standard-git-push--porcelain.sh +++ b/t/t5411/test-0001-standard-git-push--porcelain.sh @@ -21,7 +21,7 @@ test_expect_success "git-push ($PROTOCOL/porcelain)" ' EOF test_cmp expect actual && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/heads/main refs/heads/next EOF @@ -47,7 +47,7 @@ test_expect_success "git-push --atomic ($PROTOCOL/porcelain)" ' EOF test_cmp expect actual && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/heads/main refs/heads/next EOF @@ -77,7 +77,7 @@ test_expect_success "non-fast-forward git-push ($PROTOCOL/porcelain)" ' EOF test_cmp expect actual && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/heads/main refs/heads/next EOF @@ -118,7 +118,7 @@ test_expect_success "git-push -f ($PROTOCOL/porcelain)" ' EOF test_cmp expect actual && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/heads/a/b/c refs/heads/main refs/review/main/topic diff --git a/t/t5411/test-0002-pre-receive-declined.sh b/t/t5411/test-0002-pre-receive-declined.sh index f6abfab69da7d1..bee97fad0d2600 100644 --- a/t/t5411/test-0002-pre-receive-declined.sh +++ b/t/t5411/test-0002-pre-receive-declined.sh @@ -21,7 +21,7 @@ test_expect_success "git-push is declined ($PROTOCOL)" ' EOF test_cmp expect actual && - test_cmp_refs -C "$upstream" <<-\EOF + test_cmp_refs --git-dir "$upstream" <<-\EOF refs/heads/main EOF ' diff --git a/t/t5411/test-0003-pre-receive-declined--porcelain.sh b/t/t5411/test-0003-pre-receive-declined--porcelain.sh index 98b746013b2248..38d98cd3565f2a 100644 --- a/t/t5411/test-0003-pre-receive-declined--porcelain.sh +++ b/t/t5411/test-0003-pre-receive-declined--porcelain.sh @@ -22,7 +22,7 @@ test_expect_success "git-push is declined ($PROTOCOL/porcelain)" ' EOF test_cmp expect actual && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/heads/main EOF ' diff --git a/t/t5411/test-0011-no-hook-error.sh b/t/t5411/test-0011-no-hook-error.sh index d35002b1f0237e..d981375120cb5f 100644 --- a/t/t5411/test-0011-no-hook-error.sh +++ b/t/t5411/test-0011-no-hook-error.sh @@ -20,7 +20,7 @@ test_expect_success "proc-receive: no hook, fail to push special ref ($PROTOCOL) EOF test_cmp expect actual && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/heads/main refs/heads/next EOF @@ -29,7 +29,7 @@ test_expect_success "proc-receive: no hook, fail to push special ref ($PROTOCOL) # Refs of upstream : main(A) next(A) # Refs of workbench: main(A) tags/v123 test_expect_success "cleanup ($PROTOCOL)" ' - git -C "$upstream" update-ref -d refs/heads/next + git --git-dir="$upstream" update-ref -d refs/heads/next ' # Refs of upstream : main(A) @@ -54,7 +54,7 @@ test_expect_success "proc-receive: no hook, all failed for atomic push ($PROTOCO EOF test_cmp expect actual && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/heads/main EOF ' diff --git a/t/t5411/test-0012-no-hook-error--porcelain.sh b/t/t5411/test-0012-no-hook-error--porcelain.sh index 04468b501887b6..6ea6256b2d16cf 100644 --- a/t/t5411/test-0012-no-hook-error--porcelain.sh +++ b/t/t5411/test-0012-no-hook-error--porcelain.sh @@ -21,7 +21,7 @@ test_expect_success "proc-receive: no hook, fail to push special ref ($PROTOCOL/ EOF test_cmp expect actual && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/heads/main refs/heads/next EOF @@ -30,7 +30,7 @@ test_expect_success "proc-receive: no hook, fail to push special ref ($PROTOCOL/ # Refs of upstream : main(A) next(A) # Refs of workbench: main(A) tags/v123 test_expect_success "cleanup ($PROTOCOL/porcelain)" ' - git -C "$upstream" update-ref -d refs/heads/next + git --git-dir="$upstream" update-ref -d refs/heads/next ' # Refs of upstream : main(A) @@ -56,7 +56,7 @@ test_expect_success "proc-receive: no hook, all failed for atomic push ($PROTOCO EOF test_cmp expect actual && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/heads/main EOF ' diff --git a/t/t5411/test-0013-bad-protocol.sh b/t/t5411/test-0013-bad-protocol.sh index 562650a96db963..1a52bc49d9c934 100644 --- a/t/t5411/test-0013-bad-protocol.sh +++ b/t/t5411/test-0013-bad-protocol.sh @@ -142,7 +142,7 @@ test_expect_success "setup proc-receive hook (hook --die-read-push-options, $PRO # Refs of workbench: main(A) tags/v123 # git push : refs/for/main/topic(A) test_expect_success "proc-receive: bad protocol (hook --die-read-push-options, $PROTOCOL)" ' - git -C "$upstream" config receive.advertisePushOptions true && + git --git-dir="$upstream" config receive.advertisePushOptions true && test_must_fail git -C workbench push origin \ -o reviewers=user1,user2 \ HEAD:refs/for/main/topic \ @@ -222,7 +222,7 @@ test_expect_success "proc-receive: bad protocol (no report, $PROTOCOL)" ' EOF test_cmp expect actual && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/heads/main refs/heads/next EOF @@ -296,7 +296,7 @@ test_expect_success "proc-receive: bad protocol (unknown status, $PROTOCOL)" ' EOF test_cmp expect actual && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/heads/main EOF ' diff --git a/t/t5411/test-0014-bad-protocol--porcelain.sh b/t/t5411/test-0014-bad-protocol--porcelain.sh index 59e8b505559105..91deaeb46ff7f6 100644 --- a/t/t5411/test-0014-bad-protocol--porcelain.sh +++ b/t/t5411/test-0014-bad-protocol--porcelain.sh @@ -142,7 +142,7 @@ test_expect_success "setup proc-receive hook (hook --die-read-push-options, $PRO # Refs of workbench: main(A) tags/v123 # git push : refs/for/main/topic(A) test_expect_success "proc-receive: bad protocol (hook --die-read-push-options, $PROTOCOL/porcelain)" ' - git -C "$upstream" config receive.advertisePushOptions true && + git --git-dir="$upstream" config receive.advertisePushOptions true && test_must_fail git -C workbench push --porcelain origin \ -o reviewers=user1,user2 \ HEAD:refs/for/main/topic \ @@ -223,7 +223,7 @@ test_expect_success "proc-receive: bad protocol (no report, $PROTOCOL/porcelain) EOF test_cmp expect actual && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/heads/main refs/heads/next EOF @@ -298,7 +298,7 @@ test_expect_success "proc-receive: bad protocol (unknown status, $PROTOCOL/porce EOF test_cmp expect actual && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/heads/main EOF ' diff --git a/t/t5411/test-0020-report-ng.sh b/t/t5411/test-0020-report-ng.sh index 21853c8bd1ba2f..2d0666ab348032 100644 --- a/t/t5411/test-0020-report-ng.sh +++ b/t/t5411/test-0020-report-ng.sh @@ -57,7 +57,7 @@ test_expect_success "proc-receive: fail to update (ng, with message, $PROTOCOL)" EOF test_cmp expect actual && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/heads/main EOF ' diff --git a/t/t5411/test-0021-report-ng--porcelain.sh b/t/t5411/test-0021-report-ng--porcelain.sh index 507c0836d983c6..87e1b771511a54 100644 --- a/t/t5411/test-0021-report-ng--porcelain.sh +++ b/t/t5411/test-0021-report-ng--porcelain.sh @@ -59,7 +59,7 @@ test_expect_success "proc-receive: fail to update (ng, with message, $PROTOCOL/p EOF test_cmp expect actual && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/heads/main EOF ' diff --git a/t/t5411/test-0022-report-unexpect-ref.sh b/t/t5411/test-0022-report-unexpect-ref.sh index b4fad45eaf6aa7..d2ebc1705d1cb0 100644 --- a/t/t5411/test-0022-report-unexpect-ref.sh +++ b/t/t5411/test-0022-report-unexpect-ref.sh @@ -31,7 +31,7 @@ test_expect_success "proc-receive: report unexpected ref ($PROTOCOL)" ' EOF test_cmp expect actual && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/heads/main EOF ' @@ -39,5 +39,5 @@ test_expect_success "proc-receive: report unexpected ref ($PROTOCOL)" ' # Refs of upstream : main(B) # Refs of workbench: main(A) tags/v123 test_expect_success "cleanup ($PROTOCOL)" ' - git -C "$upstream" update-ref refs/heads/main $A + git --git-dir="$upstream" update-ref refs/heads/main $A ' diff --git a/t/t5411/test-0023-report-unexpect-ref--porcelain.sh b/t/t5411/test-0023-report-unexpect-ref--porcelain.sh index 7bf5c12fd63c4e..ba7877bb4c0997 100644 --- a/t/t5411/test-0023-report-unexpect-ref--porcelain.sh +++ b/t/t5411/test-0023-report-unexpect-ref--porcelain.sh @@ -32,7 +32,7 @@ test_expect_success "proc-receive: report unexpected ref ($PROTOCOL/porcelain)" EOF test_cmp expect actual && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/heads/main EOF ' @@ -40,5 +40,5 @@ test_expect_success "proc-receive: report unexpected ref ($PROTOCOL/porcelain)" # Refs of upstream : main(B) # Refs of workbench: main(A) tags/v123 test_expect_success "cleanup ($PROTOCOL/porcelain)" ' - git -C "$upstream" update-ref refs/heads/main $A + git --git-dir="$upstream" update-ref refs/heads/main $A ' diff --git a/t/t5411/test-0024-report-unknown-ref.sh b/t/t5411/test-0024-report-unknown-ref.sh index 0c878dfb9e17f2..bf2d1d4bb0a9b8 100644 --- a/t/t5411/test-0024-report-unknown-ref.sh +++ b/t/t5411/test-0024-report-unknown-ref.sh @@ -26,7 +26,7 @@ test_expect_success "proc-receive: report unknown reference ($PROTOCOL)" ' EOF test_cmp expect actual && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/heads/main EOF ' diff --git a/t/t5411/test-0025-report-unknown-ref--porcelain.sh b/t/t5411/test-0025-report-unknown-ref--porcelain.sh index 9d83c46c1248db..5e0262ed8010da 100644 --- a/t/t5411/test-0025-report-unknown-ref--porcelain.sh +++ b/t/t5411/test-0025-report-unknown-ref--porcelain.sh @@ -27,7 +27,7 @@ test_expect_success "proc-receive: report unknown reference ($PROTOCOL/porcelain EOF test_cmp expect actual && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/heads/main EOF ' diff --git a/t/t5411/test-0026-push-options.sh b/t/t5411/test-0026-push-options.sh index 626c1f9688c62a..111200007a9b3b 100644 --- a/t/t5411/test-0026-push-options.sh +++ b/t/t5411/test-0026-push-options.sh @@ -85,7 +85,7 @@ test_expect_success "restore proc-receive hook ($PROTOCOL)" ' # Refs of upstream : main(A) next(A) # Refs of workbench: main(A) tags/v123 test_expect_success "cleanup ($PROTOCOL)" ' - git -C "$upstream" update-ref -d refs/heads/next + git --git-dir="$upstream" update-ref -d refs/heads/next ' # Refs of upstream : main(A) @@ -120,7 +120,7 @@ test_expect_success "proc-receive: push with options ($PROTOCOL)" ' EOF test_cmp expect actual && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/heads/main refs/heads/next EOF @@ -129,5 +129,5 @@ test_expect_success "proc-receive: push with options ($PROTOCOL)" ' # Refs of upstream : main(A) next(A) # Refs of workbench: main(A) tags/v123 test_expect_success "cleanup ($PROTOCOL)" ' - git -C "$upstream" update-ref -d refs/heads/next + git --git-dir="$upstream" update-ref -d refs/heads/next ' diff --git a/t/t5411/test-0027-push-options--porcelain.sh b/t/t5411/test-0027-push-options--porcelain.sh index af8e613f716b1e..90e400050e3ee7 100644 --- a/t/t5411/test-0027-push-options--porcelain.sh +++ b/t/t5411/test-0027-push-options--porcelain.sh @@ -88,7 +88,7 @@ test_expect_success "restore proc-receive hook ($PROTOCOL/porcelain)" ' # Refs of upstream : main(A) next(A) # Refs of workbench: main(A) tags/v123 test_expect_success "cleanup ($PROTOCOL/porcelain)" ' - git -C "$upstream" update-ref -d refs/heads/next + git --git-dir="$upstream" update-ref -d refs/heads/next ' # Refs of upstream : main(A) @@ -125,7 +125,7 @@ test_expect_success "proc-receive: push with options ($PROTOCOL/porcelain)" ' EOF test_cmp expect actual && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/heads/main refs/heads/next EOF @@ -134,5 +134,5 @@ test_expect_success "proc-receive: push with options ($PROTOCOL/porcelain)" ' # Refs of upstream : main(A) next(A) # Refs of workbench: main(A) tags/v123 test_expect_success "cleanup ($PROTOCOL/porcelain)" ' - git -C "$upstream" update-ref -d refs/heads/next + git --git-dir="$upstream" update-ref -d refs/heads/next ' diff --git a/t/t5411/test-0030-report-ok.sh b/t/t5411/test-0030-report-ok.sh index 9a2c3063771601..a9dc9ddf4d21aa 100644 --- a/t/t5411/test-0030-report-ok.sh +++ b/t/t5411/test-0030-report-ok.sh @@ -27,7 +27,7 @@ test_expect_success "proc-receive: ok ($PROTOCOL)" ' EOF test_cmp expect actual && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/heads/main EOF ' diff --git a/t/t5411/test-0031-report-ok--porcelain.sh b/t/t5411/test-0031-report-ok--porcelain.sh index 863c69ec823379..480b00fd6ed39a 100644 --- a/t/t5411/test-0031-report-ok--porcelain.sh +++ b/t/t5411/test-0031-report-ok--porcelain.sh @@ -28,7 +28,7 @@ test_expect_success "proc-receive: ok ($PROTOCOL/porcelain)" ' EOF test_cmp expect actual && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/heads/main EOF ' diff --git a/t/t5411/test-0032-report-with-options.sh b/t/t5411/test-0032-report-with-options.sh index 2dddaf19572574..313d50a5164981 100644 --- a/t/t5411/test-0032-report-with-options.sh +++ b/t/t5411/test-0032-report-with-options.sh @@ -247,7 +247,7 @@ test_expect_success "proc-receive: report with multiple rewrites ($PROTOCOL)" ' EOF test_cmp expect actual && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/heads/main EOF ' diff --git a/t/t5411/test-0033-report-with-options--porcelain.sh b/t/t5411/test-0033-report-with-options--porcelain.sh index f1aaa1e3b5f293..ef325bb5de2f4f 100644 --- a/t/t5411/test-0033-report-with-options--porcelain.sh +++ b/t/t5411/test-0033-report-with-options--porcelain.sh @@ -256,7 +256,7 @@ test_expect_success "proc-receive: report with multiple rewrites ($PROTOCOL/porc EOF test_cmp expect actual && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/heads/main EOF ' diff --git a/t/t5411/test-0034-report-ft.sh b/t/t5411/test-0034-report-ft.sh index ecdc660c21becf..10db1668f644dc 100644 --- a/t/t5411/test-0034-report-ft.sh +++ b/t/t5411/test-0034-report-ft.sh @@ -29,7 +29,7 @@ test_expect_success "proc-receive: fall through, let receive-pack to execute ($P EOF test_cmp expect actual && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/for/main/topic refs/heads/main EOF @@ -38,5 +38,5 @@ test_expect_success "proc-receive: fall through, let receive-pack to execute ($P # Refs of upstream : main(A) refs/for/main/topic(A) # Refs of workbench: main(A) tags/v123 test_expect_success "cleanup ($PROTOCOL)" ' - git -C "$upstream" update-ref -d refs/for/main/topic + git --git-dir="$upstream" update-ref -d refs/for/main/topic ' diff --git a/t/t5411/test-0035-report-ft--porcelain.sh b/t/t5411/test-0035-report-ft--porcelain.sh index cea6ceed5ba042..0f0a8e8a3dedad 100644 --- a/t/t5411/test-0035-report-ft--porcelain.sh +++ b/t/t5411/test-0035-report-ft--porcelain.sh @@ -30,7 +30,7 @@ test_expect_success "proc-receive: fall through, let receive-pack to execute ($P EOF test_cmp expect actual && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/for/main/topic refs/heads/main EOF @@ -39,5 +39,5 @@ test_expect_success "proc-receive: fall through, let receive-pack to execute ($P # Refs of upstream : main(A) refs/for/main/topic(A) # Refs of workbench: main(A) tags/v123 test_expect_success "cleanup ($PROTOCOL/porcelain)" ' - git -C "$upstream" update-ref -d refs/for/main/topic + git --git-dir="$upstream" update-ref -d refs/for/main/topic ' diff --git a/t/t5411/test-0036-report-multi-rewrite-for-one-ref.sh b/t/t5411/test-0036-report-multi-rewrite-for-one-ref.sh index 6caef35875add0..5b4d7f1c12c8a7 100644 --- a/t/t5411/test-0036-report-multi-rewrite-for-one-ref.sh +++ b/t/t5411/test-0036-report-multi-rewrite-for-one-ref.sh @@ -66,7 +66,7 @@ test_expect_success "proc-receive: multiple rewrite for one ref, no refname for EOF test_cmp expect actual && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/heads/main EOF ' @@ -141,7 +141,7 @@ test_expect_success "proc-receive: multiple rewrites for one ref, no refname for EOF test_cmp expect actual && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/heads/main EOF ' @@ -202,7 +202,7 @@ test_expect_success "proc-receive: multiple rewrites for one ref ($PROTOCOL)" ' EOF test_cmp expect actual && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/heads/main EOF ' diff --git a/t/t5411/test-0037-report-multi-rewrite-for-one-ref--porcelain.sh b/t/t5411/test-0037-report-multi-rewrite-for-one-ref--porcelain.sh index 9844185b6b938b..ee8eb4713dd4dd 100644 --- a/t/t5411/test-0037-report-multi-rewrite-for-one-ref--porcelain.sh +++ b/t/t5411/test-0037-report-multi-rewrite-for-one-ref--porcelain.sh @@ -160,7 +160,7 @@ test_expect_success "proc-receive: multiple rewrites for one ref ($PROTOCOL/porc EOF test_cmp expect actual && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/heads/main EOF ' diff --git a/t/t5411/test-0038-report-mixed-refs.sh b/t/t5411/test-0038-report-mixed-refs.sh index 07235c3c73086f..e2dd2ce320790c 100644 --- a/t/t5411/test-0038-report-mixed-refs.sh +++ b/t/t5411/test-0038-report-mixed-refs.sh @@ -66,7 +66,7 @@ test_expect_success "proc-receive: report update of mixed refs ($PROTOCOL)" ' EOF test_cmp expect actual && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/heads/bar refs/heads/baz refs/heads/foo diff --git a/t/t5411/test-0039-report-mixed-refs--porcelain.sh b/t/t5411/test-0039-report-mixed-refs--porcelain.sh index 2a989f576bd9d4..69f8c72634ca2d 100644 --- a/t/t5411/test-0039-report-mixed-refs--porcelain.sh +++ b/t/t5411/test-0039-report-mixed-refs--porcelain.sh @@ -67,7 +67,7 @@ test_expect_success "proc-receive: report update of mixed refs ($PROTOCOL/porcel EOF test_cmp expect actual && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/heads/bar refs/heads/baz refs/heads/foo diff --git a/t/t5411/test-0040-process-all-refs.sh b/t/t5411/test-0040-process-all-refs.sh index 19f30f6cf6d119..421543706d1cae 100644 --- a/t/t5411/test-0040-process-all-refs.sh +++ b/t/t5411/test-0040-process-all-refs.sh @@ -93,7 +93,7 @@ test_expect_success "proc-receive: process all refs ($PROTOCOL)" ' EOF test_cmp expect actual && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/heads/bar refs/heads/baz refs/heads/main diff --git a/t/t5411/test-0041-process-all-refs--porcelain.sh b/t/t5411/test-0041-process-all-refs--porcelain.sh index 54c2be08c19965..8a2eca908159f1 100644 --- a/t/t5411/test-0041-process-all-refs--porcelain.sh +++ b/t/t5411/test-0041-process-all-refs--porcelain.sh @@ -94,7 +94,7 @@ test_expect_success "proc-receive: process all refs ($PROTOCOL/porcelain)" ' EOF test_cmp expect actual && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/heads/bar refs/heads/baz refs/heads/main diff --git a/t/t5411/test-0050-proc-receive-refs-with-modifiers.sh b/t/t5411/test-0050-proc-receive-refs-with-modifiers.sh index cd4cc987b8ca56..cf6242149c5875 100644 --- a/t/t5411/test-0050-proc-receive-refs-with-modifiers.sh +++ b/t/t5411/test-0050-proc-receive-refs-with-modifiers.sh @@ -51,7 +51,7 @@ test_expect_success "proc-receive: update branch and new tag ($PROTOCOL)" ' EOF test_cmp expect actual && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/heads/main EOF ' @@ -59,10 +59,10 @@ test_expect_success "proc-receive: update branch and new tag ($PROTOCOL)" ' # Refs of upstream : main(A) # Refs of workbench: main(A) tags/v123 test_expect_success "setup upstream: create tags/v123 ($PROTOCOL)" ' - git -C "$upstream" update-ref refs/heads/topic $A && - git -C "$upstream" update-ref refs/tags/v123 $TAG && + git --git-dir="$upstream" update-ref refs/heads/topic $A && + git --git-dir="$upstream" update-ref refs/tags/v123 $TAG && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/heads/main refs/heads/topic refs/tags/v123 @@ -122,7 +122,7 @@ test_expect_success "proc-receive: create/delete branch, and delete tag ($PROTOC EOF test_cmp expect actual && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs --git-dir "$upstream" <<-EOF refs/heads/main refs/heads/topic EOF diff --git a/t/t5500-fetch-pack.sh b/t/t5500-fetch-pack.sh index 649a615ec9af15..2033180affcadb 100755 --- a/t/t5500-fetch-pack.sh +++ b/t/t5500-fetch-pack.sh @@ -975,8 +975,8 @@ test_expect_success 'fetching deepen beyond merged branch' ' git merge --no-ff branch && cd - && git clone --bare --depth 3 "file://$(pwd)/shallow-deepen-merged" deepen.git && - git -C deepen.git fetch origin --deepen=1 && - git -C deepen.git rev-list --all >actual && + git --git-dir=deepen.git fetch origin --deepen=1 && + git --git-dir=deepen.git rev-list --all >actual && for commit in $(sed "/^$/d" deepen.git/shallow) do test_grep "$commit" actual || exit 1 diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh index e592c0bcde91e9..f1f6254fb022e2 100755 --- a/t/t5505-remote.sh +++ b/t/t5505-remote.sh @@ -83,8 +83,8 @@ test_expect_success 'add another remote' ' test_expect_success 'setup bare clone for server' ' git clone --bare "file://$(pwd)/one" srv.bare && - git -C srv.bare config --local uploadpack.allowfilter 1 && - git -C srv.bare config --local uploadpack.allowanysha1inwant 1 + git --git-dir=srv.bare config --local uploadpack.allowfilter 1 && + git --git-dir=srv.bare config --local uploadpack.allowanysha1inwant 1 ' test_expect_success 'filters for promisor remotes are listed by git remote -v' ' @@ -1022,10 +1022,10 @@ test_expect_success 'rename handles remote without fetch refspec' ' git clone --bare one no-refspec.git && # confirm assumption that bare clone does not create refspec test_expect_code 5 \ - git -C no-refspec.git config --unset-all remote.origin.fetch && - git -C no-refspec.git config remote.origin.url >expect && - git -C no-refspec.git remote rename origin foo && - git -C no-refspec.git config remote.foo.url >actual && + git --git-dir=no-refspec.git config --unset-all remote.origin.fetch && + git --git-dir=no-refspec.git config remote.origin.url >expect && + git --git-dir=no-refspec.git remote rename origin foo && + git --git-dir=no-refspec.git config remote.foo.url >actual && test_cmp expect actual ' diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh index ba8b47117f8fe6..09349f026752de 100755 --- a/t/t5510-fetch.sh +++ b/t/t5510-fetch.sh @@ -1349,7 +1349,7 @@ test_expect_success 'prepare source branch' ' ' validate_store_type () { - git -C dest count-objects -v >actual && + git --git-dir=dest count-objects -v >actual && case "$store_type" in packed) grep "^count: 0$" actual ;; @@ -1373,9 +1373,9 @@ test_unpack_limit () { test_expect_success "fetch trumps transfer limit" ' rm -fr dest && git --bare init dest && - git -C dest config fetch.unpacklimit $fetch_limit && - git -C dest config transfer.unpacklimit $transfer_limit && - git -C dest fetch .. onebranch && + git --git-dir=dest config fetch.unpacklimit $fetch_limit && + git --git-dir=dest config transfer.unpacklimit $transfer_limit && + git --git-dir=dest fetch . onebranch && validate_store_type ' } @@ -1588,10 +1588,10 @@ test_expect_success 'fetch --tags fetches existing tags' ' git clone --bare base repo && git -C base tag tag-1 && - git -C repo for-each-ref >out && + git --git-dir=repo for-each-ref >out && test_grep ! "tag-1" out && - git -C repo fetch --tags && - git -C repo for-each-ref >out && + git --git-dir=repo fetch --tags && + git --git-dir=repo for-each-ref >out && test_grep "tag-1" out ' @@ -1605,15 +1605,15 @@ test_expect_success 'fetch --tags fetches non-conflicting tags' ' git clone --bare base repo && git -C base tag tag-2 && - git -C repo for-each-ref >out && + git --git-dir=repo for-each-ref >out && test_grep ! "tag-2" out && git -C base commit --allow-empty -m "second empty-commit" && git -C base tag -f tag-1 && - test_must_fail git -C repo fetch --tags 2>out && + test_must_fail git --git-dir=repo fetch --tags 2>out && test_grep "tag-1 (would clobber existing tag)" out && - git -C repo for-each-ref >out && + git --git-dir=repo for-each-ref >out && test_grep "tag-2" out ' diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh index 29e2f176081561..c6ef4691ebf6de 100755 --- a/t/t5516-fetch-push.sh +++ b/t/t5516-fetch-push.sh @@ -1534,18 +1534,18 @@ test_expect_success 'pushing a tag pushes the tagged object' ' test_expect_success 'push into bare respects core.logallrefupdates' ' test_when_finished "rm -rf dst.git" && git init --bare dst.git && - git -C dst.git config core.logallrefupdates true && + git --git-dir=dst.git config core.logallrefupdates true && # double push to test both with and without # the actual pack transfer git push dst.git main:one && echo "one@{0} push" >expect && - git -C dst.git log -g --format="%gd %gs" one >actual && + git --git-dir=dst.git log -g --format="%gd %gs" one >actual && test_cmp expect actual && git push dst.git main:two && echo "two@{0} push" >expect && - git -C dst.git log -g --format="%gd %gs" two >actual && + git --git-dir=dst.git log -g --format="%gd %gs" two >actual && test_cmp expect actual ' @@ -1806,11 +1806,11 @@ test_expect_success 'denyCurrentBranch and worktrees' ' test_expect_success 'denyCurrentBranch and bare repository worktrees' ' test_when_finished "rm -fr bare.git" && git clone --bare . bare.git && - git -C bare.git worktree add wt && + git --git-dir=bare.git worktree add bare.git/wt && test_commit grape && - git -C bare.git config receive.denyCurrentBranch refuse && + git --git-dir=bare.git config receive.denyCurrentBranch refuse && test_must_fail git push bare.git HEAD:wt && - git -C bare.git config receive.denyCurrentBranch updateInstead && + git --git-dir=bare.git config receive.denyCurrentBranch updateInstead && git push bare.git HEAD:wt && test_path_exists bare.git/wt/grape.t && test_must_fail git push --delete bare.git wt @@ -1827,10 +1827,10 @@ test_expect_success 'refuse fetch to current branch of worktree' ' test_expect_success 'refuse fetch to current branch of bare repository worktree' ' test_when_finished "rm -fr bare.git" && git clone --bare . bare.git && - git -C bare.git worktree add wt && + git --git-dir=bare.git worktree add bare.git/wt && test_commit banana && - test_must_fail git -C bare.git fetch .. HEAD:wt && - git -C bare.git fetch -u .. HEAD:wt + test_must_fail git --git-dir=bare.git fetch . HEAD:wt && + git --git-dir=bare.git fetch -u . HEAD:wt ' test_expect_success 'refuse to push a hidden ref, and make sure do not pollute the repository' ' diff --git a/t/t5531-deep-submodule-push.sh b/t/t5531-deep-submodule-push.sh index 05debd1134db49..68019934423908 100755 --- a/t/t5531-deep-submodule-push.sh +++ b/t/t5531-deep-submodule-push.sh @@ -485,8 +485,8 @@ test_expect_success 'push --dry-run does not recursively update submodules' ' git commit -m "Ninth commit for gar/bage" && git push --dry-run --recurse-submodules=on-demand ../pub.git main ) && - git -C submodule.git rev-parse main >actual_submodule && - git -C pub.git rev-parse main >actual_pub && + git --git-dir=submodule.git rev-parse main >actual_submodule && + git --git-dir=pub.git rev-parse main >actual_pub && test_cmp expected_pub actual_pub && test_cmp expected_submodule actual_submodule ' @@ -494,20 +494,20 @@ test_expect_success 'push --dry-run does not recursively update submodules' ' test_expect_success 'push --dry-run does not recursively update submodules' ' git -C work push --dry-run --recurse-submodules=only ../pub.git main && - git -C submodule.git rev-parse main >actual_submodule && - git -C pub.git rev-parse main >actual_pub && + git --git-dir=submodule.git rev-parse main >actual_submodule && + git --git-dir=pub.git rev-parse main >actual_pub && test_cmp expected_pub actual_pub && test_cmp expected_submodule actual_submodule ' test_expect_success 'push only unpushed submodules recursively' ' git -C work/gar/bage rev-parse main >expected_submodule && - git -C pub.git rev-parse main >expected_pub && + git --git-dir=pub.git rev-parse main >expected_pub && git -C work push --recurse-submodules=only ../pub.git main && - git -C submodule.git rev-parse main >actual_submodule && - git -C pub.git rev-parse main >actual_pub && + git --git-dir=submodule.git rev-parse main >actual_submodule && + git --git-dir=pub.git rev-parse main >actual_pub && test_cmp expected_submodule actual_submodule && test_cmp expected_pub actual_pub ' @@ -577,8 +577,8 @@ test_expect_success 'push propagating the remotes name to a submodule' ' # Succeeds when submodules has matching remote and refspec git -C work push --recurse-submodules=on-demand origin main && - git -C submodule.git rev-parse main >actual_submodule && - git -C pub.git rev-parse main >actual_pub && + git --git-dir=submodule.git rev-parse main >actual_submodule && + git --git-dir=pub.git rev-parse main >actual_pub && git -C work/gar/bage rev-parse main >expected_submodule && git -C work rev-parse main >expected_pub && test_cmp expected_submodule actual_submodule && @@ -607,8 +607,8 @@ test_expect_success 'push propagating refspec to a submodule' ' git -C work/gar/bage branch branch2 main && git -C work push --recurse-submodules=on-demand origin branch2 && - git -C submodule.git rev-parse branch2 >actual_submodule && - git -C pub.git rev-parse branch2 >actual_pub && + git --git-dir=submodule.git rev-parse branch2 >actual_submodule && + git --git-dir=pub.git rev-parse branch2 >actual_pub && git -C work/gar/bage rev-parse branch2 >expected_submodule && git -C work rev-parse branch2 >expected_pub && test_cmp expected_submodule actual_submodule && @@ -629,8 +629,8 @@ test_expect_success 'push propagating HEAD refspec to a submodule' ' git -C work push --recurse-submodules=on-demand origin \ HEAD:refs/heads/branch2 && - git -C submodule.git rev-parse branch2 >actual_submodule && - git -C pub.git rev-parse branch2 >actual_pub && + git --git-dir=submodule.git rev-parse branch2 >actual_submodule && + git --git-dir=pub.git rev-parse branch2 >actual_pub && git -C work/gar/bage rev-parse branch2 >expected_submodule && git -C work rev-parse branch2 >expected_pub && test_cmp expected_submodule actual_submodule && diff --git a/t/t5544-pack-objects-hook.sh b/t/t5544-pack-objects-hook.sh index 89147a052e72cd..1d74afa699d91e 100755 --- a/t/t5544-pack-objects-hook.sh +++ b/t/t5544-pack-objects-hook.sh @@ -70,8 +70,8 @@ test_expect_success 'hook works with partial clone' ' test_config_global uploadpack.packObjectsHook ./hook && test_config_global uploadpack.allowFilter true && git clone --bare --no-local --filter=blob:none . dst.git && - git -C dst.git rev-list --objects --missing=allow-any --no-object-names --all >objects && - git -C dst.git cat-file --batch-check="%(objecttype)" types && + git --git-dir=dst.git rev-list --objects --missing=allow-any --no-object-names --all >objects && + git --git-dir=dst.git cat-file --batch-check="%(objecttype)" types && ! grep blob types ' diff --git a/t/t5545-push-options.sh b/t/t5545-push-options.sh index fb13549da7f305..ec11ecc0a24f58 100755 --- a/t/t5545-push-options.sh +++ b/t/t5545-push-options.sh @@ -261,7 +261,7 @@ test_expect_success 'push options work properly across http' ' test_commit -C test_http_clone one && git -C test_http_clone push origin main && - git -C "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git rev-parse --verify main >expect && + git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git rev-parse --verify main >expect && git -C test_http_clone rev-parse --verify main >actual && test_cmp expect actual && @@ -271,7 +271,7 @@ test_expect_success 'push options work properly across http' ' test_cmp expect "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git/hooks/pre-receive.push_options && test_cmp expect "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git/hooks/post-receive.push_options && - git -C "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git rev-parse --verify main >expect && + git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git rev-parse --verify main >expect && git -C test_http_clone rev-parse --verify main >actual && test_cmp expect actual ' diff --git a/t/t5546-receive-limits.sh b/t/t5546-receive-limits.sh index f1e61c9f09572e..dc1d1964583706 100755 --- a/t/t5546-receive-limits.sh +++ b/t/t5546-receive-limits.sh @@ -9,7 +9,7 @@ test_description='check receive input limits' # When the limit is 10000, `git receive-pack` will call `git unpack-objects`. validate_store_type () { - git -C dest count-objects -v >actual && + git --git-dir=dest count-objects -v >actual && case "$store_type" in index) grep "^count: 0$" actual ;; diff --git a/t/t5547-push-quarantine.sh b/t/t5547-push-quarantine.sh index 7133debc12ce1b..a33eaa593866ab 100755 --- a/t/t5547-push-quarantine.sh +++ b/t/t5547-push-quarantine.sh @@ -6,7 +6,7 @@ test_description='check quarantine of objects during push' test_expect_success 'create picky dest repo' ' git init --bare dest.git && - test_hook --setup -C dest.git pre-receive <<-\EOF + test_hook --setup --git-dir dest.git pre-receive <<-\EOF while read old new ref; do test "$(git log -1 --format=%s $new)" = reject && exit 1 done diff --git a/t/t5548-push-porcelain.sh b/t/t5548-push-porcelain.sh index 4c19404ebe9be6..0b4181d11de9b9 100755 --- a/t/t5548-push-porcelain.sh +++ b/t/t5548-push-porcelain.sh @@ -83,7 +83,7 @@ setup_upstream () { # The upstream repository provides services using the HTTP protocol. if ! test "$1" = "upstream.git" then - git -C "$1" config http.receivepack true + git --git-dir="$1" config http.receivepack true fi } @@ -153,7 +153,7 @@ run_git_push_porcelain_output_test() { EOF test_cmp expect actual && - git -C "$upstream" show-ref >out && + git --git-dir="$upstream" show-ref >out && make_user_friendly_and_stable_output actual && cat >expect <<-EOF && refs/heads/bar @@ -187,7 +187,7 @@ run_git_push_porcelain_output_test() { EOF test_cmp expect actual && - git -C "$upstream" show-ref >out && + git --git-dir="$upstream" show-ref >out && make_user_friendly_and_stable_output actual && cat >expect <<-EOF && refs/heads/bar @@ -221,7 +221,7 @@ run_git_push_porcelain_output_test() { EOF test_cmp expect actual && - git -C "$upstream" show-ref >out && + git --git-dir="$upstream" show-ref >out && make_user_friendly_and_stable_output actual && cat >expect <<-EOF && refs/heads/bar @@ -238,7 +238,7 @@ run_git_push_porcelain_output_test() { test_expect_success ".. pre-receive hook declined ($PROTOCOL)" ' test_when_finished "rm -f \"$upstream/hooks/pre-receive\" && setup_upstream \"$upstream\"" && - test_hook --setup -C "$upstream" pre-receive <<-EOF && + test_hook --setup --git-dir "$upstream" pre-receive <<-EOF && exit 1 EOF test_must_fail git -C workbench push --porcelain --force origin \ @@ -259,7 +259,7 @@ run_git_push_porcelain_output_test() { EOF test_cmp expect actual && - git -C "$upstream" show-ref >out && + git --git-dir="$upstream" show-ref >out && make_user_friendly_and_stable_output actual && cat >expect <<-EOF && refs/heads/bar @@ -290,7 +290,7 @@ run_git_push_porcelain_output_test() { EOF test_cmp expect actual && - git -C "$upstream" show-ref >out && + git --git-dir="$upstream" show-ref >out && make_user_friendly_and_stable_output actual && cat >expect <<-EOF && refs/heads/bar @@ -324,7 +324,7 @@ run_git_push_porcelain_output_test() { EOF test_cmp expect actual && - git -C "$upstream" show-ref >out && + git --git-dir="$upstream" show-ref >out && make_user_friendly_and_stable_output actual && cat >expect <<-EOF && refs/heads/bar @@ -370,7 +370,7 @@ run_git_push_dry_run_porcelain_output_test() { EOF test_cmp expect actual && - git -C "$upstream" show-ref >out && + git --git-dir="$upstream" show-ref >out && make_user_friendly_and_stable_output actual && cat >expect <<-EOF && refs/heads/bar @@ -403,7 +403,7 @@ run_git_push_dry_run_porcelain_output_test() { EOF test_cmp expect actual && - git -C "$upstream" show-ref >out && + git --git-dir="$upstream" show-ref >out && make_user_friendly_and_stable_output actual && cat >expect <<-EOF && refs/heads/bar @@ -436,7 +436,7 @@ run_git_push_dry_run_porcelain_output_test() { EOF test_cmp expect actual && - git -C "$upstream" show-ref >out && + git --git-dir="$upstream" show-ref >out && make_user_friendly_and_stable_output actual && cat >expect <<-EOF && refs/heads/bar @@ -469,7 +469,7 @@ run_git_push_dry_run_porcelain_output_test() { EOF test_cmp expect actual && - git -C "$upstream" show-ref >out && + git --git-dir="$upstream" show-ref >out && make_user_friendly_and_stable_output actual && cat >expect <<-EOF && refs/heads/bar diff --git a/t/t5570-git-daemon.sh b/t/t5570-git-daemon.sh index 8df4001b7221e4..1a8d4a250810f7 100755 --- a/t/t5570-git-daemon.sh +++ b/t/t5570-git-daemon.sh @@ -228,7 +228,7 @@ test_expect_success FAKENC 'hostname interpolation works after LF-stripping' ' # just pick out the value of main, which avoids any protocol # particulars perl -lne "print \$1 if m{^(\\S+) refs/heads/main}" actual && - git -C "$repo" rev-parse main >expect && + git --git-dir="$repo" rev-parse main >expect && test_cmp expect actual ' diff --git a/t/t5583-push-branches.sh b/t/t5583-push-branches.sh index e7e1b6dab66fb3..5a5f0e2e69da3c 100755 --- a/t/t5583-push-branches.sh +++ b/t/t5583-push-branches.sh @@ -15,12 +15,12 @@ delete_refs() { do echo "delete ${arg}" >>deletes done - git -C $dir update-ref --stdin < deletes + git --git-dir=$dir update-ref --stdin < deletes } test_expect_success 'setup bare remote' ' git init --bare remote-1 && - git -C remote-1 config gc.auto 0 && + git --git-dir=remote-1 config gc.auto 0 && test_commit one && git push remote-1 HEAD ' @@ -48,10 +48,10 @@ test_expect_success '--all and --branches have the same behavior' ' $commit refs/heads/main EOF - git -C remote-1 show-ref --heads >actual.all && + git --git-dir=remote-1 show-ref --heads >actual.all && delete_refs remote-1 refs/heads/branch-1 refs/heads/branch-2 && git push remote-1 --branches && - git -C remote-1 show-ref --heads >actual.branches && + git --git-dir=remote-1 show-ref --heads >actual.branches && test_cmp actual.all actual.branches && test_cmp expect actual.all ' @@ -92,7 +92,7 @@ test_expect_success '--all or --branches combines with --follow-tags have same b refs/tags/annotated-1 \ refs/tags/annotated-2" && git push remote-1 --all --follow-tags && - git -C remote-1 show-ref > actual.all && + git --git-dir=remote-1 show-ref > actual.all && cat >expect <<-EOF && $commit refs/heads/branch-1 $commit refs/heads/branch-2 @@ -107,7 +107,7 @@ test_expect_success '--all or --branches combines with --follow-tags have same b refs/tags/annotated-1 \ refs/tags/annotated-2 && git push remote-1 --branches --follow-tags && - git -C remote-1 show-ref >actual.branches && + git --git-dir=remote-1 show-ref >actual.branches && test_cmp actual.all actual.branches && test_cmp expect actual.all ' diff --git a/t/t5601-clone.sh b/t/t5601-clone.sh index d743d986c401a0..2ff7bdf8e56985 100755 --- a/t/t5601-clone.sh +++ b/t/t5601-clone.sh @@ -168,7 +168,7 @@ test_expect_success 'clone with files ref format' ' test_when_finished "rm -rf ref-storage" && git clone --ref-format=files --mirror src ref-storage && echo files >expect && - git -C ref-storage rev-parse --show-ref-format >actual && + git --git-dir=ref-storage rev-parse --show-ref-format >actual && test_cmp expect actual ' @@ -646,7 +646,7 @@ test_expect_success 'GIT_TRACE_PACKFILE produces a usable pack' ' rm -rf dst.git && GIT_TRACE_PACKFILE=$PWD/tmp.pack git clone --no-local --bare src dst.git && git init --bare replay.git && - git -C replay.git index-pack -v --stdin expect && - git -C a.git config --bool core.bare >actual && + git --git-dir=a.git config --bool core.bare >actual && test_cmp expect actual && echo true >expect && - git -C x config --bool core.bare >actual && + git --git-dir=x config --bool core.bare >actual && test_cmp expect actual && git bundle create b1.bundle --all && git bundle create b2.bundle main && @@ -65,7 +65,7 @@ test_expect_success 'Even without -l, local will make a hardlink' ' ' test_expect_success 'local clone of repo with nonexistent ref in HEAD' ' - git -C a.git symbolic-ref HEAD refs/heads/nonexistent && + git --git-dir=a.git symbolic-ref HEAD refs/heads/nonexistent && git clone a d && (cd d && git fetch && diff --git a/t/t5606-clone-options.sh b/t/t5606-clone-options.sh index 96e416642e0d4c..cf5481f7799cdb 100755 --- a/t/t5606-clone-options.sh +++ b/t/t5606-clone-options.sh @@ -46,7 +46,7 @@ test_expect_success 'clone --bare -o' ' git clone -o foo --bare parent clone-bare-o && (cd parent && pwd) >expect && - git -C clone-bare-o config remote.foo.url >actual && + git --git-dir=clone-bare-o config remote.foo.url >actual && test_cmp expect actual ' @@ -190,7 +190,7 @@ test_expect_success 'guesses initial branch name correctly' ' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \ git clone no-head is-it2 && test_must_fail git -C is-it2 symbolic-ref refs/remotes/origin/HEAD && - git -C no-head update-ref --no-deref HEAD refs/heads/guess && + git --git-dir=no-head update-ref --no-deref HEAD refs/heads/guess && GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \ git -c init.defaultBranch=guess clone no-head is-it3 && test refs/remotes/origin/guess = \ diff --git a/t/t5613-info-alternate.sh b/t/t5613-info-alternate.sh index c752804a8e90cc..a2a7948d5137cf 100755 --- a/t/t5613-info-alternate.sh +++ b/t/t5613-info-alternate.sh @@ -115,7 +115,7 @@ test_expect_success 'relative duplicates are eliminated' ' alternate: $(pwd)/B/.git/objects alternate: $(pwd)/A/.git/objects EOF - git -C deep/subdir/duplicate.git count-objects -v >actual && + git --git-dir=deep/subdir/duplicate.git count-objects -v >actual && grep ^alternate: actual >actual.alternates && test_cmp expect actual.alternates ' @@ -132,7 +132,7 @@ test_expect_success CASE_INSENSITIVE_FS 'dup finding can be case-insensitive' ' alternate: $(pwd)/B/.git/objects alternate: $(pwd)/A/.git/objects EOF - git -C insensitive.git count-objects -v >actual && + git --git-dir=insensitive.git count-objects -v >actual && grep ^alternate: actual >actual.alternates && test_cmp expect actual.alternates ' diff --git a/t/t5615-alternate-env.sh b/t/t5615-alternate-env.sh index 9d6aa2187f2aaa..53e81b73fb28b5 100755 --- a/t/t5615-alternate-env.sh +++ b/t/t5615-alternate-env.sh @@ -19,9 +19,9 @@ check_obj () { test_expect_success 'create alternate repositories' ' git init --bare one.git && - one=$(echo one | git -C one.git hash-object -w --stdin) && + one=$(echo one | git --git-dir=one.git hash-object -w --stdin) && git init --bare two.git && - two=$(echo two | git -C two.git hash-object -w --stdin) + two=$(echo two | git --git-dir=two.git hash-object -w --stdin) ' test_expect_success 'objects inaccessible without alternates' ' diff --git a/t/t5616-partial-clone.sh b/t/t5616-partial-clone.sh index 35fa36ef9b3541..bfd9853fb11ef6 100755 --- a/t/t5616-partial-clone.sh +++ b/t/t5616-partial-clone.sh @@ -28,8 +28,8 @@ test_expect_success 'setup normal src repo' ' # bare clone "src" giving "srv.bare" for use as our server. test_expect_success 'setup bare clone for server' ' git clone --bare "file://$(pwd)/src" srv.bare && - git -C srv.bare config --local uploadpack.allowfilter 1 && - git -C srv.bare config --local uploadpack.allowanysha1inwant 1 + git --git-dir=srv.bare config --local uploadpack.allowfilter 1 && + git --git-dir=srv.bare config --local uploadpack.allowanysha1inwant 1 ' # do basic partial clone from "srv.bare" @@ -59,7 +59,7 @@ test_expect_success 'rev-list --missing=allow-promisor on partial clone' ' test_expect_success 'verify that .promisor file contains refs fetched' ' ls pc1/.git/objects/pack/pack-*.promisor >promisorlist && test_line_count = 1 promisorlist && - git -C srv.bare rev-parse --verify HEAD >headhash && + git --git-dir=srv.bare rev-parse --verify HEAD >headhash && grep "$(cat headhash) HEAD" $(cat promisorlist) && grep "$(cat headhash) refs/heads/main" $(cat promisorlist) ' @@ -335,14 +335,14 @@ test_expect_success 'implicitly construct combine: filter with repeated flags' ' "file://$(pwd)/srv.bare" pc2 && grep "trace:.* git pack-objects .*--filter=combine:blob:none+tree:1" \ trace && - git -C pc2 rev-list --objects --missing=allow-any HEAD >objects && + git --git-dir=pc2 rev-list --objects --missing=allow-any HEAD >objects && # We should have gotten some root trees. grep " $" objects && # Should not have gotten any non-root trees or blobs. ! grep " ." objects && - xargs -n 1 git -C pc2 cat-file -t types && + xargs -n 1 git --git-dir=pc2 cat-file -t types && sort -u types >unique_types.actual && test_write_lines commit tree >unique_types.expected && test_cmp unique_types.expected unique_types.actual @@ -423,10 +423,10 @@ test_expect_success 'fetch what is specified on CLI even if already promised' ' git hash-object --stdin blob && git clone --bare --filter=blob:none "file://$(pwd)/src" dst.git && - git -C dst.git rev-list --objects --quiet --missing=print HEAD >missing_before && + git --git-dir=dst.git rev-list --objects --quiet --missing=print HEAD >missing_before && grep "?$(cat blob)" missing_before && - git -C dst.git fetch origin $(cat blob) && - git -C dst.git rev-list --objects --quiet --missing=print HEAD >missing_after && + git --git-dir=dst.git fetch origin $(cat blob) && + git --git-dir=dst.git rev-list --objects --quiet --missing=print HEAD >missing_after && ! grep "?$(cat blob)" missing_after ' @@ -501,7 +501,7 @@ setup_triangle () { # for this tree or blob. test_commit -C promisor-remote one && # so that ref advertisement is not empty git -C promisor-remote config --local uploadpack.allowanysha1inwant 1 && - git -C client remote set-url origin "file://$(pwd)/promisor-remote" + git --git-dir=client remote set-url origin "file://$(pwd)/promisor-remote" } # NEEDSWORK: The tests beginning with "fetch lazy-fetches" below only @@ -515,7 +515,7 @@ test_expect_success 'fetch lazy-fetches only to resolve deltas' ' # Exercise to make sure it works. Git will not fetch anything from the # promisor remote other than for the big tree (because it needs to # resolve the delta). - GIT_TRACE_PACKET="$(pwd)/trace" git -C client \ + GIT_TRACE_PACKET="$(pwd)/trace" git --git-dir=client \ fetch "file://$(pwd)/server" main && # Verify the assumption that the client needed to fetch the delta base @@ -528,13 +528,13 @@ test_expect_success 'fetch lazy-fetches only to resolve deltas, protocol v2' ' setup_triangle && git -C server config --local protocol.version 2 && - git -C client config --local protocol.version 2 && + git --git-dir=client config --local protocol.version 2 && git -C promisor-remote config --local protocol.version 2 && # Exercise to make sure it works. Git will not fetch anything from the # promisor remote other than for the big blob (because it needs to # resolve the delta). - GIT_TRACE_PACKET="$(pwd)/trace" git -C client \ + GIT_TRACE_PACKET="$(pwd)/trace" git --git-dir=client \ fetch "file://$(pwd)/server" main && # Verify that protocol version 2 was used. @@ -577,7 +577,7 @@ test_expect_success 'verify fetch succeeds when asking for new tags' ' test_commit -C src $i && git -C src branch $i || return 1 done && - git -C srv.bare fetch --tags origin +refs/heads/*:refs/heads/* && + git --git-dir=srv.bare fetch --tags origin +refs/heads/*:refs/heads/* && git -C tag-test -c protocol.version=2 fetch --tags origin ' @@ -591,7 +591,7 @@ test_expect_success 'verify fetch downloads only one pack when updating refs' ' test_commit -C src $i && git -C src branch $i || return 1 done && - git -C srv.bare fetch origin +refs/heads/*:refs/heads/* && + git --git-dir=srv.bare fetch origin +refs/heads/*:refs/heads/* && git -C pack-test fetch origin && ls pack-test/.git/objects/pack/*pack >pack-list && test_line_count = 3 pack-list @@ -647,7 +647,7 @@ test_expect_success 'repack does not loosen promisor objects' ' rm -rf client trace && git clone --bare --filter=blob:none "file://$(pwd)/srv.bare" client && test_when_finished "rm -rf client trace" && - GIT_TRACE2_PERF="$(pwd)/trace" git -C client repack -A -d && + GIT_TRACE2_PERF="$(pwd)/trace" git --git-dir=client repack -A -d && grep "loosen_unused_packed_objects/loosened:0" trace ' diff --git a/t/t5617-clone-submodules-remote.sh b/t/t5617-clone-submodules-remote.sh index 688433824934d8..844620733e8059 100755 --- a/t/t5617-clone-submodules-remote.sh +++ b/t/t5617-clone-submodules-remote.sh @@ -32,8 +32,8 @@ test_expect_success 'setup' ' # bare clone giving "srv.bare" for use as our server. test_expect_success 'setup bare clone for server' ' git clone --bare "file://$(pwd)/." srv.bare && - git -C srv.bare config --local uploadpack.allowfilter 1 && - git -C srv.bare config --local uploadpack.allowanysha1inwant 1 + git --git-dir=srv.bare config --local uploadpack.allowfilter 1 && + git --git-dir=srv.bare config --local uploadpack.allowanysha1inwant 1 ' test_expect_success 'clone with --no-remote-submodules' ' diff --git a/t/t5619-clone-local-ambiguous-transport.sh b/t/t5619-clone-local-ambiguous-transport.sh index cce62bf78d3351..ef69432465f89b 100755 --- a/t/t5619-clone-local-ambiguous-transport.sh +++ b/t/t5619-clone-local-ambiguous-transport.sh @@ -21,10 +21,10 @@ test_expect_success 'setup' ' echo "secret" >sensitive/secret && git init --bare "$REPO" && - test_commit_bulk -C "$REPO" --ref=main 1 && + (GIT_DIR="$REPO" && export GIT_DIR && test_commit_bulk --ref=main 1) && - git -C "$REPO" update-ref HEAD main && - git -C "$REPO" update-server-info && + git --git-dir="$REPO" update-ref HEAD main && + git --git-dir="$REPO" update-server-info && git init malicious && ( @@ -48,9 +48,9 @@ test_expect_success 'setup' ' # avoid the client attempting to checkout any objects (which # will be missing, and thus will cause the clone to fail before # we can trigger the exploit). - git -C "$REPO" for-each-ref --format="delete %(refname)" >in && - git -C "$REPO" update-ref --stdin in && + git --git-dir="$REPO" update-ref --stdin actual && + git --git-dir=dst cat-file -t $oid >actual && echo "commit" >expect && test_cmp expect actual && - git -C dst for-each-ref refs >expect && + git --git-dir=dst for-each-ref refs >expect && test_must_be_empty expect && - test_must_fail git -C dst config remote.origin.fetch + test_must_fail git --git-dir=dst config remote.origin.fetch ' test_expect_success 'clone with --revision being a short raw commit hash' ' diff --git a/t/t5702-protocol-v2.sh b/t/t5702-protocol-v2.sh index f826ac46a5be5a..4c365fbd3ab2a3 100755 --- a/t/t5702-protocol-v2.sh +++ b/t/t5702-protocol-v2.sh @@ -289,7 +289,7 @@ test_expect_success 'bare clone propagates empty default branch' ' clone --bare \ "file://$(pwd)/file_empty_parent" file_empty_child.git && echo "refs/heads/mydefaultbranch" >expect && - git -C file_empty_child.git symbolic-ref HEAD >actual && + git --git-dir=file_empty_child.git symbolic-ref HEAD >actual && test_cmp expect actual ' @@ -341,7 +341,7 @@ test_expect_success 'bare clone propagates unborn HEAD from non-empty repo' ' clone --bare "file://$(pwd)/file_unborn_parent" \ file_unborn_child.git 2>stderr && echo "refs/heads/mydefaultbranch" >expect && - git -C file_unborn_child.git symbolic-ref HEAD >actual && + git --git-dir=file_unborn_child.git symbolic-ref HEAD >actual && test_cmp expect actual && ! grep "warning:" stderr ' diff --git a/t/t5710-promisor-remote-capability.sh b/t/t5710-promisor-remote-capability.sh index af9f8304a353ef..a6a78196c67948 100755 --- a/t/t5710-promisor-remote-capability.sh +++ b/t/t5710-promisor-remote-capability.sh @@ -30,11 +30,11 @@ test_expect_success 'setup: create bare "server" repository' ' git clone --bare --no-local template server && mv server/objects/pack/pack-* . && packfile=$(ls pack-*.pack) && - git -C server unpack-objects --strict <"$packfile" + git --git-dir=server unpack-objects --strict <"$packfile" ' check_missing_objects () { - git -C "$1" rev-list --objects --all --missing=print > all.txt && + git --git-dir="$1" rev-list --objects --all --missing=print > all.txt && perl -ne 'print if s/^[?]//' all.txt >missing.txt && test_line_count = "$2" missing.txt && if test "$2" -lt 2 @@ -53,13 +53,13 @@ initialize_server () { missing_oids="$2" # Repack everything first - git -C server -c repack.writebitmaps=false repack -a -d && + git --git-dir=server -c repack.writebitmaps=false repack -a -d && # Remove promisor file in case they exist, useful when reinitializing rm -rf server/objects/pack/*.promisor && # Repack without the largest object and create a promisor pack on server - git -C server -c repack.writebitmaps=false repack -a -d \ + git --git-dir=server -c repack.writebitmaps=false repack -a -d \ --filter=blob:limit=5k --filter-to="$(pwd)/pack" && promisor_file=$(ls server/objects/pack/*.pack | sed "s/\.pack/.promisor/") && >"$promisor_file" && @@ -82,23 +82,23 @@ test_expect_success "setup for testing promisor remote advertisement" ' # Copy the largest object from server to lop obj="HEAD:foo" && - oid="$(git -C server rev-parse $obj)" && + oid="$(git --git-dir=server rev-parse $obj)" && copy_to_lop "$oid" && initialize_server 1 "$oid" && # Configure lop as promisor remote for server - git -C server remote add lop "file://$(pwd)/lop" && - git -C server config remote.lop.promisor true && + git --git-dir=server remote add lop "file://$(pwd)/lop" && + git --git-dir=server config remote.lop.promisor true && - git -C lop config uploadpack.allowFilter true && - git -C lop config uploadpack.allowAnySHA1InWant true && - git -C server config uploadpack.allowFilter true && - git -C server config uploadpack.allowAnySHA1InWant true + git --git-dir=lop config uploadpack.allowFilter true && + git --git-dir=lop config uploadpack.allowAnySHA1InWant true && + git --git-dir=server config uploadpack.allowFilter true && + git --git-dir=server config uploadpack.allowAnySHA1InWant true ' test_expect_success "clone with promisor.advertise set to 'true'" ' - git -C server config promisor.advertise true && + git --git-dir=server config promisor.advertise true && test_when_finished "rm -rf client" && # Clone from server to create a client @@ -113,7 +113,7 @@ test_expect_success "clone with promisor.advertise set to 'true'" ' ' test_expect_success "clone with promisor.advertise set to 'false'" ' - git -C server config promisor.advertise false && + git --git-dir=server config promisor.advertise false && test_when_finished "rm -rf client" && # Clone from server to create a client @@ -131,7 +131,7 @@ test_expect_success "clone with promisor.advertise set to 'false'" ' ' test_expect_success "clone with promisor.acceptfromserver set to 'None'" ' - git -C server config promisor.advertise true && + git --git-dir=server config promisor.advertise true && test_when_finished "rm -rf client" && # Clone from server to create a client @@ -149,7 +149,7 @@ test_expect_success "clone with promisor.acceptfromserver set to 'None'" ' ' test_expect_success "init + fetch with promisor.advertise set to 'true'" ' - git -C server config promisor.advertise true && + git --git-dir=server config promisor.advertise true && test_when_finished "rm -rf client" && mkdir client && @@ -167,7 +167,7 @@ test_expect_success "init + fetch with promisor.advertise set to 'true'" ' ' test_expect_success "clone with promisor.acceptfromserver set to 'KnownName'" ' - git -C server config promisor.advertise true && + git --git-dir=server config promisor.advertise true && test_when_finished "rm -rf client" && # Clone from server to create a client @@ -182,7 +182,7 @@ test_expect_success "clone with promisor.acceptfromserver set to 'KnownName'" ' ' test_expect_success "clone with 'KnownName' and different remote names" ' - git -C server config promisor.advertise true && + git --git-dir=server config promisor.advertise true && test_when_finished "rm -rf client" && # Clone from server to create a client @@ -200,7 +200,7 @@ test_expect_success "clone with 'KnownName' and different remote names" ' ' test_expect_success "clone with 'KnownName' and missing URL in the config" ' - git -C server config promisor.advertise true && + git --git-dir=server config promisor.advertise true && test_when_finished "rm -rf client" && # Clone from server to create a client @@ -219,7 +219,7 @@ test_expect_success "clone with 'KnownName' and missing URL in the config" ' ' test_expect_success "clone with promisor.acceptfromserver set to 'KnownUrl'" ' - git -C server config promisor.advertise true && + git --git-dir=server config promisor.advertise true && test_when_finished "rm -rf client" && # Clone from server to create a client @@ -236,7 +236,7 @@ test_expect_success "clone with promisor.acceptfromserver set to 'KnownUrl'" ' test_expect_success "clone with 'KnownUrl' and different remote urls" ' ln -s lop serverTwo && - git -C server config promisor.advertise true && + git --git-dir=server config promisor.advertise true && test_when_finished "rm -rf client" && # Clone from server to create a client @@ -254,11 +254,11 @@ test_expect_success "clone with 'KnownUrl' and different remote urls" ' ' test_expect_success "clone with 'KnownUrl' and url not configured on the server" ' - git -C server config promisor.advertise true && + git --git-dir=server config promisor.advertise true && test_when_finished "rm -rf client" && - test_when_finished "git -C server config set remote.lop.url \"file://$(pwd)/lop\"" && - git -C server config unset remote.lop.url && + test_when_finished "git --git-dir=server config set remote.lop.url \"file://$(pwd)/lop\"" && + git --git-dir=server config unset remote.lop.url && # Clone from server to create a client # It should fail because the client will reject the LOP as URLs are @@ -275,11 +275,11 @@ test_expect_success "clone with 'KnownUrl' and url not configured on the server" ' test_expect_success "clone with 'KnownUrl' and empty url, so not advertised" ' - git -C server config promisor.advertise true && + git --git-dir=server config promisor.advertise true && test_when_finished "rm -rf client" && - test_when_finished "git -C server config set remote.lop.url \"file://$(pwd)/lop\"" && - git -C server config set remote.lop.url "" && + test_when_finished "git --git-dir=server config set remote.lop.url \"file://$(pwd)/lop\"" && + git --git-dir=server config set remote.lop.url "" && # Clone from server to create a client # It should fail because the client will reject the LOP as an empty URL is @@ -409,7 +409,7 @@ test_expect_success "clone with promisor.storeFields=partialCloneFilter" ' check_missing_objects server 1 "$oid" && # Change the configuration on the server and fetch from the client - git -C server config remote.lop.partialCloneFilter "blob:limit=7k" && + git --git-dir=server config remote.lop.partialCloneFilter "blob:limit=7k" && GIT_NO_LAZY_FETCH=0 git -C client fetch \ --filter="blob:limit=5k" ../server 2>err && @@ -448,7 +448,7 @@ test_expect_success "clone and fetch with --filter=auto" ' check_missing_objects server 1 "$oid" && # Now change the filter on the server - git -C server config remote.lop.partialCloneFilter "blob:limit=5678" && + git --git-dir=server config remote.lop.partialCloneFilter "blob:limit=5678" && # Get a new commit on the server to ensure "git fetch" actually runs fetch-pack test_commit -C template new-commit && @@ -465,7 +465,7 @@ test_expect_success "clone and fetch with --filter=auto" ' check_missing_objects server 1 "$oid" && # Change the filter on the server again - git -C server config remote.lop.partialCloneFilter "blob:limit=5432" && + git --git-dir=server config remote.lop.partialCloneFilter "blob:limit=5432" && # Get yet a new commit on the server to ensure fetch-pack runs test_commit -C template yet-a-new-commit && @@ -484,7 +484,7 @@ test_expect_success "clone and fetch with --filter=auto" ' ' test_expect_success "clone with promisor.advertise set to 'true' but don't delete the client" ' - git -C server config promisor.advertise true && + git --git-dir=server config promisor.advertise true && # Clone from server to create a client GIT_NO_LAZY_FETCH=0 git clone -c remote.lop.promisor=true \ @@ -504,9 +504,9 @@ test_expect_success "setup for subsequent fetches" ' git -C template commit -m bar && # Fetch new commit with large blob - git -C server fetch origin && - git -C server update-ref HEAD FETCH_HEAD && - git -C server rev-parse HEAD >expected_head && + git --git-dir=server fetch origin && + git --git-dir=server update-ref HEAD FETCH_HEAD && + git --git-dir=server rev-parse HEAD >expected_head && # Repack everything twice and remove .promisor files before # each repack. This makes sure everything gets repacked @@ -515,19 +515,19 @@ test_expect_success "setup for subsequent fetches" ' # packfile and its associated .promisor file. rm -f server/objects/pack/*.promisor && - git -C server -c repack.writebitmaps=false repack -a -d && + git --git-dir=server -c repack.writebitmaps=false repack -a -d && rm -f server/objects/pack/*.promisor && - git -C server -c repack.writebitmaps=false repack -a -d && + git --git-dir=server -c repack.writebitmaps=false repack -a -d && # Unpack everything rm pack-* && mv server/objects/pack/pack-* . && packfile=$(ls pack-*.pack) && - git -C server unpack-objects --strict <"$packfile" && + git --git-dir=server unpack-objects --strict <"$packfile" && # Copy new large object to lop obj_bar="HEAD:bar" && - oid_bar="$(git -C server rev-parse $obj_bar)" && + oid_bar="$(git --git-dir=server rev-parse $obj_bar)" && copy_to_lop "$oid_bar" && # Reinitialize server so that the 2 largest objects are missing @@ -539,7 +539,7 @@ test_expect_success "setup for subsequent fetches" ' ' test_expect_success "subsequent fetch from a client when promisor.advertise is true" ' - git -C server config promisor.advertise true && + git --git-dir=server config promisor.advertise true && GIT_NO_LAZY_FETCH=0 git -C client pull origin && @@ -552,7 +552,7 @@ test_expect_success "subsequent fetch from a client when promisor.advertise is t ' test_expect_success "subsequent fetch from a client when promisor.advertise is false" ' - git -C server config promisor.advertise false && + git --git-dir=server config promisor.advertise false && GIT_NO_LAZY_FETCH=0 git -C client2 pull origin && diff --git a/t/t5811-proto-disable-git.sh b/t/t5811-proto-disable-git.sh index b0061e6a373f4d..fd262cd356770d 100755 --- a/t/t5811-proto-disable-git.sh +++ b/t/t5811-proto-disable-git.sh @@ -13,7 +13,7 @@ test_expect_success 'create git-accessible repo' ' git --bare init "$bare" && git push "$bare" HEAD && >"$bare/git-daemon-export-ok" && - git -C "$bare" config daemon.receivepack true + git --git-dir="$bare" config daemon.receivepack true ' test_proto "git://" git "$GIT_DAEMON_URL/repo.git" diff --git a/t/t5812-proto-disable-http.sh b/t/t5812-proto-disable-http.sh index 96187efaa82ac6..aaaaebb6bfeac9 100755 --- a/t/t5812-proto-disable-http.sh +++ b/t/t5812-proto-disable-http.sh @@ -12,7 +12,7 @@ test_expect_success 'create git-accessible repo' ' test_commit one && git --bare init "$bare" && git push "$bare" HEAD && - git -C "$bare" config http.receivepack true + git --git-dir="$bare" config http.receivepack true ' test_proto "smart http" http "$HTTPD_URL/smart/repo.git" diff --git a/t/t6020-bundle-misc.sh b/t/t6020-bundle-misc.sh index 500c81b8a14237..842f34f038b6e4 100755 --- a/t/t6020-bundle-misc.sh +++ b/t/t6020-bundle-misc.sh @@ -452,7 +452,7 @@ test_expect_success 'create bundle 4 - with tags' ' test_expect_success 'clone from bundle' ' git clone --mirror 1.bdl mirror.git && - git -C mirror.git show-ref | + git --git-dir=mirror.git show-ref | make_user_friendly_and_stable_output >actual && cat >expect <<-\EOF && refs/heads/topic/1 @@ -526,7 +526,7 @@ test_expect_success 'full bundle upto annotated tag' ' test_expect_success 'clone from full bundle upto annotated tag' ' git clone --mirror v2.bdl tag-clone.git && - git -C tag-clone.git show-ref | + git --git-dir=tag-clone.git show-ref | make_user_friendly_and_stable_output >actual && cat >expect <<-\EOF && refs/tags/v2 diff --git a/t/t6500-gc.sh b/t/t6500-gc.sh index ea9aaad47091a4..199660f0c95737 100755 --- a/t/t6500-gc.sh +++ b/t/t6500-gc.sh @@ -190,10 +190,10 @@ test_expect_success 'one of gc.reflogExpire{Unreachable,}=never does not skip "e test_expect_success 'gc.repackFilter launches repack with a filter' ' git clone --no-local --bare . bare.git && - git -C bare.git -c gc.cruftPacks=false gc && + git --git-dir=bare.git -c gc.cruftPacks=false gc && test_stdout_line_count = 1 ls bare.git/objects/pack/*.pack && - GIT_TRACE=$(pwd)/trace.out git -C bare.git -c gc.repackFilter=blob:none \ + GIT_TRACE=$(pwd)/trace.out git --git-dir=bare.git -c gc.repackFilter=blob:none \ -c repack.writeBitmaps=false -c gc.cruftPacks=false gc && test_stdout_line_count = 2 ls bare.git/objects/pack/*.pack && grep -E "^trace: (built-in|exec|run_command): git repack .* --filter=blob:none ?.*" trace.out diff --git a/t/t7416-submodule-dash-url.sh b/t/t7416-submodule-dash-url.sh index 3d944a00e0d8ec..6e45c526b69926 100755 --- a/t/t7416-submodule-dash-url.sh +++ b/t/t7416-submodule-dash-url.sh @@ -28,7 +28,7 @@ test_expect_success 'clone can recurse submodule' ' test_expect_success 'fsck accepts protected dash' ' test_when_finished "rm -rf dst" && git init --bare dst && - git -C dst config transfer.fsckObjects true && + git --git-dir=dst config transfer.fsckObjects true && git push dst HEAD ' @@ -47,7 +47,7 @@ test_expect_success 'clone rejects unprotected dash' ' test_expect_success 'fsck rejects unprotected dash' ' test_when_finished "rm -rf dst" && git init --bare dst && - git -C dst config transfer.fsckObjects true && + git --git-dir=dst config transfer.fsckObjects true && test_must_fail git push dst HEAD 2>err && grep gitmodulesUrl err ' @@ -77,7 +77,7 @@ test_expect_success 'fsck rejects missing URL scheme' ' git commit -m "gitmodules with missing URL scheme" && test_when_finished "rm -rf dst" && git init --bare dst && - git -C dst config transfer.fsckObjects true && + git --git-dir=dst config transfer.fsckObjects true && test_must_fail git push dst HEAD 2>err && grep gitmodulesUrl err ' @@ -93,7 +93,7 @@ test_expect_success 'fsck rejects relative URL resolving to missing scheme' ' git commit -m "gitmodules with relative URL that strips off scheme" && test_when_finished "rm -rf dst" && git init --bare dst && - git -C dst config transfer.fsckObjects true && + git --git-dir=dst config transfer.fsckObjects true && test_must_fail git push dst HEAD 2>err && grep gitmodulesUrl err ' @@ -109,7 +109,7 @@ test_expect_success 'fsck rejects empty URL scheme' ' git commit -m "gitmodules with empty URL scheme" && test_when_finished "rm -rf dst" && git init --bare dst && - git -C dst config transfer.fsckObjects true && + git --git-dir=dst config transfer.fsckObjects true && test_must_fail git push dst HEAD 2>err && grep gitmodulesUrl err ' @@ -125,7 +125,7 @@ test_expect_success 'fsck rejects relative URL resolving to empty scheme' ' git commit -m "relative gitmodules URL resolving to empty scheme" && test_when_finished "rm -rf dst" && git init --bare dst && - git -C dst config transfer.fsckObjects true && + git --git-dir=dst config transfer.fsckObjects true && test_must_fail git push dst HEAD 2>err && grep gitmodulesUrl err ' @@ -141,7 +141,7 @@ test_expect_success 'fsck rejects empty hostname' ' git commit -m "gitmodules with extra slashes" && test_when_finished "rm -rf dst" && git init --bare dst && - git -C dst config transfer.fsckObjects true && + git --git-dir=dst config transfer.fsckObjects true && test_must_fail git push dst HEAD 2>err && grep gitmodulesUrl err ' @@ -157,7 +157,7 @@ test_expect_success 'fsck rejects relative url that produced empty hostname' ' git commit -m "gitmodules abusing relative_path" && test_when_finished "rm -rf dst" && git init --bare dst && - git -C dst config transfer.fsckObjects true && + git --git-dir=dst config transfer.fsckObjects true && test_must_fail git push dst HEAD 2>err && grep gitmodulesUrl err ' @@ -172,7 +172,7 @@ test_expect_success 'fsck permits embedded newline with unrecognized scheme' ' git commit -m "gitmodules with unrecognized scheme" && test_when_finished "rm -rf dst" && git init --bare dst && - git -C dst config transfer.fsckObjects true && + git --git-dir=dst config transfer.fsckObjects true && git push dst HEAD ' @@ -187,7 +187,7 @@ test_expect_success 'fsck rejects embedded newline in url' ' git commit -m "gitmodules with newline" && test_when_finished "rm -rf dst" && git init --bare dst && - git -C dst config transfer.fsckObjects true && + git --git-dir=dst config transfer.fsckObjects true && test_must_fail git push dst HEAD 2>err && grep gitmodulesUrl err ' @@ -202,7 +202,7 @@ test_expect_success 'fsck rejects embedded newline in relative url' ' git commit -m "relative url with newline" && test_when_finished "rm -rf dst" && git init --bare dst && - git -C dst config transfer.fsckObjects true && + git --git-dir=dst config transfer.fsckObjects true && test_must_fail git push dst HEAD 2>err && grep gitmodulesUrl err ' @@ -217,7 +217,7 @@ test_expect_success 'fsck rejects embedded newline in git url' ' git commit -m "git url with newline" && test_when_finished "rm -rf dst" && git init --bare dst && - git -C dst config transfer.fsckObjects true && + git --git-dir=dst config transfer.fsckObjects true && test_must_fail git push dst HEAD 2>err && grep gitmodulesUrl err ' diff --git a/t/t7417-submodule-path-url.sh b/t/t7417-submodule-path-url.sh index 5e3051da8bb362..d6d50353dc8c52 100755 --- a/t/t7417-submodule-path-url.sh +++ b/t/t7417-submodule-path-url.sh @@ -27,7 +27,7 @@ test_expect_success 'clone rejects unprotected dash' ' test_expect_success 'fsck rejects unprotected dash' ' test_when_finished "rm -rf dst" && git init --bare dst && - git -C dst config transfer.fsckObjects true && + git --git-dir=dst config transfer.fsckObjects true && test_must_fail git push dst HEAD 2>err && grep gitmodulesPath err ' diff --git a/t/t7450-bad-git-dotfiles.sh b/t/t7450-bad-git-dotfiles.sh index f512eed278c46b..f8e3aede1ec9fa 100755 --- a/t/t7450-bad-git-dotfiles.sh +++ b/t/t7450-bad-git-dotfiles.sh @@ -119,15 +119,15 @@ test_expect_success 'fsck detects evil superproject' ' test_expect_success 'transfer.fsckObjects detects evil superproject (unpack)' ' rm -rf dst.git && git init --bare dst.git && - git -C dst.git config transfer.fsckObjects true && + git --git-dir=dst.git config transfer.fsckObjects true && test_must_fail git push dst.git HEAD ' test_expect_success 'transfer.fsckObjects detects evil superproject (index)' ' rm -rf dst.git && git init --bare dst.git && - git -C dst.git config transfer.fsckObjects true && - git -C dst.git config transfer.unpackLimit 1 && + git --git-dir=dst.git config transfer.fsckObjects true && + git --git-dir=dst.git config transfer.unpackLimit 1 && test_must_fail git push dst.git HEAD ' @@ -151,20 +151,20 @@ test_expect_success 'create oddly ordered pack' ' test_expect_success 'transfer.fsckObjects handles odd pack (unpack)' ' rm -rf dst.git && git init --bare dst.git && - test_must_fail git -C dst.git unpack-objects --strict output && + test_must_fail git --git-dir=dst.git index-pack --strict odd.pack 2>output && # Make sure we fail due to bad gitmodules content, not because we # could not read the blob in the first place. grep gitmodulesName output diff --git a/t/t7519-status-fsmonitor.sh b/t/t7519-status-fsmonitor.sh index 7ee69ecdd4aa2c..52eabf09b23dc9 100755 --- a/t/t7519-status-fsmonitor.sh +++ b/t/t7519-status-fsmonitor.sh @@ -61,12 +61,12 @@ test_expect_success 'incompatible bare repo' ' git init --bare bare-clone && test_must_fail \ - git -C ./bare-clone -c core.fsmonitor=foo \ + git --git-dir=./bare-clone -c core.fsmonitor=foo \ update-index --fsmonitor 2>actual && grep "bare repository .* is incompatible with fsmonitor" actual && test_must_fail \ - git -C ./bare-clone -c core.fsmonitor=true \ + git --git-dir=./bare-clone -c core.fsmonitor=true \ update-index --fsmonitor 2>actual && grep "bare repository .* is incompatible with fsmonitor" actual ' @@ -74,7 +74,7 @@ test_expect_success 'incompatible bare repo' ' test_expect_success FSMONITOR_DAEMON 'run fsmonitor-daemon in bare repo' ' test_when_finished "rm -rf ./bare-clone actual" && git init --bare bare-clone && - test_must_fail git -C ./bare-clone fsmonitor--daemon run 2>actual && + test_must_fail git --git-dir=./bare-clone fsmonitor--daemon run 2>actual && grep "bare repository .* is incompatible with fsmonitor" actual ' diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index 58f43d9cf8c866..1102a9c8f757d1 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -288,18 +288,18 @@ test_expect_success 'repacking fails when missing .pack actually means missing o test_expect_success 'bitmaps are created by default in bare repos' ' git clone --bare .git bare.git && rm -f bare.git/objects/pack/*.bitmap && - git -C bare.git repack -ad && + git --git-dir=bare.git repack -ad && bitmap=$(ls bare.git/objects/pack/*.bitmap) && test_path_is_file "$bitmap" ' test_expect_success 'incremental repack does not complain' ' - git -C bare.git repack -q 2>repack.err && + git --git-dir=bare.git repack -q 2>repack.err && test_must_be_empty repack.err ' test_expect_success 'bitmaps can be disabled on bare repos' ' - git -c repack.writeBitmaps=false -C bare.git repack -ad && + git -c repack.writeBitmaps=false --git-dir=bare.git repack -ad && bitmap=$(ls bare.git/objects/pack/*.bitmap || :) && test -z "$bitmap" ' From 003746746bb759e0110e03255d87ce5d42570c4f Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 27 Mar 2026 17:44:50 +0100 Subject: [PATCH 06/11] tests: adjust relative paths when switching to `--git-dir=` A companion commit replaced `git -C ` with `git --git-dir=` for simple cases. This commit handles the cases where that substitution also requires adjusting relative paths in command arguments. The `-C` flag changes the working directory before executing the command, so arguments like `../foo` are resolved relative to the repository. The `--git-dir` flag does not change the working directory, so the same path must be expressed relative to the original directory instead, e.g. `foo` rather than `../foo`, or `c/.git` rather than `../c/.git`. Each hunk in this commit is therefore specific to its test, making the changes not amenable to a single mechanical verification command. This commit was produced with the help of Claude Opus 4.6 acting as a sophisticated keyboard. It was told to replace `git -C ` with `git --git-dir=` and to adjust every relative path that the `-C` flag would have resolved differently. The affected files are: t0001-init.sh, t0003-attributes.sh, t1091-sparse-checkout-builtin.sh, t2400-worktree-add.sh, t2402-worktree-list.sh, t3200-branch.sh, t5504-fetch-receive-strict.sh, t6020-bundle-misc.sh, t6500-gc.sh, t7412-submodule-absorbgitdirs.sh, and t9003-help-autocorrect.sh. Assisted-by: Claude Opus 4.6 Signed-off-by: Johannes Schindelin --- t/t0001-init.sh | 2 +- t/t1091-sparse-checkout-builtin.sh | 14 +++++++------- t/t2400-worktree-add.sh | 6 +++--- t/t2402-worktree-list.sh | 16 ++++++++-------- t/t3200-branch.sh | 10 +++++----- t/t5504-fetch-receive-strict.sh | 4 ++-- t/t5509-fetch-push-namespaces.sh | 10 +++++----- t/t6020-bundle-misc.sh | 16 ++++++++-------- t/t6500-gc.sh | 4 ++-- t/t7412-submodule-absorbgitdirs.sh | 2 +- t/t9003-help-autocorrect.sh | 3 ++- 11 files changed, 44 insertions(+), 43 deletions(-) diff --git a/t/t0001-init.sh b/t/t0001-init.sh index 9701a2bcd37fde..dd3884060520b2 100755 --- a/t/t0001-init.sh +++ b/t/t0001-init.sh @@ -346,7 +346,7 @@ test_expect_success 'bare & --separate-git-dir incompatible within worktree' ' test_when_finished "rm -rf bare.git linkwt seprepo" && test_commit gumby && git clone --bare . bare.git && - git -C bare.git worktree add --detach ../linkwt && + git --git-dir=bare.git worktree add --detach linkwt && test_must_fail git -C linkwt init --separate-git-dir seprepo 2>err && test_grep "incompatible" err ' diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh index a60ec5dd410213..eb5d9bc82bf27c 100755 --- a/t/t1091-sparse-checkout-builtin.sh +++ b/t/t1091-sparse-checkout-builtin.sh @@ -990,9 +990,9 @@ test_expect_success 'check-rules cone mode' ' deep/deeper1/deepest EOF - git -C bare ls-tree -r --name-only HEAD >all-files && - git -C bare sparse-checkout check-rules --cone \ - --rules-file ../rules >check-rules-file all-files && + git --git-dir=bare sparse-checkout check-rules --cone \ + --rules-file rules >check-rules-file out && @@ -1012,8 +1012,8 @@ test_expect_success 'check-rules non-cone mode' ' deep/deeper1/deepest/a EOF - git -C bare ls-tree -r --name-only HEAD >all-files && - git -C bare sparse-checkout check-rules --no-cone --rules-file ../rules\ + git --git-dir=bare ls-tree -r --name-only HEAD >all-files && + git --git-dir=bare sparse-checkout check-rules --no-cone --rules-file rules\ >check-rules-file actual actual-bare actual-bare hook.expect && - post_checkout_hook bare && - git -C bare worktree add --detach ../goozy && + post_checkout_hook --git-dir bare && + git --git-dir=bare worktree add --detach goozy && test_cmp hook.expect goozy/hook.actual ' diff --git a/t/t2402-worktree-list.sh b/t/t2402-worktree-list.sh index 9fca01a2035d21..fd6951bd565a8b 100755 --- a/t/t2402-worktree-list.sh +++ b/t/t2402-worktree-list.sh @@ -210,18 +210,18 @@ test_expect_success 'bare repo setup' ' ' test_expect_success '"list" all worktrees from bare main' ' - test_when_finished "rm -rf there out actual expect && git -C bare1 worktree prune" && - git -C bare1 worktree add --detach ../there main && + test_when_finished "rm -rf there out actual expect && git --git-dir=bare1 worktree prune" && + git --git-dir=bare1 worktree add --detach there main && echo "$(pwd)/bare1 (bare)" >expect && echo "$(git -C there rev-parse --show-toplevel) $(git -C there rev-parse --short HEAD) (detached HEAD)" >>expect && - git -C bare1 worktree list >out && + git --git-dir=bare1 worktree list >out && sed "s/ */ /g" actual && test_cmp expect actual ' test_expect_success '"list" all worktrees --porcelain from bare main' ' - test_when_finished "rm -rf there actual expect && git -C bare1 worktree prune" && - git -C bare1 worktree add --detach ../there main && + test_when_finished "rm -rf there actual expect && git --git-dir=bare1 worktree prune" && + git --git-dir=bare1 worktree add --detach there main && echo "worktree $(pwd)/bare1" >expect && echo "bare" >>expect && echo >>expect && @@ -229,13 +229,13 @@ test_expect_success '"list" all worktrees --porcelain from bare main' ' echo "HEAD $(git -C there rev-parse HEAD)" >>expect && echo "detached" >>expect && echo >>expect && - git -C bare1 worktree list --porcelain >actual && + git --git-dir=bare1 worktree list --porcelain >actual && test_cmp expect actual ' test_expect_success '"list" all worktrees from linked with a bare main' ' - test_when_finished "rm -rf there out actual expect && git -C bare1 worktree prune" && - git -C bare1 worktree add --detach ../there main && + test_when_finished "rm -rf there out actual expect && git --git-dir=bare1 worktree prune" && + git --git-dir=bare1 worktree add --detach there main && echo "$(pwd)/bare1 (bare)" >expect && echo "$(git -C there rev-parse --show-toplevel) $(git -C there rev-parse --short HEAD) (detached HEAD)" >>expect && git -C there worktree list >out && diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh index e7829c2c4bfdc3..47bad607adcb48 100755 --- a/t/t3200-branch.sh +++ b/t/t3200-branch.sh @@ -406,7 +406,7 @@ test_expect_success 'bare main worktree has HEAD at branch deleted by secondary git init -b main nonbare && test_commit -C nonbare x && git clone --bare nonbare bare && - git -C bare worktree add --detach ../secondary main && + git --git-dir=bare worktree add --detach secondary main && git -C secondary branch -D main ' @@ -416,11 +416,11 @@ test_expect_success 'secondary worktrees recognize core.bare=true in main config test_commit -C non_bare_repo x && git clone --bare non_bare_repo bare_repo && - git -C bare_repo config extensions.worktreeConfig true && - git -C bare_repo config unset core.bare && - git -C bare_repo config --worktree core.bare true && + git --git-dir=bare_repo config extensions.worktreeConfig true && + git --git-dir=bare_repo config unset core.bare && + git --git-dir=bare_repo config --worktree core.bare true && - git -C bare_repo worktree add ../secondary_worktree && + git --git-dir=bare_repo worktree add secondary_worktree && git -C secondary_worktree checkout main ' diff --git a/t/t5504-fetch-receive-strict.sh b/t/t5504-fetch-receive-strict.sh index 438250c75ed0a2..0b795b4177d147 100755 --- a/t/t5504-fetch-receive-strict.sh +++ b/t/t5504-fetch-receive-strict.sh @@ -370,9 +370,9 @@ test_expect_success PERL_TEST_HELPERS 'badFilemode is not a strict error' ' rm -rf dst.git && git init --bare dst.git && - git -C dst.git config transfer.fsckObjects true && + git --git-dir=dst.git config transfer.fsckObjects true && - git -C badmode.git push ../dst.git $tree:refs/tags/tree 2>err && + git --git-dir=badmode.git push dst.git $tree:refs/tags/tree 2>err && grep "$tree: badFilemode" err ' diff --git a/t/t5509-fetch-push-namespaces.sh b/t/t5509-fetch-push-namespaces.sh index 6b623cfde16a1b..8a7f6551c9a5e8 100755 --- a/t/t5509-fetch-push-namespaces.sh +++ b/t/t5509-fetch-push-namespaces.sh @@ -88,17 +88,17 @@ test_expect_success 'mirroring a repository using a ref namespace' ' test_expect_success 'hide namespaced refs with transfer.hideRefs' ' GIT_NAMESPACE=namespace \ - git -C pushee -c transfer.hideRefs=refs/tags \ - ls-remote "ext::git %s ." >actual && + git --git-dir=pushee -c transfer.hideRefs=refs/tags \ + ls-remote "ext::git %s pushee" >actual && printf "$commit1\trefs/heads/main\n" >expected && test_cmp expected actual ' test_expect_success 'check that transfer.hideRefs does not match unstripped refs' ' - git -C pushee pack-refs --all && + git --git-dir=pushee pack-refs --all && GIT_NAMESPACE=namespace \ - git -C pushee -c transfer.hideRefs=refs/namespaces/namespace/refs/tags \ - ls-remote "ext::git %s ." >actual && + git --git-dir=pushee -c transfer.hideRefs=refs/namespaces/namespace/refs/tags \ + ls-remote "ext::git %s pushee" >actual && printf "$commit1\trefs/heads/main\n" >expected && printf "$commit0\trefs/tags/0\n" >>expected && printf "$commit1\trefs/tags/1\n" >>expected && diff --git a/t/t6020-bundle-misc.sh b/t/t6020-bundle-misc.sh index 842f34f038b6e4..9850541f59e4ae 100755 --- a/t/t6020-bundle-misc.sh +++ b/t/t6020-bundle-misc.sh @@ -358,11 +358,11 @@ test_expect_success 'fail to verify bundle without prerequisites' ' error: Z EOF - test_must_fail git -C test1.git bundle verify ../2.bdl 2>&1 | + test_must_fail git --git-dir=test1.git bundle verify 2.bdl 2>&1 | make_user_friendly_and_stable_output >actual && test_cmp expect actual && - test_must_fail git -C test1.git bundle verify ../stdin-2.bdl 2>&1 | + test_must_fail git --git-dir=test1.git bundle verify stdin-2.bdl 2>&1 | make_user_friendly_and_stable_output >actual && test_cmp expect actual ' @@ -460,8 +460,8 @@ test_expect_success 'clone from bundle' ' EOF test_cmp expect actual && - git -C mirror.git fetch ../2.bdl "+refs/*:refs/*" && - git -C mirror.git show-ref | + git --git-dir=mirror.git fetch 2.bdl "+refs/*:refs/*" && + git --git-dir=mirror.git show-ref | make_user_friendly_and_stable_output >actual && cat >expect <<-\EOF && refs/heads/release @@ -470,8 +470,8 @@ test_expect_success 'clone from bundle' ' EOF test_cmp expect actual && - git -C mirror.git fetch ../3.bdl "+refs/*:refs/*" && - git -C mirror.git show-ref | + git --git-dir=mirror.git fetch 3.bdl "+refs/*:refs/*" && + git --git-dir=mirror.git show-ref | make_user_friendly_and_stable_output >actual && cat >expect <<-\EOF && refs/heads/main @@ -481,8 +481,8 @@ test_expect_success 'clone from bundle' ' EOF test_cmp expect actual && - git -C mirror.git fetch ../4.bdl "+refs/*:refs/*" && - git -C mirror.git show-ref | + git --git-dir=mirror.git fetch 4.bdl "+refs/*:refs/*" && + git --git-dir=mirror.git show-ref | make_user_friendly_and_stable_output >actual && cat >expect <<-\EOF && refs/heads/main diff --git a/t/t6500-gc.sh b/t/t6500-gc.sh index 199660f0c95737..e884be08e1bc8d 100755 --- a/t/t6500-gc.sh +++ b/t/t6500-gc.sh @@ -203,8 +203,8 @@ test_expect_success 'gc.repackFilterTo store filtered out objects' ' test_when_finished "rm -rf bare.git filtered.git" && git init --bare filtered.git && - git -C bare.git -c gc.repackFilter=blob:none \ - -c gc.repackFilterTo=../filtered.git/objects/pack/pack \ + git --git-dir=bare.git -c gc.repackFilter=blob:none \ + -c gc.repackFilterTo=filtered.git/objects/pack/pack \ -c repack.writeBitmaps=false -c gc.cruftPacks=false gc && test_stdout_line_count = 1 ls bare.git/objects/pack/*.pack && diff --git a/t/t7412-submodule-absorbgitdirs.sh b/t/t7412-submodule-absorbgitdirs.sh index 0490499573fd39..b1a2d7491157df 100755 --- a/t/t7412-submodule-absorbgitdirs.sh +++ b/t/t7412-submodule-absorbgitdirs.sh @@ -122,7 +122,7 @@ test_expect_success 'absorb the git dir outside of primary worktree' ' test_when_finished "rm -rf repo-bare.git" && git clone --bare . repo-bare.git && test_when_finished "rm -rf repo-wt" && - git -C repo-bare.git worktree add ../repo-wt && + git --git-dir=repo-bare.git worktree add repo-wt && test_when_finished "rm -f .gitconfig" && test_config_global protocol.file.allow always && diff --git a/t/t9003-help-autocorrect.sh b/t/t9003-help-autocorrect.sh index 8da318d2b543da..33ad9dc3cf9797 100755 --- a/t/t9003-help-autocorrect.sh +++ b/t/t9003-help-autocorrect.sh @@ -65,8 +65,9 @@ test_expect_success 'autocorrect can be declined altogether' ' ' test_expect_success 'autocorrect works in work tree created from bare repo' ' + test_when_finished "rm -rf bare.git worktree" && git clone --bare . bare.git && - git -C bare.git worktree add ../worktree && + git --git-dir=bare.git worktree add worktree && git -C worktree -c help.autocorrect=immediate status ' From da61aa33b27100ad66abd23ab20019bed4ba1101 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 27 Mar 2026 17:44:51 +0100 Subject: [PATCH 07/11] tests: export `GIT_DIR` when entering bare repositories via `cd` Some tests need to `cd` into a bare repository rather than address it from outside, typically because they create files there, inspect the object store, or call helpers that assume they are already inside the repository. For these, the `--git-dir` approach used by the companion commits is not applicable: the test genuinely needs its working directory to be inside the repository. The solution is to set and export `GIT_DIR=.` immediately after entering the bare repository. This tells Git explicitly where the repository is and prevents the implicit discovery that `safe.bareRepository=explicit` would reject. Should the default ever change (Git v3.0 is the most likely candidate), these tests will continue to work without modification. A few cases deserve special mention. In t1400-update-ref.sh, the test framework variable `$bare` points to the bare repository and the test sets `GIT_DIR=$bare` with a `cd $bare` plus a later `cd -` and `sane_unset GIT_DIR` for cleanup. In t2400-worktree-add.sh, some subshells use the shorter inline form `GIT_DIR=. git worktree add ...` where only a single command needs the override. In t5411/common-functions.sh, the change affects the shared setup used by the entire proc-receive test family. In lib-proto-disable.sh and lib-bitmap.sh, the change is inside shared test library functions that are sourced by multiple test scripts. This commit was produced with the help of Claude Opus 4.6 acting as a sophisticated keyboard. It was told to add `GIT_DIR=. && export GIT_DIR &&` after every `cd &&` inside a subshell that runs Git commands on a bare repository. The dominant pattern can be verified: git show HEAD | sed 's/ GIT_DIR=\. && export GIT_DIR &&//' | sed -ne '/^diff/,/@@/d' -e 's/^[-+]//p' | uniq -u Residual output corresponds to structural adjustments (subshell changes, inline `GIT_DIR=.` prefix form, cleanup via `sane_unset`) and adjacent `git -C` to `--git-dir` conversions that share the same hunk. Assisted-by: Claude Opus 4.6 Signed-off-by: Johannes Schindelin --- t/annotate-tests.sh | 4 ++-- t/lib-bitmap.sh | 2 +- t/lib-commit-graph.sh | 4 ++++ t/lib-proto-disable.sh | 16 +++++++-------- t/t1006-cat-file.sh | 2 ++ t/t1400-update-ref.sh | 10 ++++++---- t/t1450-fsck.sh | 6 ++++++ t/t1512-rev-parse-disambiguation.sh | 12 ++++++++--- t/t1800-hook.sh | 5 ++--- t/t2400-worktree-add.sh | 9 +++++++-- t/t2406-worktree-repair.sh | 6 ++++-- t/t3451-history-reword.sh | 2 +- t/t4203-mailmap.sh | 13 +++++++----- t/t5001-archive-attr.sh | 4 ++-- t/t5003-archive-zip.sh | 2 +- t/t5300-pack-object.sh | 2 +- t/t5310-pack-bitmaps.sh | 8 ++++---- t/t5311-pack-bitmaps-shallow.sh | 2 +- t/t5319-multi-pack-index.sh | 2 +- t/t5411/test-0000-standard-git-push.sh | 2 +- .../test-0001-standard-git-push--porcelain.sh | 2 +- t/t5411/test-0010-proc-receive-settings.sh | 2 +- t/t5411/test-0038-report-mixed-refs.sh | 2 +- .../test-0039-report-mixed-refs--porcelain.sh | 2 +- t/t5411/test-0040-process-all-refs.sh | 8 ++++---- .../test-0041-process-all-refs--porcelain.sh | 8 ++++---- ...t-0050-proc-receive-refs-with-modifiers.sh | 2 +- t/t5500-fetch-pack.sh | 3 ++- t/t5503-tagfollow.sh | 4 ++-- t/t5504-fetch-receive-strict.sh | 2 +- t/t5505-remote.sh | 12 +++++++++++ t/t5509-fetch-push-namespaces.sh | 2 +- t/t5510-fetch.sh | 20 +++++++++---------- t/t5516-fetch-push.sh | 12 +++++------ t/t5519-push-alternates.sh | 4 ++-- t/t5525-fetch-tagopt.sh | 6 +++--- t/t5531-deep-submodule-push.sh | 10 +++++----- t/t5601-clone.sh | 6 +++--- t/t5612-clone-refspec.sh | 4 ++-- t/t5615-alternate-env.sh | 9 ++++++--- t/t5616-partial-clone.sh | 2 +- t/t5900-repo-selection.sh | 6 +++--- t/t6030-bisect-porcelain.sh | 4 ++-- t/t6060-merge-index.sh | 6 +++--- t/t6136-pathspec-in-bare.sh | 4 ++-- t/t7103-reset-bare.sh | 4 +++- t/t7700-repack.sh | 10 +++++----- t/t7704-repack-cruft.sh | 2 +- t/t7900-maintenance.sh | 2 +- 49 files changed, 160 insertions(+), 113 deletions(-) diff --git a/t/annotate-tests.sh b/t/annotate-tests.sh index 87572459e4b873..bbcf01a6b6eb6a 100644 --- a/t/annotate-tests.sh +++ b/t/annotate-tests.sh @@ -86,7 +86,7 @@ test_expect_success 'blame with --contents' ' test_expect_success 'blame with --contents in a bare repo' ' git clone --bare . bare-contents.git && ( - cd bare-contents.git && + cd bare-contents.git && GIT_DIR=. && export GIT_DIR && echo "1A quick brown fox jumps over the" >contents && check_count --contents=contents A 1 ) @@ -101,7 +101,7 @@ test_expect_success 'blame with --contents changed' ' test_expect_success 'blame in a bare repo without starting commit' ' git clone --bare . bare.git && ( - cd bare.git && + cd bare.git && GIT_DIR=. && export GIT_DIR && check_count A 2 ) ' diff --git a/t/lib-bitmap.sh b/t/lib-bitmap.sh index 62aa6744a695f5..6c8d8a27735dcc 100644 --- a/t/lib-bitmap.sh +++ b/t/lib-bitmap.sh @@ -207,7 +207,7 @@ basic_bitmap_tests () { rm -fr partial-clone.git && git clone --no-local --bare --filter=blob:none . partial-clone.git && ( - cd partial-clone.git && + cd partial-clone.git && GIT_DIR=. && export GIT_DIR && pack=$(echo objects/pack/*.pack) && git verify-pack -v "$pack" >have && awk "/blob/ { print \$1 }" blobs && diff --git a/t/lib-commit-graph.sh b/t/lib-commit-graph.sh index 905a1702479523..8783c95ecbe1da 100755 --- a/t/lib-commit-graph.sh +++ b/t/lib-commit-graph.sh @@ -86,6 +86,10 @@ graph_read_expect() { EOF ( cd "$DIR" && + if test -n "$BARE" + then + GIT_DIR=. && export GIT_DIR + fi && test-tool read-graph >output && test_cmp expect output ) diff --git a/t/lib-proto-disable.sh b/t/lib-proto-disable.sh index 22c3fbfb44105a..0824872427d5a0 100644 --- a/t/lib-proto-disable.sh +++ b/t/lib-proto-disable.sh @@ -17,7 +17,7 @@ test_allow_var () { test_expect_success "fetch $desc (enabled)" ' ( - cd tmp.git && + cd tmp.git && GIT_DIR=. && export GIT_DIR && GIT_ALLOW_PROTOCOL=$proto && export GIT_ALLOW_PROTOCOL && git fetch @@ -26,7 +26,7 @@ test_allow_var () { test_expect_success "push $desc (enabled)" ' ( - cd tmp.git && + cd tmp.git && GIT_DIR=. && export GIT_DIR && GIT_ALLOW_PROTOCOL=$proto && export GIT_ALLOW_PROTOCOL && git push origin HEAD:pushed @@ -35,7 +35,7 @@ test_allow_var () { test_expect_success "push $desc (disabled)" ' ( - cd tmp.git && + cd tmp.git && GIT_DIR=. && export GIT_DIR && GIT_ALLOW_PROTOCOL=none && export GIT_ALLOW_PROTOCOL && test_must_fail git push origin HEAD:pushed @@ -44,7 +44,7 @@ test_allow_var () { test_expect_success "fetch $desc (disabled)" ' ( - cd tmp.git && + cd tmp.git && GIT_DIR=. && export GIT_DIR && GIT_ALLOW_PROTOCOL=none && export GIT_ALLOW_PROTOCOL && test_must_fail git fetch @@ -110,16 +110,16 @@ test_config () { ' test_expect_success "fetch $desc (enabled)" ' - git -C tmp.git -c protocol.$proto.allow=user fetch + git --git-dir=tmp.git -c protocol.$proto.allow=user fetch ' test_expect_success "push $desc (enabled)" ' - git -C tmp.git -c protocol.$proto.allow=user push origin HEAD:pushed + git --git-dir=tmp.git -c protocol.$proto.allow=user push origin HEAD:pushed ' test_expect_success "push $desc (disabled)" ' ( - cd tmp.git && + cd tmp.git && GIT_DIR=. && export GIT_DIR && GIT_PROTOCOL_FROM_USER=0 && export GIT_PROTOCOL_FROM_USER && test_must_fail git -c protocol.$proto.allow=user push origin HEAD:pushed @@ -128,7 +128,7 @@ test_config () { test_expect_success "fetch $desc (disabled)" ' ( - cd tmp.git && + cd tmp.git && GIT_DIR=. && export GIT_DIR && GIT_PROTOCOL_FROM_USER=0 && export GIT_PROTOCOL_FROM_USER && test_must_fail git -c protocol.$proto.allow=user fetch diff --git a/t/t1006-cat-file.sh b/t/t1006-cat-file.sh index 8e2c52652c5185..05b86325e1c773 100755 --- a/t/t1006-cat-file.sh +++ b/t/t1006-cat-file.sh @@ -805,6 +805,8 @@ test_expect_success 'cat-file -t and -s on corrupt loose object' ' git init --bare corrupt-loose.git && ( cd corrupt-loose.git && + GIT_DIR=. && + export GIT_DIR && # Setup and create the empty blob and its path empty_path=$(git rev-parse --git-path objects/$(test_oid_to_path "$EMPTY_BLOB")) && diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh index 3f2b07a7653cde..04703f3c12ae4c 100755 --- a/t/t1400-update-ref.sh +++ b/t/t1400-update-ref.sh @@ -28,11 +28,13 @@ create_test_commits () test_expect_success setup ' git checkout --orphan main && create_test_commits "" && - mkdir $bare && - cd $bare && - git init --bare -b main && + git init --bare -b main $bare && + # Cannot use a subshell: create_test_commits sets bareA..bareF + # via eval, and those must remain visible to later tests. + GIT_DIR=$bare && + export GIT_DIR && create_test_commits "bare" && - cd - + sane_unset GIT_DIR ' test_expect_success "create $m" ' diff --git a/t/t1450-fsck.sh b/t/t1450-fsck.sh index 54e81c263686de..2a3250d1bc5c14 100755 --- a/t/t1450-fsck.sh +++ b/t/t1450-fsck.sh @@ -54,6 +54,8 @@ test_expect_success 'object with hash mismatch' ' git init --bare hash-mismatch && ( cd hash-mismatch && + GIT_DIR=. && + export GIT_DIR && oid=$(echo blob | git hash-object -w --stdin) && oldoid=$oid && @@ -76,6 +78,8 @@ test_expect_success 'zlib corrupt loose object output ' ' git init --bare corrupt-loose-output && ( cd corrupt-loose-output && + GIT_DIR=. && + export GIT_DIR && oid=$(git hash-object -w --stdin --literally stdout.actual 2>stderr.actual && check_stdout_merged_to_stderr pre-receive update post-receive post-update ' diff --git a/t/t2400-worktree-add.sh b/t/t2400-worktree-add.sh index b056353dc76772..2daa42677aa58c 100755 --- a/t/t2400-worktree-add.sh +++ b/t/t2400-worktree-add.sh @@ -174,13 +174,15 @@ test_expect_success '"add" from a bare repo' ' ( git clone --bare . bare && cd bare && - git worktree add -b bare-main ../there2 main + GIT_DIR=. git worktree add -b bare-main ../there2 main ) ' test_expect_success 'checkout from a bare repo without "add"' ' ( cd bare && + GIT_DIR=. && + export GIT_DIR && test_must_fail git checkout main ) ' @@ -189,7 +191,7 @@ test_expect_success '"add" default branch of a bare repo' ' ( git clone --bare . bare2 && cd bare2 && - git worktree add ../there3 main && + GIT_DIR=. git worktree add ../there3 main && cd ../there3 && # Simple check that a Git command does not # immediately fail with the current setup @@ -206,6 +208,8 @@ test_expect_success '"add" to bare repo with worktree config' ' ( git clone --bare . bare3 && cd bare3 && + GIT_DIR=. && + export GIT_DIR && git config extensions.worktreeconfig true && # Add config values that are erroneous to have in @@ -219,6 +223,7 @@ test_expect_success '"add" to bare repo with worktree config' ' git config --worktree bogus.key value && git config --unset core.bare && git worktree add ../there4 main && + sane_unset GIT_DIR && cd ../there4 && # Simple check that a Git command does not diff --git a/t/t2406-worktree-repair.sh b/t/t2406-worktree-repair.sh index f5f19b3169384f..f14745346b7684 100755 --- a/t/t2406-worktree-repair.sh +++ b/t/t2406-worktree-repair.sh @@ -81,10 +81,12 @@ test_expect_success 'repair .git file from linked worktree' ' test_expect_success 'repair .git file from bare.git' ' test_when_finished "rm -rf bare.git corrupt && git worktree prune" && git clone --bare . bare.git && - git -C bare.git worktree add --detach ../corrupt && + (cd bare.git && GIT_DIR=. && export GIT_DIR && + git worktree add --detach ../corrupt) && git -C corrupt rev-parse --absolute-git-dir >expect && rm -f corrupt/.git && - git -C bare.git worktree repair && + (cd bare.git && GIT_DIR=. && export GIT_DIR && + git worktree repair) && git -C corrupt rev-parse --absolute-git-dir >actual && test_cmp expect actual ' diff --git a/t/t3451-history-reword.sh b/t/t3451-history-reword.sh index de7b357685db4a..cadc4aa38c28c1 100755 --- a/t/t3451-history-reword.sh +++ b/t/t3451-history-reword.sh @@ -150,7 +150,7 @@ test_expect_success 'can reword in a bare repo' ' test_commit -C repo first && git clone --bare repo repo.git && ( - cd repo.git && + cd repo.git && GIT_DIR=. && export GIT_DIR && reword_with_message HEAD <<-EOF && reworded EOF diff --git a/t/t4203-mailmap.sh b/t/t4203-mailmap.sh index 74b7ddccb26d59..1e79b4eaca2dc7 100755 --- a/t/t4203-mailmap.sh +++ b/t/t4203-mailmap.sh @@ -432,7 +432,7 @@ test_expect_success 'mailmap.blob defaults to off in non-bare repo' ' test_expect_success 'mailmap.blob defaults to HEAD:.mailmap in bare repo' ' git clone --bare non-bare bare && ( - cd bare && + cd bare && GIT_DIR=. && export GIT_DIR && cat >expect <<-\EOF && 1 Fake Name EOF @@ -943,13 +943,16 @@ test_expect_success 'set up mailmap location tests' ' ' test_expect_success 'bare repo with --work-tree finds mailmap at top-level' ' - git -C loc-bare --work-tree=. log -1 --format=%aE >actual && - echo new@example.com >expect && - test_cmp expect actual + ( + cd loc-bare && GIT_DIR=. && export GIT_DIR && + git --work-tree=. log -1 --format=%aE >actual && + echo new@example.com >expect && + test_cmp expect actual + ) ' test_expect_success 'bare repo does not look in current directory' ' - git -C loc-bare log -1 --format=%aE >actual && + git --git-dir=loc-bare log -1 --format=%aE >actual && echo orig@example.com >expect && test_cmp expect actual ' diff --git a/t/t5001-archive-attr.sh b/t/t5001-archive-attr.sh index e7450764411093..77201cf4ab41b1 100755 --- a/t/t5001-archive-attr.sh +++ b/t/t5001-archive-attr.sh @@ -127,12 +127,12 @@ test_expect_exists worktree2/ignored-by-tree test_expect_missing worktree2/ignored-by-worktree test_expect_success 'git archive vs. bare' ' - (cd bare && git archive HEAD) >bare-archive.tar && + (cd bare && GIT_DIR=. && export GIT_DIR && git archive HEAD) >bare-archive.tar && test_cmp_bin archive.tar bare-archive.tar ' test_expect_success 'git archive with worktree attributes, bare' ' - (cd bare && + (cd bare && GIT_DIR=. && export GIT_DIR && git -c attr.tree=HEAD archive --worktree-attributes HEAD) >bare-worktree.tar && (mkdir bare-worktree && cd bare-worktree && "$TAR" xf -) d1.zip' + '(cd bare.git && GIT_DIR=. && export GIT_DIR && git archive --format=zip HEAD) >d1.zip' test_expect_success \ 'git archive --format=zip vs. the same in a bare repo' \ diff --git a/t/t5300-pack-object.sh b/t/t5300-pack-object.sh index 0820d6ff2dea15..9083558036f470 100755 --- a/t/t5300-pack-object.sh +++ b/t/t5300-pack-object.sh @@ -227,7 +227,7 @@ check_use_objects () { git init --bare git2 && cp "$1".pack "$1".idx git2/objects/pack && ( - cd git2 && + cd git2 && GIT_DIR=. && export GIT_DIR && git diff-tree --root -p $commit && while read object do diff --git a/t/t5310-pack-bitmaps.sh b/t/t5310-pack-bitmaps.sh index 34ac63acdd0e43..82397f3cd2f4f1 100755 --- a/t/t5310-pack-bitmaps.sh +++ b/t/t5310-pack-bitmaps.sh @@ -223,7 +223,7 @@ test_bitmap_cases () { test_expect_success JGIT,SHA1 'we can read jgit bitmaps' ' git clone --bare . compat-jgit.git && ( - cd compat-jgit.git && + cd compat-jgit.git && GIT_DIR=. && export GIT_DIR && rm -f objects/pack/*.bitmap && jgit gc && git rev-list --test-bitmap HEAD @@ -233,7 +233,7 @@ test_bitmap_cases () { test_expect_success JGIT,SHA1 'jgit can read our bitmaps' ' git clone --bare . compat-us.git && ( - cd compat-us.git && + cd compat-us.git && GIT_DIR=. && export GIT_DIR && git config pack.writeBitmapLookupTable '"$writeLookupTable"' && git repack -adb && # jgit gc will barf if it does not like our bitmaps @@ -374,7 +374,7 @@ test_bitmap_cases () { test_when_finished "rm -rf client.git" && git init --bare client.git && ( - cd client.git && + cd client.git && GIT_DIR=. && export GIT_DIR && git config transfer.unpackLimit 1 && git fetch .. delta-reuse-old:delta-reuse-old && git fetch .. delta-reuse-new:delta-reuse-new && @@ -388,7 +388,7 @@ test_bitmap_cases () { test_when_finished "rm -rf client.git" && git init --bare client.git && ( - cd client.git && + cd client.git && GIT_DIR=. && export GIT_DIR && # This test relies on reusing a delta, but if the # path-walk machinery is engaged, the base object diff --git a/t/t5311-pack-bitmaps-shallow.sh b/t/t5311-pack-bitmaps-shallow.sh index 012852c156ac79..36572386f3191e 100755 --- a/t/t5311-pack-bitmaps-shallow.sh +++ b/t/t5311-pack-bitmaps-shallow.sh @@ -47,7 +47,7 @@ test_shallow_bitmaps () { ' test_expect_success 'shallow fetch from bitmapped repo' ' - (cd shallow.git && git fetch) + (cd shallow.git && GIT_DIR=. && export GIT_DIR && git fetch) ' } diff --git a/t/t5319-multi-pack-index.sh b/t/t5319-multi-pack-index.sh index a7c79225f67526..bfcc13b0f35a44 100755 --- a/t/t5319-multi-pack-index.sh +++ b/t/t5319-multi-pack-index.sh @@ -274,7 +274,7 @@ test_expect_success 'midx picks objects from preferred pack' ' test_when_finished rm -rf preferred.git && git init --bare preferred.git && ( - cd preferred.git && + cd preferred.git && GIT_DIR=. && export GIT_DIR && a=$(echo "a" | git hash-object -w --stdin) && b=$(echo "b" | git hash-object -w --stdin) && diff --git a/t/t5411/test-0000-standard-git-push.sh b/t/t5411/test-0000-standard-git-push.sh index 8274e00cd9c02e..5f45386886674a 100644 --- a/t/t5411/test-0000-standard-git-push.sh +++ b/t/t5411/test-0000-standard-git-push.sh @@ -126,7 +126,7 @@ test_expect_success "git-push -f ($PROTOCOL)" ' # Refs of workbench: main(A) tags/v123 test_expect_success "cleanup ($PROTOCOL)" ' ( - cd "$upstream" && + cd "$upstream" && GIT_DIR=. && export GIT_DIR && git update-ref -d refs/review/main/topic && git update-ref -d refs/tags/v123 && git update-ref -d refs/heads/a/b/c diff --git a/t/t5411/test-0001-standard-git-push--porcelain.sh b/t/t5411/test-0001-standard-git-push--porcelain.sh index 45c06b4d775158..05d2871598932b 100644 --- a/t/t5411/test-0001-standard-git-push--porcelain.sh +++ b/t/t5411/test-0001-standard-git-push--porcelain.sh @@ -130,7 +130,7 @@ test_expect_success "git-push -f ($PROTOCOL/porcelain)" ' # Refs of workbench: main(A) tags/v123 test_expect_success "cleanup ($PROTOCOL/porcelain)" ' ( - cd "$upstream" && + cd "$upstream" && GIT_DIR=. && export GIT_DIR && git update-ref -d refs/review/main/topic && git update-ref -d refs/tags/v123 && git update-ref -d refs/heads/a/b/c diff --git a/t/t5411/test-0010-proc-receive-settings.sh b/t/t5411/test-0010-proc-receive-settings.sh index a36809927b37ab..b9b0c0ffa9df06 100644 --- a/t/t5411/test-0010-proc-receive-settings.sh +++ b/t/t5411/test-0010-proc-receive-settings.sh @@ -1,6 +1,6 @@ test_expect_success "add two receive.procReceiveRefs settings" ' ( - cd "$upstream" && + cd "$upstream" && GIT_DIR=. && export GIT_DIR && git config --add receive.procReceiveRefs refs/for && git config --add receive.procReceiveRefs refs/review/ ) diff --git a/t/t5411/test-0038-report-mixed-refs.sh b/t/t5411/test-0038-report-mixed-refs.sh index e2dd2ce320790c..e4d42af3ac9878 100644 --- a/t/t5411/test-0038-report-mixed-refs.sh +++ b/t/t5411/test-0038-report-mixed-refs.sh @@ -78,7 +78,7 @@ test_expect_success "proc-receive: report update of mixed refs ($PROTOCOL)" ' # Refs of workbench: main(A) tags/v123 test_expect_success "cleanup ($PROTOCOL)" ' ( - cd "$upstream" && + cd "$upstream" && GIT_DIR=. && export GIT_DIR && git update-ref refs/heads/main $A && git update-ref -d refs/heads/foo && git update-ref -d refs/heads/bar && diff --git a/t/t5411/test-0039-report-mixed-refs--porcelain.sh b/t/t5411/test-0039-report-mixed-refs--porcelain.sh index 69f8c72634ca2d..29b23fc9084140 100644 --- a/t/t5411/test-0039-report-mixed-refs--porcelain.sh +++ b/t/t5411/test-0039-report-mixed-refs--porcelain.sh @@ -79,7 +79,7 @@ test_expect_success "proc-receive: report update of mixed refs ($PROTOCOL/porcel # Refs of workbench: main(A) tags/v123 test_expect_success "cleanup ($PROTOCOL/porcelain)" ' ( - cd "$upstream" && + cd "$upstream" && GIT_DIR=. && export GIT_DIR && git update-ref refs/heads/main $A && git update-ref -d refs/heads/foo && git update-ref -d refs/heads/bar && diff --git a/t/t5411/test-0040-process-all-refs.sh b/t/t5411/test-0040-process-all-refs.sh index 421543706d1cae..f9260d61329ccc 100644 --- a/t/t5411/test-0040-process-all-refs.sh +++ b/t/t5411/test-0040-process-all-refs.sh @@ -1,13 +1,13 @@ test_expect_success "config receive.procReceiveRefs = refs ($PROTOCOL)" ' - git -C "$upstream" config --unset-all receive.procReceiveRefs && - git -C "$upstream" config --add receive.procReceiveRefs refs + git --git-dir="$upstream" config --unset-all receive.procReceiveRefs && + git --git-dir="$upstream" config --add receive.procReceiveRefs refs ' # Refs of upstream : main(A) # Refs of workbench: main(A) tags/v123 test_expect_success "setup upstream branches ($PROTOCOL)" ' ( - cd "$upstream" && + cd "$upstream" && GIT_DIR=. && export GIT_DIR && git update-ref refs/heads/main $B && git update-ref refs/heads/foo $A && git update-ref refs/heads/bar $A && @@ -104,7 +104,7 @@ test_expect_success "proc-receive: process all refs ($PROTOCOL)" ' # Refs of workbench: main(A) tags/v123 test_expect_success "cleanup ($PROTOCOL)" ' ( - cd "$upstream" && + cd "$upstream" && GIT_DIR=. && export GIT_DIR && git update-ref -d refs/heads/bar && git update-ref -d refs/heads/baz ) diff --git a/t/t5411/test-0041-process-all-refs--porcelain.sh b/t/t5411/test-0041-process-all-refs--porcelain.sh index 8a2eca908159f1..fa1b65e1ebee75 100644 --- a/t/t5411/test-0041-process-all-refs--porcelain.sh +++ b/t/t5411/test-0041-process-all-refs--porcelain.sh @@ -1,13 +1,13 @@ test_expect_success "config receive.procReceiveRefs = refs ($PROTOCOL/porcelain)" ' - git -C "$upstream" config --unset-all receive.procReceiveRefs && - git -C "$upstream" config --add receive.procReceiveRefs refs + git --git-dir="$upstream" config --unset-all receive.procReceiveRefs && + git --git-dir="$upstream" config --add receive.procReceiveRefs refs ' # Refs of upstream : main(A) # Refs of workbench: main(A) tags/v123 test_expect_success "setup upstream branches ($PROTOCOL/porcelain)" ' ( - cd "$upstream" && + cd "$upstream" && GIT_DIR=. && export GIT_DIR && git update-ref refs/heads/main $B && git update-ref refs/heads/foo $A && git update-ref refs/heads/bar $A && @@ -105,7 +105,7 @@ test_expect_success "proc-receive: process all refs ($PROTOCOL/porcelain)" ' # Refs of workbench: main(A) tags/v123 test_expect_success "cleanup ($PROTOCOL/porcelain)" ' ( - cd "$upstream" && + cd "$upstream" && GIT_DIR=. && export GIT_DIR && git update-ref -d refs/heads/bar && git update-ref -d refs/heads/baz ) diff --git a/t/t5411/test-0050-proc-receive-refs-with-modifiers.sh b/t/t5411/test-0050-proc-receive-refs-with-modifiers.sh index cf6242149c5875..b64283eed52284 100644 --- a/t/t5411/test-0050-proc-receive-refs-with-modifiers.sh +++ b/t/t5411/test-0050-proc-receive-refs-with-modifiers.sh @@ -1,6 +1,6 @@ test_expect_success "config receive.procReceiveRefs with modifiers ($PROTOCOL)" ' ( - cd "$upstream" && + cd "$upstream" && GIT_DIR=. && export GIT_DIR && git config --unset-all receive.procReceiveRefs && git config --add receive.procReceiveRefs m:refs/heads/main && git config --add receive.procReceiveRefs ad:refs/heads && diff --git a/t/t5500-fetch-pack.sh b/t/t5500-fetch-pack.sh index 2033180affcadb..ec94c66bb5a314 100755 --- a/t/t5500-fetch-pack.sh +++ b/t/t5500-fetch-pack.sh @@ -454,10 +454,11 @@ test_expect_success 'fetch in shallow repo unreachable shallow objects' ' ( git clone --bare --branch B --single-branch "file://$(pwd)/." no-reflog && git clone --depth 1 "file://$(pwd)/no-reflog" shallow9 && - cd no-reflog && + cd no-reflog && GIT_DIR=. && export GIT_DIR && git tag -d TAGB1 TAGB2 && git update-ref refs/heads/B B~~ && git gc --prune=now && + unset GIT_DIR && cd ../shallow9 && git fetch origin && git fsck --no-dangling diff --git a/t/t5503-tagfollow.sh b/t/t5503-tagfollow.sh index febe44104177e1..1449833d0aa234 100755 --- a/t/t5503-tagfollow.sh +++ b/t/t5503-tagfollow.sh @@ -169,11 +169,11 @@ test_expect_success 'new clone fetch main and tags' ' test_expect_success 'fetch specific OID with tag following' ' git init --bare clone3.git && ( - cd clone3.git && + cd clone3.git && GIT_DIR=. && export GIT_DIR && git remote add origin .. && git fetch origin $B:refs/heads/main && - git -C .. for-each-ref >expect && + git --git-dir=../.git for-each-ref >expect && git for-each-ref >actual && test_cmp expect actual diff --git a/t/t5504-fetch-receive-strict.sh b/t/t5504-fetch-receive-strict.sh index 0b795b4177d147..90928cbf23892b 100755 --- a/t/t5504-fetch-receive-strict.sh +++ b/t/t5504-fetch-receive-strict.sh @@ -362,7 +362,7 @@ test_expect_success \ test_expect_success PERL_TEST_HELPERS 'badFilemode is not a strict error' ' git init --bare badmode.git && tree=$( - cd badmode.git && + cd badmode.git && GIT_DIR=. && export GIT_DIR && blob=$(echo blob | git hash-object -w --stdin | hex2oct) && printf "123456 foo\0${blob}" | git hash-object -t tree --stdin -w --literally diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh index f1f6254fb022e2..9607b2f45f595e 100755 --- a/t/t5505-remote.sh +++ b/t/t5505-remote.sh @@ -562,6 +562,7 @@ test_expect_success 'add --mirror && prune' ' ( cd mirror && git init --bare && + GIT_DIR=. && export GIT_DIR && git remote add --mirror -f origin ../one ) && ( @@ -570,6 +571,7 @@ test_expect_success 'add --mirror && prune' ' ) && ( cd mirror && + GIT_DIR=. && export GIT_DIR && git rev-parse --verify refs/heads/side2 && test_must_fail git rev-parse --verify refs/heads/side && git fetch origin && @@ -584,6 +586,7 @@ test_expect_success 'add --mirror setting HEAD' ' ( cd headmirror && git init --bare -b notmain && + GIT_DIR=. && export GIT_DIR && git remote add --mirror -f origin ../one && test "$(git symbolic-ref HEAD)" = "refs/heads/main" ) @@ -594,6 +597,7 @@ test_expect_success 'non-mirror fetch does not interfere with mirror' ' ( git init --bare -b notmain headnotmain && cd headnotmain && + GIT_DIR=. && export GIT_DIR && git remote add -f other ../two && test "$(git symbolic-ref HEAD)" = "refs/heads/notmain" ) @@ -609,6 +613,7 @@ test_expect_success 'add --mirror=fetch' ' git init --bare mirror-fetch/child && ( cd mirror-fetch/child && + GIT_DIR=. && export GIT_DIR && git remote add --mirror=fetch -f parent ../parent ) ' @@ -621,6 +626,7 @@ test_expect_success 'fetch mirrors act as mirrors during fetch' ' ) && ( cd mirror-fetch/child && + GIT_DIR=. && export GIT_DIR && git fetch parent && git rev-parse --verify refs/heads/new && git rev-parse --verify refs/heads/renamed @@ -630,6 +636,7 @@ test_expect_success 'fetch mirrors act as mirrors during fetch' ' test_expect_success 'fetch mirrors can prune' ' ( cd mirror-fetch/child && + GIT_DIR=. && export GIT_DIR && git remote prune parent && test_must_fail git rev-parse --verify refs/heads/main ) @@ -642,6 +649,7 @@ test_expect_success 'fetch mirrors do not act as mirrors during push' ' ) && ( cd mirror-fetch/child && + GIT_DIR=. && export GIT_DIR && git branch -m renamed renamed2 && git push parent : ) && @@ -656,6 +664,7 @@ test_expect_success 'add fetch mirror with specific branches' ' git init --bare mirror-fetch/track && ( cd mirror-fetch/track && + GIT_DIR=. && export GIT_DIR && git remote add --mirror=fetch -t heads/new parent ../parent ) ' @@ -663,6 +672,7 @@ test_expect_success 'add fetch mirror with specific branches' ' test_expect_success 'fetch mirror respects specific branches' ' ( cd mirror-fetch/track && + GIT_DIR=. && export GIT_DIR && git fetch parent && git rev-parse --verify refs/heads/new && test_must_fail git rev-parse --verify refs/heads/renamed @@ -698,6 +708,7 @@ test_expect_success 'push mirrors act as mirrors during push' ' test_expect_success 'push mirrors do not act as mirrors during fetch' ' ( cd mirror-push/public && + GIT_DIR=. && export GIT_DIR && git branch -m renamed renamed2 && git symbolic-ref HEAD refs/heads/renamed2 ) && @@ -1293,6 +1304,7 @@ test_expect_success 'remote set-branches with --mirror' ' git clone --mirror .git/ setbranches-mirror && ( cd setbranches-mirror && + GIT_DIR=. && export GIT_DIR && git remote rename origin scratch && git config --get-all remote.scratch.fetch >../actual.initial && diff --git a/t/t5509-fetch-push-namespaces.sh b/t/t5509-fetch-push-namespaces.sh index 8a7f6551c9a5e8..08a4980440b793 100755 --- a/t/t5509-fetch-push-namespaces.sh +++ b/t/t5509-fetch-push-namespaces.sh @@ -77,7 +77,7 @@ test_expect_success 'pulling from a repository using a ref namespace' ' test_expect_success 'mirroring a repository using a ref namespace' ' git clone --mirror pushee mirror && ( - cd mirror && + cd mirror && GIT_DIR=. && export GIT_DIR && git for-each-ref refs/ >actual && printf "$commit1 commit\trefs/namespaces/namespace/refs/heads/main\n" >expected && printf "$commit0 commit\trefs/namespaces/namespace/refs/tags/0\n" >>expected && diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh index 09349f026752de..a699e9de693f83 100755 --- a/t/t5510-fetch.sh +++ b/t/t5510-fetch.sh @@ -112,7 +112,7 @@ test_expect_success "fetch test remote HEAD in bare repository" ' test_when_finished rm -rf barerepo && ( git init --bare barerepo && - cd barerepo && + cd barerepo && GIT_DIR=. && export GIT_DIR && git remote add upstream ../two && git fetch upstream && git rev-parse --verify refs/remotes/upstream/HEAD && @@ -1488,7 +1488,7 @@ test_expect_success CASE_INSENSITIVE_FS,REFFILES 'existing references in a case test_when_finished rm -rf case_insensitive && ( git init --bare case_insensitive && - cd case_insensitive && + cd case_insensitive && GIT_DIR=. && export GIT_DIR && git remote add origin -- ../case_sensitive && test_must_fail git fetch -f origin "refs/heads/*:refs/heads/*" 2>err && test_grep "You${SQ}re on a case-insensitive filesystem" err && @@ -1513,7 +1513,7 @@ test_expect_success REFFILES 'existing reference lock in repo' ' cd .. && git init --ref-format=files --bare repo && - cd repo && + cd repo && GIT_DIR=. && export GIT_DIR && git remote add origin ../base && touch refs/heads/foo.lock && test_must_fail git fetch -f origin "refs/heads/*:refs/heads/*" 2>err && @@ -1528,7 +1528,7 @@ test_expect_success CASE_INSENSITIVE_FS,REFFILES 'F/D conflict on case insensiti test_when_finished rm -rf case_insensitive && ( git init --bare case_insensitive && - cd case_insensitive && + cd case_insensitive && GIT_DIR=. && export GIT_DIR && git remote add origin -- ../case_sensitive_fd && test_must_fail git fetch -f origin "refs/heads/*:refs/heads/*" 2>err && test_grep "cannot process ${SQ}refs/remotes/origin/foo${SQ} and ${SQ}refs/remotes/origin/foo/bar${SQ} at the same time" err && @@ -1542,7 +1542,7 @@ test_expect_success CASE_INSENSITIVE_FS,REFFILES 'D/F conflict on case insensiti test_when_finished rm -rf case_insensitive && ( git init --bare case_insensitive && - cd case_insensitive && + cd case_insensitive && GIT_DIR=. && export GIT_DIR && git remote add origin -- ../case_sensitive_df && test_must_fail git fetch -f origin "refs/heads/*:refs/heads/*" 2>err && test_grep "cannot lock ref ${SQ}refs/remotes/origin/foo${SQ}: there is a non-empty directory ${SQ}./refs/remotes/origin/foo${SQ} blocking reference ${SQ}refs/remotes/origin/foo${SQ}" err && @@ -1567,7 +1567,7 @@ test_expect_success REFFILES 'D/F conflict on case sensitive filesystem with loc cd .. && git init --ref-format=files --bare repo && - cd repo && + cd repo && GIT_DIR=. && export GIT_DIR && git remote add origin ../base && mkdir refs/heads/foo && touch refs/heads/foo/random.lock && @@ -1654,7 +1654,7 @@ test_expect_success REFFILES "FETCH_HEAD is updated even if ref updates fail" ' git init --bare repo && ( - cd repo && + cd repo && GIT_DIR=. && export GIT_DIR && rm -f FETCH_HEAD && git remote add origin ../base && >refs/heads/foo.lock && @@ -1673,7 +1673,7 @@ test_expect_success "upstream tracking info is added with --set-upstream" ' git init --bare --initial-branch=main repo && ( - cd repo && + cd repo && GIT_DIR=. && export GIT_DIR && git remote add origin ../base && git fetch origin --set-upstream main && git config get branch.main.remote >actual && @@ -1690,7 +1690,7 @@ test_expect_success REFFILES "upstream tracking info is added even with conflict git init --bare --initial-branch=main repo && ( - cd repo && + cd repo && GIT_DIR=. && export GIT_DIR && git remote add origin ../base && test_must_fail git config get branch.main.remote && @@ -1717,7 +1717,7 @@ test_expect_success REFFILES "HEAD is updated even with conflicts" ' git init --bare repo && ( - cd repo && + cd repo && GIT_DIR=. && export GIT_DIR && git remote add origin ../base && test_path_is_missing refs/remotes/origin/HEAD && diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh index c6ef4691ebf6de..f119b790205ef8 100755 --- a/t/t5516-fetch-push.sh +++ b/t/t5516-fetch-push.sh @@ -1392,7 +1392,7 @@ test_expect_success 'pushing a specific ref applies remote.$name.push as refmap' sed -e "s|refs/heads/|refs/remotes/src/|" >../dst/expect ) && ( - cd dst && + cd dst && GIT_DIR=. && export GIT_DIR && test_must_fail git show-ref refs/heads/next && test_must_fail git show-ref refs/heads/main && git show-ref refs/remotes/src/main >actual @@ -1416,7 +1416,7 @@ test_expect_success 'with no remote.$name.push, it is not used as refmap' ' git show-ref refs/heads/main >../dst/expect ) && ( - cd dst && + cd dst && GIT_DIR=. && export GIT_DIR && test_must_fail git show-ref refs/heads/next && git show-ref refs/heads/main >actual ) && @@ -1445,7 +1445,7 @@ test_expect_success 'with no remote.$name.push, upstream mapping is used' ' sed -e "s|refs/heads/main|refs/heads/trunk|" >../dst/expect ) && ( - cd dst && + cd dst && GIT_DIR=. && export GIT_DIR && test_must_fail git show-ref refs/heads/main && test_must_fail git show-ref refs/heads/next && git show-ref refs/heads/trunk >actual @@ -1471,7 +1471,7 @@ test_expect_success 'push does not follow tags by default' ' git push ../dst main ) && ( - cd dst && + cd dst && GIT_DIR=. && export GIT_DIR && git for-each-ref >../actual ) && test_cmp expect actual @@ -1495,7 +1495,7 @@ test_expect_success 'push --follow-tags only pushes relevant tags' ' git push --follow-tags ../dst main ) && ( - cd dst && + cd dst && GIT_DIR=. && export GIT_DIR && git for-each-ref >../actual ) && test_cmp expect actual @@ -1553,7 +1553,7 @@ test_expect_success 'fetch into bare respects core.logallrefupdates' ' test_when_finished "rm -rf dst.git" && git init --bare dst.git && ( - cd dst.git && + cd dst.git && GIT_DIR=. && export GIT_DIR && git config core.logallrefupdates true && # as above, we double-fetch to test both diff --git a/t/t5519-push-alternates.sh b/t/t5519-push-alternates.sh index 20ba604dfde162..4e6712fcb2b914 100755 --- a/t/t5519-push-alternates.sh +++ b/t/t5519-push-alternates.sh @@ -66,7 +66,7 @@ test_expect_success 'bob fetches from alice, works and pushes' ' # Check that the second commit by Alice is not sent # to ../bob-pub ( - cd bob-pub && + cd bob-pub && GIT_DIR=. && export GIT_DIR && second=$(git rev-parse HEAD^) && rm -f objects/info/alternates && test_must_fail git cat-file -t $second && @@ -124,7 +124,7 @@ test_expect_success 'alice works and pushes yet again' ' test_expect_success 'bob works and pushes again' ' ( - cd alice-pub && + cd alice-pub && GIT_DIR=. && export GIT_DIR && git cat-file commit main >../bob-work/commit ) && ( diff --git a/t/t5525-fetch-tagopt.sh b/t/t5525-fetch-tagopt.sh index 45815f737850b6..14b3ee1c2450d2 100755 --- a/t/t5525-fetch-tagopt.sh +++ b/t/t5525-fetch-tagopt.sh @@ -7,7 +7,7 @@ test_description='tagopt variable affects "git fetch" and is overridden by comma setup_clone () { git clone --mirror . $1 && git remote add remote_$1 $1 && - (cd $1 && + (cd $1 && GIT_DIR=. && export GIT_DIR && git tag tag_$1 && git branch branch_$1) } @@ -28,7 +28,7 @@ test_expect_success "fetch with tagopt=--no-tags does not get tag" ' test_expect_success "fetch --tags with tagopt=--no-tags gets tag" ' ( - cd one && + cd one && GIT_DIR=. && export GIT_DIR && git branch second_branch_one ) && git fetch --tags remote_one && @@ -44,7 +44,7 @@ test_expect_success "fetch --no-tags with tagopt=--tags does not get tag" ' test_expect_success "fetch with tagopt=--tags gets tag" ' ( - cd two && + cd two && GIT_DIR=. && export GIT_DIR && git branch second_branch_two ) && git fetch remote_two && diff --git a/t/t5531-deep-submodule-push.sh b/t/t5531-deep-submodule-push.sh index 68019934423908..444f4cec8738f5 100755 --- a/t/t5531-deep-submodule-push.sh +++ b/t/t5531-deep-submodule-push.sh @@ -391,7 +391,7 @@ test_expect_success 'push unpushed submodules when not needed' ' git push --recurse-submodules=on-demand ../pub.git main ) && ( - cd submodule.git && + cd submodule.git && GIT_DIR=. && export GIT_DIR && git rev-parse main >../actual ) && test_cmp expected actual @@ -399,7 +399,7 @@ test_expect_success 'push unpushed submodules when not needed' ' test_expect_success 'push unpushed submodules when not needed 2' ' ( - cd submodule.git && + cd submodule.git && GIT_DIR=. && export GIT_DIR && git rev-parse main >../expected ) && ( @@ -416,7 +416,7 @@ test_expect_success 'push unpushed submodules when not needed 2' ' git push --recurse-submodules=on-demand ../pub.git main ) && ( - cd submodule.git && + cd submodule.git && GIT_DIR=. && export GIT_DIR && git rev-parse main >../actual ) && test_cmp expected actual @@ -439,7 +439,7 @@ test_expect_success 'push unpushed submodules recursively' ' git push --recurse-submodules=on-demand ../pub.git main ) && ( - cd submodule.git && + cd submodule.git && GIT_DIR=. && export GIT_DIR && git rev-parse main >../actual ) && test_cmp expected actual @@ -461,7 +461,7 @@ test_expect_success 'push unpushable submodule recursively fails' ' test_must_fail git push --recurse-submodules=on-demand ../pub.git main ) && ( - cd submodule.git && + cd submodule.git && GIT_DIR=. && export GIT_DIR && git rev-parse main >../actual ) && test_when_finished git -C work reset --hard main^ && diff --git a/t/t5601-clone.sh b/t/t5601-clone.sh index 2ff7bdf8e56985..7c5d34e56868f6 100755 --- a/t/t5601-clone.sh +++ b/t/t5601-clone.sh @@ -118,9 +118,9 @@ test_expect_success 'clone --mirror' ' git clone --mirror src mirror && test -f mirror/HEAD && test ! -f mirror/file && - FETCH="$(cd mirror && git config remote.origin.fetch)" && + FETCH="$(cd mirror && GIT_DIR=. && export GIT_DIR && git config remote.origin.fetch)" && test "+refs/*:refs/*" = "$FETCH" && - MIRROR="$(cd mirror && git config --bool remote.origin.mirror)" && + MIRROR="$(cd mirror && GIT_DIR=. && export GIT_DIR && git config --bool remote.origin.mirror)" && test "$MIRROR" = true ' @@ -157,7 +157,7 @@ test_expect_success 'clone --mirror does not repeat tags' ' (cd src && git tag some-tag HEAD) && git clone --mirror src mirror2 && - (cd mirror2 && + (cd mirror2 && GIT_DIR=. && export GIT_DIR && git show-ref 2> clone.err > clone.out) && ! grep Duplicate mirror2/clone.err && grep some-tag mirror2/clone.out diff --git a/t/t5612-clone-refspec.sh b/t/t5612-clone-refspec.sh index 3126cfd7e9d6bd..5f0a1d8f598d6c 100755 --- a/t/t5612-clone-refspec.sh +++ b/t/t5612-clone-refspec.sh @@ -205,7 +205,7 @@ test_expect_success '--single-branch with explicit --branch with tag fetches upd test_expect_success '--single-branch with --mirror' ' ( - cd dir_mirror && + cd dir_mirror && GIT_DIR=. && export GIT_DIR && git fetch && git for-each-ref refs > ../actual ) && @@ -215,7 +215,7 @@ test_expect_success '--single-branch with --mirror' ' test_expect_success '--single-branch with explicit --branch and --mirror' ' ( - cd dir_mirror_side && + cd dir_mirror_side && GIT_DIR=. && export GIT_DIR && git fetch && git for-each-ref refs > ../actual ) && diff --git a/t/t5615-alternate-env.sh b/t/t5615-alternate-env.sh index 53e81b73fb28b5..e58715064cefa1 100755 --- a/t/t5615-alternate-env.sh +++ b/t/t5615-alternate-env.sh @@ -48,9 +48,12 @@ test_expect_success 'access multiple alternates' ' # bare paths are relative from $GIT_DIR test_expect_success 'access alternate via relative path (bare)' ' git init --bare bare.git && - check_obj "../one.git/objects" -C bare.git <<-EOF - $one blob - EOF + ( + cd bare.git && GIT_DIR=. && export GIT_DIR && + check_obj "../one.git/objects" <<-EOF + $one blob + EOF + ) ' # non-bare paths are relative to top of worktree diff --git a/t/t5616-partial-clone.sh b/t/t5616-partial-clone.sh index bfd9853fb11ef6..366245e29d149c 100755 --- a/t/t5616-partial-clone.sh +++ b/t/t5616-partial-clone.sh @@ -447,7 +447,7 @@ test_expect_success 'partial clone with sparse filter succeeds' ' --filter=sparse:oid=main:only-one \ sparse-src dst.git && ( - cd dst.git && + cd dst.git && GIT_DIR=. && export GIT_DIR && git rev-list --objects --missing=print HEAD >out && grep "^$(git rev-parse HEAD:one.t)" out && grep "^?$(git rev-parse HEAD:two.t)" out diff --git a/t/t5900-repo-selection.sh b/t/t5900-repo-selection.sh index 923fc90f877bd0..61817a660f34d8 100755 --- a/t/t5900-repo-selection.sh +++ b/t/t5900-repo-selection.sh @@ -15,7 +15,7 @@ make_tree() { make_bare() { git init --bare "$1" && - (cd "$1" && + (cd "$1" && GIT_DIR=. && export GIT_DIR && tree=$(git hash-object -w -t tree /dev/null) && commit=$(echo "$1" | git commit-tree $tree) && git update-ref HEAD $commit @@ -24,13 +24,13 @@ make_bare() { get() { git init --bare fetch && - (cd fetch && git fetch "../$1") && + (cd fetch && GIT_DIR=. && export GIT_DIR && git fetch "../$1") && git clone "$1" clone } check() { echo "$1" >expect && - (cd fetch && git log -1 --format=%s FETCH_HEAD) >actual.fetch && + (cd fetch && GIT_DIR=. && export GIT_DIR && git log -1 --format=%s FETCH_HEAD) >actual.fetch && (cd clone && git log -1 --format=%s HEAD) >actual.clone && test_cmp expect actual.fetch && test_cmp expect actual.clone diff --git a/t/t6030-bisect-porcelain.sh b/t/t6030-bisect-porcelain.sh index cdc02706404b34..f6c762f12c82ee 100755 --- a/t/t6030-bisect-porcelain.sh +++ b/t/t6030-bisect-porcelain.sh @@ -818,7 +818,7 @@ test_expect_success 'erroring out when using bad path arguments' ' test_expect_success 'test bisection on bare repo - --no-checkout specified' ' git clone --bare . bare.nocheckout && ( - cd bare.nocheckout && + cd bare.nocheckout && GIT_DIR=. && export GIT_DIR && git bisect start --no-checkout && git bisect good $HASH1 && git bisect bad $HASH4 && @@ -833,7 +833,7 @@ test_expect_success 'test bisection on bare repo - --no-checkout specified' ' test_expect_success 'test bisection on bare repo - --no-checkout defaulted' ' git clone --bare . bare.defaulted && ( - cd bare.defaulted && + cd bare.defaulted && GIT_DIR=. && export GIT_DIR && git bisect start && git bisect good $HASH1 && git bisect bad $HASH4 && diff --git a/t/t6060-merge-index.sh b/t/t6060-merge-index.sh index e6b3e6ec775993..dfec08edb79e48 100755 --- a/t/t6060-merge-index.sh +++ b/t/t6060-merge-index.sh @@ -51,7 +51,7 @@ test_expect_success 'git merge-index git-merge-one-file resolves' ' test_expect_success 'setup bare merge' ' git clone --bare . bare.git && - (cd bare.git && + (cd bare.git && GIT_DIR=. && export GIT_DIR && GIT_INDEX_FILE=$PWD/merge.index && export GIT_INDEX_FILE && git read-tree -i -m base ten two @@ -59,7 +59,7 @@ test_expect_success 'setup bare merge' ' ' test_expect_success 'merge-one-file fails without a work tree' ' - (cd bare.git && + (cd bare.git && GIT_DIR=. && export GIT_DIR && GIT_INDEX_FILE=$PWD/merge.index && export GIT_INDEX_FILE && test_must_fail git merge-index git-merge-one-file -a @@ -67,7 +67,7 @@ test_expect_success 'merge-one-file fails without a work tree' ' ' test_expect_success 'merge-one-file respects GIT_WORK_TREE' ' - (cd bare.git && + (cd bare.git && GIT_DIR=. && export GIT_DIR && mkdir work && GIT_WORK_TREE=$PWD/work && export GIT_WORK_TREE && diff --git a/t/t6136-pathspec-in-bare.sh b/t/t6136-pathspec-in-bare.sh index 1284fe014358e1..db825599cb776a 100755 --- a/t/t6136-pathspec-in-bare.sh +++ b/t/t6136-pathspec-in-bare.sh @@ -11,7 +11,7 @@ test_expect_success 'setup a bare and non-bare repository' ' test_expect_success 'log and ls-files in a bare repository' ' ( - cd bare && + cd bare && GIT_DIR=. && export GIT_DIR && test_must_fail git log -- .. >out 2>err && test_must_be_empty out && test_grep "outside repository" err && @@ -24,7 +24,7 @@ test_expect_success 'log and ls-files in a bare repository' ' test_expect_success 'log and ls-files in .git directory' ' ( - cd .git && + cd .git && GIT_DIR=. && export GIT_DIR && test_must_fail git log -- .. >out 2>err && test_must_be_empty out && test_grep "outside repository" err && diff --git a/t/t7103-reset-bare.sh b/t/t7103-reset-bare.sh index 871e438118a4bc..d234c54512c595 100755 --- a/t/t7103-reset-bare.sh +++ b/t/t7103-reset-bare.sh @@ -43,7 +43,9 @@ test_expect_success 'hard reset works with GIT_WORK_TREE' ' test_expect_success 'setup bare' ' git clone --bare . bare.git && - cd bare.git + cd bare.git && + GIT_DIR=. && + export GIT_DIR ' test_expect_success '"hard" reset is not allowed in bare' ' diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index 1102a9c8f757d1..c73f3a48d5d9f6 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -362,7 +362,7 @@ test_expect_success 'repacking with two filters works' ' ) && git clone --no-local --bare two-filters two-filters.git && ( - cd two-filters.git && + cd two-filters.git && GIT_DIR=. && export GIT_DIR && test_stdout_line_count = 1 ls objects/pack/*.pack && git -c repack.writebitmaps=false repack -a -d \ --filter=blob:none --filter=tree:1 && @@ -389,7 +389,7 @@ prepare_for_keep_packs () { ) && git clone --no-local --bare keep-packs keep-packs.git && ( - cd keep-packs.git && + cd keep-packs.git && GIT_DIR=. && export GIT_DIR && # Create two packs # The first pack will contain all of the objects except one blob @@ -408,7 +408,7 @@ prepare_for_keep_packs () { test_expect_success '--filter works with .keep packs' ' prepare_for_keep_packs && ( - cd keep-packs.git && + cd keep-packs.git && GIT_DIR=. && export GIT_DIR && foo_pack=$(test-tool find-pack -c 1 HEAD:foo.t) && bar_pack=$(test-tool find-pack -c 1 HEAD:bar.t) && @@ -438,7 +438,7 @@ test_expect_success '--filter works with --pack-kept-objects and .keep packs' ' rm -rf keep-packs keep-packs.git && prepare_for_keep_packs && ( - cd keep-packs.git && + cd keep-packs.git && GIT_DIR=. && export GIT_DIR && foo_pack=$(test-tool find-pack -c 1 HEAD:foo.t) && bar_pack=$(test-tool find-pack -c 1 HEAD:bar.t) && @@ -506,7 +506,7 @@ test_expect_success '--filter works with --max-pack-size' ' ) && git clone --no-local --bare max-pack-size max-pack-size.git && ( - cd max-pack-size.git && + cd max-pack-size.git && GIT_DIR=. && export GIT_DIR && git -c repack.writebitmaps=false repack -a -d --filter=blob:none \ --max-pack-size=1M \ --filter-to=../filtered.git/objects/pack/pack && diff --git a/t/t7704-repack-cruft.sh b/t/t7704-repack-cruft.sh index aa2e2e6ad887f2..674673cccb57c8 100755 --- a/t/t7704-repack-cruft.sh +++ b/t/t7704-repack-cruft.sh @@ -109,7 +109,7 @@ test_expect_success '--expire-to stores pruned objects (5.minutes.ago)' ' test_cmp expect actual && ( - cd expired.git && + cd expired.git && GIT_DIR=. && export GIT_DIR && expired="$(ls objects/pack/pack-*.mtimes)" && test-tool pack-mtimes $(basename $expired) >out && diff --git a/t/t7900-maintenance.sh b/t/t7900-maintenance.sh index 4700beacc18281..118c62c89b8cf4 100755 --- a/t/t7900-maintenance.sh +++ b/t/t7900-maintenance.sh @@ -1397,7 +1397,7 @@ test_expect_success 'register and unregister bare repo' ' test_might_fail git config --global --unset-all maintenance.repo && git init --bare barerepo && ( - cd barerepo && + cd barerepo && GIT_DIR=. && export GIT_DIR && git maintenance register && git config --get --global --fixed-value maintenance.repo "$(pwd)" && git maintenance unregister && From 6e899c5da3b12e8b99337447f862a1f0b6cdf348 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 27 Mar 2026 17:44:52 +0100 Subject: [PATCH 08/11] t7103, t9903: prepare for safe.bareRepository=explicit default Several tests enter the `.git` directory (or a bare repository) directly via `cd .git` or `cd bare.git` and then run Git commands from within. When `safe.bareRepository` is set to `explicit`, these commands fail because Git considers the implicitly-discovered bare repository unsafe. A future change, most likely timed for Git v3.0, intends to make `explicit` the default. The naive fix of setting `GIT_DIR=.` does not work here because it changes worktree detection: Git would no longer see the parent as a working tree, breaking tests that specifically verify "this operation requires a work tree" (such as `git reset --hard` inside `.git`). Instead, opt into the current default explicitly via the `GIT_CONFIG_PARAMETERS` environment variable, following existing precedent in t0033-safe-directory.sh. Each affected subshell exports `GIT_CONFIG_PARAMETERS="'safe.bareRepository=all'"` so that the bare-repository safety check passes while preserving the original worktree semantics. This commit was produced with the help of Claude Opus 4.6 acting as a sophisticated keyboard. It was told to add ` && export GIT_CONFIG_PARAMETERS="${SQ}safe.bareRepository=all${SQ}"` after every `cd .git` or `cd bare.git` line inside a subshell that runs Git commands. The purely mechanical nature of the change can be verified by stripping the addition from the diff and confirming that no lines actually changed: git show HEAD | sed 's/ && export GIT_CONFIG_PARAMETERS=.*$//' | sed -ne '/^diff/,/@@/d' -e 's/^[-+]//p' | uniq -u An empty output confirms that every hunk is the same mechanical insertion. Assisted-by: Claude Opus 4.6 Signed-off-by: Johannes Schindelin --- t/t7103-reset-bare.sh | 10 +++++----- t/t9903-bash-prompt.sh | 14 +++++++------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/t/t7103-reset-bare.sh b/t/t7103-reset-bare.sh index d234c54512c595..a7ef69ff9c3ee4 100755 --- a/t/t7103-reset-bare.sh +++ b/t/t7103-reset-bare.sh @@ -13,26 +13,26 @@ test_expect_success 'setup non-bare' ' ' test_expect_success '"hard" reset requires a worktree' ' - (cd .git && + (cd .git && export GIT_CONFIG_PARAMETERS="${SQ}safe.bareRepository=all${SQ}" && test_must_fail git reset --hard) ' test_expect_success '"merge" reset requires a worktree' ' - (cd .git && + (cd .git && export GIT_CONFIG_PARAMETERS="${SQ}safe.bareRepository=all${SQ}" && test_must_fail git reset --merge) ' test_expect_success '"keep" reset requires a worktree' ' - (cd .git && + (cd .git && export GIT_CONFIG_PARAMETERS="${SQ}safe.bareRepository=all${SQ}" && test_must_fail git reset --keep) ' test_expect_success '"mixed" reset is ok' ' - (cd .git && git reset) + (cd .git && export GIT_CONFIG_PARAMETERS="${SQ}safe.bareRepository=all${SQ}" && git reset) ' test_expect_success '"soft" reset is ok' ' - (cd .git && git reset --soft) + (cd .git && export GIT_CONFIG_PARAMETERS="${SQ}safe.bareRepository=all${SQ}" && git reset --soft) ' test_expect_success 'hard reset works with GIT_WORK_TREE' ' diff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh index 637a6f13a6d9b3..13846e28d5e5f1 100755 --- a/t/t9903-bash-prompt.sh +++ b/t/t9903-bash-prompt.sh @@ -135,7 +135,7 @@ test_expect_success 'prompt - describe detached head - default' ' test_expect_success 'prompt - inside .git directory' ' printf " (GIT_DIR!)" >expected && ( - cd .git && + cd .git && export GIT_CONFIG_PARAMETERS="${SQ}safe.bareRepository=all${SQ}" && __git_ps1 >"$actual" ) && test_cmp expected "$actual" @@ -155,7 +155,7 @@ test_expect_success 'prompt - inside bare repository' ' git init --bare bare.git && test_when_finished "rm -rf bare.git" && ( - cd bare.git && + cd bare.git && export GIT_CONFIG_PARAMETERS="${SQ}safe.bareRepository=all${SQ}" && __git_ps1 >"$actual" ) && test_cmp expected "$actual" @@ -374,7 +374,7 @@ test_expect_success 'prompt - dirty status indicator - not shown inside .git dir test_when_finished "git reset --hard" && ( GIT_PS1_SHOWDIRTYSTATE=y && - cd .git && + cd .git && export GIT_CONFIG_PARAMETERS="${SQ}safe.bareRepository=all${SQ}" && __git_ps1 >"$actual" ) && test_cmp expected "$actual" @@ -409,7 +409,7 @@ test_expect_success 'prompt - stash status indicator - not shown inside .git dir test_when_finished "git stash drop" && ( GIT_PS1_SHOWSTASHSTATE=y && - cd .git && + cd .git && export GIT_CONFIG_PARAMETERS="${SQ}safe.bareRepository=all${SQ}" && __git_ps1 >"$actual" ) && test_cmp expected "$actual" @@ -514,7 +514,7 @@ test_expect_success 'prompt - untracked files status indicator - not shown insid printf " (GIT_DIR!)" >expected && ( GIT_PS1_SHOWUNTRACKEDFILES=y && - cd .git && + cd .git && export GIT_CONFIG_PARAMETERS="${SQ}safe.bareRepository=all${SQ}" && __git_ps1 >"$actual" ) && test_cmp expected "$actual" @@ -619,7 +619,7 @@ test_expect_success 'prompt - bash color pc mode - inside .git directory' ' ( GIT_PS1_SHOWDIRTYSTATE=y && GIT_PS1_SHOWCOLORHINTS=y && - cd .git && + cd .git && export GIT_CONFIG_PARAMETERS="${SQ}safe.bareRepository=all${SQ}" && __git_ps1 "BEFORE:" ":AFTER" && printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual" ) && @@ -749,7 +749,7 @@ test_expect_success 'prompt - hide if pwd ignored - inside gitdir' ' printf " (GIT_DIR!)" >expected && ( GIT_PS1_HIDE_IF_PWD_IGNORED=y && - cd .git && + cd .git && export GIT_CONFIG_PARAMETERS="${SQ}safe.bareRepository=all${SQ}" && __git_ps1 >"$actual" ) && test_cmp expected "$actual" From 9d4fafe7f48733d44a5d44d09745492dbbd555ba Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 27 Mar 2026 17:44:53 +0100 Subject: [PATCH 09/11] category-H --- t/t0001-init.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/t/t0001-init.sh b/t/t0001-init.sh index dd3884060520b2..ec1b0ae75aff0d 100755 --- a/t/t0001-init.sh +++ b/t/t0001-init.sh @@ -77,6 +77,7 @@ test_expect_success 'plain nested through aliased command' ' ' test_expect_success 'plain nested in bare through aliased command' ' + test_config_global safe.bareRepository all && ( git init --bare bare-ancestor-aliased.git && cd bare-ancestor-aliased.git && From 9d973bba74f719b8e63f0a59928df3f0f6961fcd Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 27 Mar 2026 17:44:54 +0100 Subject: [PATCH 10/11] category-L --- t/t6020-bundle-misc.sh | 4 ++-- t/t9210-scalar.sh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/t/t6020-bundle-misc.sh b/t/t6020-bundle-misc.sh index 9850541f59e4ae..da960af519c561 100755 --- a/t/t6020-bundle-misc.sh +++ b/t/t6020-bundle-misc.sh @@ -594,9 +594,9 @@ do reflist=$(git for-each-ref --format="%(objectname)") && git rev-list --objects --filter=$filter --missing=allow-any \ $reflist >expect && - for repo in cloned unbundled + for opt in "--git-dir cloned" "-C unbundled" do - git -C $repo rev-list --objects --missing=allow-any \ + git $opt rev-list --objects --missing=allow-any \ $reflist >actual && test_cmp expect actual || return 1 done diff --git a/t/t9210-scalar.sh b/t/t9210-scalar.sh index 009437a5f3168f..54513c220b679a 100755 --- a/t/t9210-scalar.sh +++ b/t/t9210-scalar.sh @@ -88,7 +88,7 @@ test_expect_success 'scalar enlistments need a worktree' ' test_when_finished rm -rf bare test && git init --bare bare/src && - ! scalar register bare/src 2>err && + ! scalar -c safe.bareRepository=all register bare/src 2>err && grep "Scalar enlistments require a worktree" err && git init test/src && From a30a801be521b15c94d4b3b058a663b587339e4e Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Mon, 23 Mar 2026 20:08:41 +0100 Subject: [PATCH 11/11] safe.bareRepository: default to "explicit" with WITH_BREAKING_CHANGES When an attacker can convince a user to clone a crafted repository that contains an embedded bare repository with malicious hooks, any Git command the user runs after entering that subdirectory will discover the bare repository and execute the hooks. The user does not even need to run a Git command explicitly: many shell prompts run `git status` in the background to display branch and dirty state information, and `git status` in turn may invoke the fsmonitor hook if so configured, making the user vulnerable the moment they `cd` into the directory. The safe.bareRepository configuration variable (introduced in 8959555cee7e (setup_git_directory(): add an owner check for the top-level directory, 2022-03-02)) already provides protection against this attack vector by allowing users to set it to "explicit", but the default remained "all" for backwards compatibility. Since Git 3.0 is the natural point to change defaults to safer values, flip the default from "all" to "explicit" when built with WITH_BREAKING_CHANGES. This means Git will refuse to work with bare repositories that are discovered implicitly by walking up the directory tree. Bare repositories specified via --git-dir or GIT_DIR continue to work, and directories that look like .git, worktrees, or submodule directories are unaffected (the existing is_implicit_bare_repo() whitelist handles those cases). Users who rely on implicit bare repository discovery can restore the previous behavior by setting safe.bareRepository=all in their global or system configuration. The test for the "safe.bareRepository in the repository" scenario needed a more involved fix: it writes a safe.bareRepository=all entry into the bare repository's own config to verify that repo-local config does not override the protected (global) setting. Previously, test_config -C was used to write that entry, but its cleanup runs git -C config --unset, which itself fails when the default is "explicit" and the global config has already been cleaned up. Switching to direct git config --file access avoids going through repository discovery entirely. Assisted-by: Claude Opus 4.6 Signed-off-by: Johannes Schindelin --- Documentation/BreakingChanges.adoc | 24 ++++++++++++++++++++++++ Documentation/config/safe.adoc | 10 ++++++++-- setup.c | 4 ++++ t/t0035-safe-bare-repository.sh | 10 ++++++++-- 4 files changed, 44 insertions(+), 4 deletions(-) diff --git a/Documentation/BreakingChanges.adoc b/Documentation/BreakingChanges.adoc index f814450d2f65ac..f680d524d56ba3 100644 --- a/Documentation/BreakingChanges.adoc +++ b/Documentation/BreakingChanges.adoc @@ -216,6 +216,30 @@ would be significant, we may decide to defer this change to a subsequent minor release. This evaluation will also take into account our own experience with how painful it is to keep Rust an optional component. +* The default value of `safe.bareRepository` will change from `all` to + `explicit`. It is all too easy for an attacker to trick a user into cloning a + repository that contains an embedded bare repository with malicious hooks + configured. If the user enters that subdirectory and runs any Git command, Git + discovers the bare repository and the hooks fire. The user does not even need + to run a Git command explicitly: many shell prompts run `git status` in the + background to display branch and dirty state information, and `git status` in + turn may invoke the fsmonitor hook if so configured, making the user + vulnerable the moment they `cd` into the directory. The `safe.bareRepository` + configuration variable was introduced in 8959555cee (setup_git_directory(): + add an owner check for the top-level directory, 2022-03-02) with a default of + `all` to preserve backwards compatibility. ++ +Changing the default to `explicit` means that Git will refuse to work with bare +repositories that are discovered implicitly by walking up the directory tree. +Bare repositories specified explicitly via the `--git-dir` command-line option +or the `GIT_DIR` environment variable continue to work regardless of this +setting. Repositories that look like a `.git` directory, a worktree, or a +submodule directory are also unaffected. ++ +Users who rely on implicit discovery of bare repositories can restore the +previous behavior by setting `safe.bareRepository=all` in their global or +system configuration. + === Removals * Support for grafting commits has long been superseded by git-replace(1). diff --git a/Documentation/config/safe.adoc b/Documentation/config/safe.adoc index 2d45c98b12d951..5b1690aebe8f58 100644 --- a/Documentation/config/safe.adoc +++ b/Documentation/config/safe.adoc @@ -2,10 +2,12 @@ safe.bareRepository:: Specifies which bare repositories Git will work with. The currently supported values are: + -* `all`: Git works with all bare repositories. This is the default. +* `all`: Git works with all bare repositories. This is the default in + Git 2.x. * `explicit`: Git only works with bare repositories specified via the top-level `--git-dir` command-line option, or the `GIT_DIR` - environment variable (see linkgit:git[1]). + environment variable (see linkgit:git[1]). This will be the default + in Git 3.0. + If you do not use bare repositories in your workflow, then it may be beneficial to set `safe.bareRepository` to `explicit` in your global @@ -13,6 +15,10 @@ config. This will protect you from attacks that involve cloning a repository that contains a bare repository and running a Git command within that directory. + +If you use bare repositories regularly and want to preserve the current +behavior after upgrading to Git 3.0, set `safe.bareRepository` to `all` +in your global or system config. ++ This config setting is only respected in protected configuration (see <>). This prevents untrusted repositories from tampering with this value. diff --git a/setup.c b/setup.c index 7ec4427368a2a7..17c0662076487e 100644 --- a/setup.c +++ b/setup.c @@ -1485,7 +1485,11 @@ static int allowed_bare_repo_cb(const char *key, const char *value, static enum allowed_bare_repo get_allowed_bare_repo(void) { +#ifdef WITH_BREAKING_CHANGES + enum allowed_bare_repo result = ALLOWED_BARE_REPO_EXPLICIT; +#else enum allowed_bare_repo result = ALLOWED_BARE_REPO_ALL; +#endif git_protected_config(allowed_bare_repo_cb, &result); return result; } diff --git a/t/t0035-safe-bare-repository.sh b/t/t0035-safe-bare-repository.sh index ae7ef092abf6d9..1d3d19f5b476a0 100755 --- a/t/t0035-safe-bare-repository.sh +++ b/t/t0035-safe-bare-repository.sh @@ -44,11 +44,16 @@ test_expect_success 'setup an embedded bare repo, secondary worktree and submodu test_path_is_dir outer-repo/.git/modules/subn ' -test_expect_success 'safe.bareRepository unset' ' +test_expect_success !WITH_BREAKING_CHANGES 'safe.bareRepository unset' ' test_unconfig --global safe.bareRepository && expect_accepted_implicit -C outer-repo/bare-repo ' +test_expect_success WITH_BREAKING_CHANGES 'safe.bareRepository unset (defaults to explicit)' ' + test_unconfig --global safe.bareRepository && + expect_rejected -C outer-repo/bare-repo +' + test_expect_success 'safe.bareRepository=all' ' test_config_global safe.bareRepository all && expect_accepted_implicit -C outer-repo/bare-repo @@ -63,7 +68,8 @@ test_expect_success 'safe.bareRepository in the repository' ' # safe.bareRepository must not be "explicit", otherwise # git config fails with "fatal: not in a git directory" (like # safe.directory) - test_config -C outer-repo/bare-repo safe.bareRepository all && + test_when_finished "git config --file outer-repo/bare-repo/config --unset safe.bareRepository" && + git config --file outer-repo/bare-repo/config safe.bareRepository all && test_config_global safe.bareRepository explicit && expect_rejected -C outer-repo/bare-repo '