path: root/builtin/init-db.c
diff options
authorJeff King <>2010-05-10 09:42:06 (GMT)
committerJunio C Hamano <>2010-05-10 18:25:37 (GMT)
commit87a074df2455f305df8facc22e85dac1cfeb0d6b (patch)
treeddc38543916d6dc2bc3f2e700278ca85365df2b1 /builtin/init-db.c
parent43acff34b902c38808ac0f326090f2516250e1f0 (diff)
handle "git --bare init <dir>" properly
If we know we are creating a bare repository, we use setenv to set the GIT_DIR directory to the current directory (either where we already were, or one we created and chdir'd into with "git init --bare <dir>"). However, with "git --bare init <dir>" (note the --bare as a git wrapper option), the setup code actually sets GIT_DIR for us, but it uses the wrong, original cwd when a directory is given. Because our setenv does not use the overwrite flag, it is ignored. We need to set the overwrite flag, but only when we are given a directory on the command line. That still allows: GIT_DIR=foo.git git init --bare to work. The behavior is changed for: GIT_DIR=foo.git git init --bare bar.git which used to create the repository in foo.git, but now will use bar.git. This is more sane, as command line options should generally override the environment. Noticed by Oliver Hoffmann. Signed-off-by: Jeff King <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'builtin/init-db.c')
1 files changed, 1 insertions, 1 deletions
diff --git a/builtin/init-db.c b/builtin/init-db.c
index edc40ff..0271285 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -463,7 +463,7 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
static char git_dir[PATH_MAX+1];
- getcwd(git_dir, sizeof(git_dir)), 0);
+ getcwd(git_dir, sizeof(git_dir)), argc > 0);
if (init_shared_repository != -1)