Skip to content

Commit 81bcdc2

Browse files
committed
test-tool: add a --git-dir option
8d1a744 (setup.c: create `safe.bareRepository`, 2022-07-14) introduced the `safe.bareRepository` config setting that can reject implicit bare repository discovery. It defaults to `all` for now, but the commit message already describes the social engineering attack that motivates changing that default to `explicit` at some point. When that day comes, any `test-tool -C <bare-repo>` invocation will trigger implicit discovery and be refused. Add a `--git-dir=<path>` option that works the same way `git --git-dir=<path>` does: it calls `setenv(GIT_DIR_ENVIRONMENT, ...)` before dispatching to the subcommand, bypassing repository discovery entirely. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 1f8a88e commit 81bcdc2

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

t/helper/test-tool.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
#include "test-tool-utils.h"
44
#include "trace2.h"
55
#include "parse-options.h"
6+
#include "environment.h"
67

78
static const char * const test_tool_usage[] = {
8-
"test-tool [-C <directory>] <command [<arguments>...]]",
9+
"test-tool [-C <directory>] [--git-dir=<path>] <command [<arguments>...]]",
910
NULL
1011
};
1112

@@ -107,9 +108,12 @@ static NORETURN void die_usage(void)
107108
int cmd_main(int argc, const char **argv)
108109
{
109110
const char *working_directory = NULL;
111+
const char *git_dir = NULL;
110112
struct option options[] = {
111113
OPT_STRING('C', NULL, &working_directory, "directory",
112114
"change the working directory"),
115+
OPT_STRING(0, "git-dir", &git_dir, "path",
116+
"set the path to the repository"),
113117
OPT_END()
114118
};
115119

@@ -123,6 +127,8 @@ int cmd_main(int argc, const char **argv)
123127

124128
if (working_directory && chdir(working_directory) < 0)
125129
die("Could not cd to '%s'", working_directory);
130+
if (git_dir)
131+
setenv(GIT_DIR_ENVIRONMENT, git_dir, 1);
126132

127133
for (size_t i = 0; i < ARRAY_SIZE(cmds); i++) {
128134
if (!strcmp(cmds[i].name, argv[1])) {

0 commit comments

Comments
 (0)