{"thread":{"id":"23743","subject":"git init --bare versus git --bare init","startedAt":"2010-05-08T10:38:13Z","lastAt":"2010-05-10T09:42:06Z","messageCount":2,"participants":["Oliver Hoffmann","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"141243","messageId":"201005081238.14156.oliverhoffmann32@googlemail.com","threadId":"23743","inReplyTo":null,"subject":"git init --bare versus git --bare init","fromName":"Oliver Hoffmann","fromEmail":"oliverhoffmann32@googlemail.com","sentAt":"2010-05-08T10:38:13Z","receivedAt":"2010-05-08T10:38:13Z","isPatch":false,"sender":{"key":"oliverhoffmann32@googlemail.com","avatar":null},"body":"Hi Git Folk,\n\nIf one accidentally writes \"git --bare init <dir>\" instead of \"git init --bare \n<dir>\" an appended directory argument is ignored and $CUR_DIR or the working \ndirectory will be used:\n\n> pwd\n/tmp/foo\n> git --bare init /tmp/bar\nInitialized empty Git repository in /tmp/foo/\n> git init --bare /tmp/bar\nInitialized empty Git repository in /tmp/bar/\n\n... but both should probably be initialized in /tmp/bar/\n\nGreetings,\nOliver Hoffmann\n"},{"id":"141364","messageId":"20100510094206.GA30869@coredump.intra.peff.net","threadId":"23743","inReplyTo":"201005081238.14156.oliverhoffmann32@googlemail.com","subject":"[PATCH] handle \"git --bare init <dir>\" properly","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2010-05-10T09:42:06Z","receivedAt":"2010-05-10T09:42:06Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"If we know we are creating a bare repository, we use setenv\nto set the GIT_DIR directory to the current directory\n(either where we already were, or one we created and chdir'd\ninto with \"git init --bare <dir>\").\n\nHowever, with \"git --bare init <dir>\" (note the --bare as a\ngit wrapper option), the setup code actually sets GIT_DIR\nfor us, but it uses the wrong, original cwd when a directory\nis given. Because our setenv does not use the overwrite\nflag, it is ignored.\n\nWe need to set the overwrite flag, but only when we are\ngiven a directory on the command line. That still allows:\n\n  GIT_DIR=foo.git git init --bare\n\nto work. The behavior is changed for:\n\n  GIT_DIR=foo.git git init --bare bar.git\n\nwhich used to create the repository in foo.git, but now will\nuse bar.git. This is more sane, as command line options\nshould generally override the environment.\n\nNoticed by Oliver Hoffmann.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\nThanks for the bug report, Oliver.\n\n builtin/init-db.c |    2 +-\n t/t0001-init.sh   |   14 ++++++++++++++\n 2 files changed, 15 insertions(+), 1 deletions(-)\n\ndiff --git a/builtin/init-db.c b/builtin/init-db.c\nindex edc40ff..0271285 100644\n--- a/builtin/init-db.c\n+++ b/builtin/init-db.c\n@@ -463,7 +463,7 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)\n \t\tstatic char git_dir[PATH_MAX+1];\n \n \t\tsetenv(GIT_DIR_ENVIRONMENT,\n-\t\t\tgetcwd(git_dir, sizeof(git_dir)), 0);\n+\t\t\tgetcwd(git_dir, sizeof(git_dir)), argc > 0);\n \t}\n \n \tif (init_shared_repository != -1)\ndiff --git a/t/t0001-init.sh b/t/t0001-init.sh\nindex 6757734..7c0a698 100755\n--- a/t/t0001-init.sh\n+++ b/t/t0001-init.sh\n@@ -310,4 +310,18 @@ test_expect_success POSIXPERM 'init notices EPERM' '\n \t)\n '\n \n+test_expect_success 'init creates a new bare directory with global --bare' '\n+\trm -rf newdir &&\n+\tgit --bare init newdir &&\n+\ttest -d newdir/refs\n+'\n+\n+test_expect_success 'init prefers command line to GIT_DIR' '\n+\trm -rf newdir &&\n+\tmkdir otherdir &&\n+\tGIT_DIR=otherdir git --bare init newdir &&\n+\ttest -d newdir/refs &&\n+\t! test -d otherdir/refs\n+'\n+\n test_done\n-- \n1.7.1.248.gf52fc.dirty\n"}]}