{"thread":{"id":"9534","subject":"git clone regression","startedAt":"2007-08-15T12:28:26Z","lastAt":"2007-08-27T10:54:48Z","messageCount":8,"participants":["Junio C Hamano","Johannes Schindelin"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"50767","messageId":"7v643hrnh1.fsf@gitster.siamese.dyndns.org","threadId":"9534","inReplyTo":null,"subject":"git clone regression","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-08-15T12:28:26Z","receivedAt":"2007-08-15T12:28:26Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"It appears that with 1.5.3-rc5\n\n\t$ git clone --bare $origin_url target.git\n\ndoes not set \"core.bare = true\" in target.git/config.  We used\nto, at least with 1.5.2.2.  I am strongly suspecting that this\nis another fallout from the worktree series.\n"},{"id":"50791","messageId":"Pine.LNX.4.64.0708151821260.19496@wbgn129.biozentrum.uni-wuerzburg.de","threadId":"9534","inReplyTo":"7v643hrnh1.fsf@gitster.siamese.dyndns.org","subject":"[PATCH] Fix initialization of a bare repository","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-08-15T16:25:44Z","receivedAt":"2007-08-15T16:25:44Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nThe recent work-tree cleanup broke it; core.bare was set to false\nerroneously when calling \"git --bare init\".  Coincidentally, this\nfixes \"git clone --bare\", too.\n\nNoticed by Junio Hamano.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n\n\tOn Wed, 15 Aug 2007, Junio C Hamano wrote:\n\n\t> It appears that with 1.5.3-rc5\n\t> \n\t> \t$ git clone --bare $origin_url target.git\n\t> \n\t> does not set \"core.bare = true\" in target.git/config.  We used\n\t> to, at least with 1.5.2.2.  I am strongly suspecting that this\n\t> is another fallout from the worktree series.\n\n\tSorry.  Yes, this is another fallout.\n\n\tMaybe this is not enough, though.  Maybe we need to check if the \n\tGIT_DIR=. too, since 7efeb8f0 would set the work tree to \".\", too.\n\n\tBut maybe this would merit a separate fix in set_work_tree(), like\n\n\t\tif (!strcmp(getenv(GIT_DIR_ENVIRONMENT), \".\")) {\n\t\t\tinside_work_tree = 0;\n\t\t\treturn NULL;\n\t\t}\n\n\tHmm?\n\n builtin-init-db.c |   13 ++++++++-----\n git.c             |    1 +\n 2 files changed, 9 insertions(+), 5 deletions(-)\n\ndiff --git a/builtin-init-db.c b/builtin-init-db.c\nindex 75fb227..2e45a7e 100644\n--- a/builtin-init-db.c\n+++ b/builtin-init-db.c\n@@ -302,11 +302,14 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)\n \t\t\tusage(init_db_usage);\n \t}\n \n-\tgit_work_tree_cfg = xcalloc(PATH_MAX, 1);\n-\tif (!getcwd(git_work_tree_cfg, PATH_MAX))\n-\t\tdie (\"Cannot access current working directory.\");\n-\tif (access(get_git_work_tree(), X_OK))\n-\t\tdie (\"Cannot access work tree '%s'\", get_git_work_tree());\n+\tif (!is_bare_repository_cfg) {\n+\t\tgit_work_tree_cfg = xcalloc(PATH_MAX, 1);\n+\t\tif (!getcwd(git_work_tree_cfg, PATH_MAX))\n+\t\t\tdie (\"Cannot access current working directory.\");\n+\t\tif (access(get_git_work_tree(), X_OK))\n+\t\t\tdie (\"Cannot access work tree '%s'\",\n+\t\t\t\t\tget_git_work_tree());\n+\t}\n \n \t/*\n \t * Set up the default .git directory contents\ndiff --git a/git.c b/git.c\nindex 1bf2744..f0062a0 100644\n--- a/git.c\n+++ b/git.c\n@@ -100,6 +100,7 @@ static int handle_options(const char*** argv, int* argc, int* envchanged)\n \t\t} else if (!strcmp(cmd, \"--bare\")) {\n \t\t\tstatic char git_dir[PATH_MAX+1];\n \t\t\tsetenv(GIT_DIR_ENVIRONMENT, getcwd(git_dir, sizeof(git_dir)), 1);\n+\t\t\tis_bare_repository_cfg = 1;\n \t\t} else if (!strcmp(cmd, \"-2\") ||\n \t\t\t\t!strcmp(cmd, \"--redirect-stderr\")) {\n \t\t\tif (dup2(1, 2) < 0)\n-- \n1.5.1.rc1.4887.ga4a43-dirty\n"},{"id":"50809","messageId":"7vlkccr4wu.fsf@gitster.siamese.dyndns.org","threadId":"9534","inReplyTo":"Pine.LNX.4.64.0708151821260.19496@wbgn129.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] Fix initialization of a bare repository","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-08-15T19:09:21Z","receivedAt":"2007-08-15T19:09:21Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n> \tMaybe this is not enough, though.  Maybe we need to check if the \n> \tGIT_DIR=. too, since 7efeb8f0 would set the work tree to \".\", too.\n>\n> \tBut maybe this would merit a separate fix in set_work_tree(), like\n>\n> \t\tif (!strcmp(getenv(GIT_DIR_ENVIRONMENT), \".\")) {\n> \t\t\tinside_work_tree = 0;\n> \t\t\treturn NULL;\n> \t\t}\n>\n> \tHmm?\n\nI do not know.  If you treat \".\" differently from a pathname\nthat is the same as what $(pwd) would give you, you will confuse\neven more users.\n\nCurrently we have:\n\n - char *git_work_tree_cfg: the location of the work tree when\n   $GIT_WORK_TREE nor --work-tree option is in use.  Contrary to\n   the name of the variable, it does not necessarily come from\n   core.worktree.  This comes from core.worktree if set,\n   otherwise derived from the location of the repository\n   (i.e. unless $GIT_DIR is set, above \"/.git\" of the found\n   repository, otherwise \".\").\n\n - char *work_tree: the location of the work tree, which comes\n   from $GIT_WORK_TREE (or --work-tree option) if set, otherwise\n   git_work_tree_cfg above.\n\n - int inside_work_tree: is $(cwd) inside of the work tree (if\n   we have one)?\n\n - int is_bare_repository_cfg: are we treating this repository\n   as bare?  Contrary to the name of the variable, it does not\n   necessarily come from core.bare (get_git_work_tree()\n   overwrites the value found in core.bare to false in if we\n   have a work_tree).\n\n - int is_bare_repository(): are we treating this repository\n   as bare?  This is the function the callers usually use.\n\nI think tying the presense of work_tree and repository bareness\nas is_bare_repository() does is almost always right for the\nnormal callers.  One valid use of GIT_WORK_TREE is to put a work\ntree to a repository otherwise declared as a bare one.\n\nBut obviously init-db is rather a special case with a chicken\nand egg problem.  What it wants to know is not if we are\ncurrently treating the repository as a bare one, but if we would\nwant to mark its core.bare with \"this should be normally treated\nas bare\".  Your patch treats this special case as such without\naffecting the normal codepath, which I think is a sane thing to\ndo.\n\nThanks for a quick fix.\n"},{"id":"50810","messageId":"7v8x8cr444.fsf@gitster.siamese.dyndns.org","threadId":"9534","inReplyTo":"7vlkccr4wu.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH] Fix initialization of a bare repository","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-08-15T19:26:35Z","receivedAt":"2007-08-15T19:26:35Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Thanks for a quick fix.\n\nGaah.  I spoke way too early.  This breaks even more things than\nit fixes.  Even something as simple as \"git add .\" does not work\nanymore.\n"},{"id":"50814","messageId":"7vhcn0pm3h.fsf@gitster.siamese.dyndns.org","threadId":"9534","inReplyTo":"Pine.LNX.4.64.0708151821260.19496@wbgn129.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] Fix initialization of a bare repository","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-08-15T20:41:06Z","receivedAt":"2007-08-15T20:41:06Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Wait a minute.\n\nLet's step back a bit and think what we want to happen here.\n\n * No GIT_DIR, no --bare.  Having GIT_WORK_TREE is an error.\n\n   $ mkdir foo && cd foo && git init\n\n   We want to say \"not bare\" and create foo/.git/config and friends. \n\n * No GIT_DIR, with --bare.  Having GIT_WORK_TREE is an error.\n\n   $ mkdir foo && cd foo && git --bare init\n\n   We want to say \"is bare\" and create foo/config, foo/HEAD and\n   friends.\n\n * With GIT_DIR but no GIT_WORK_TREE, with or without --bare.\n\n   $ mkdir foo.git && GIT_DIR=foo.git git init\n   $ mkdir foo.git && GIT_DIR=foo.git git --bare init\n\n   We want to say \"is bare\" and create foo.git/config and friends.\n\n * With GIT_DIR and GIT_WORK_TREE.  Having --bare is an error.\n\n   $ mkdir foo.git foo.work\n   $ GIT_DIR=foo.git GIT_WORK_TREE=foo.work git init\n\n   We want to say \"not bare\", create foo.git/config and friends,\n   and record core.worktree = /full/path/to/foo.work\n\nIs the above list reasonable?\n\n---\n\n t/t0001-init.sh |  111 +++++++++++++++++++++++++++++++++++++++++++++++++++++++\n 1 files changed, 111 insertions(+), 0 deletions(-)\n create mode 100755 t/t0001-init.sh\n\ndiff --git a/t/t0001-init.sh b/t/t0001-init.sh\nnew file mode 100755\nindex 0000000..9fb2b59\n--- /dev/null\n+++ b/t/t0001-init.sh\n@@ -0,0 +1,111 @@\n+#!/bin/sh\n+\n+test_description='git init'\n+\n+. ./test-lib.sh\n+\n+check_config () {\n+\tif test -d \"$1\" && test -f \"$1/config\" && test -d \"$1/refs\"\n+\tthen\n+\t\t: happy\n+\telse\n+\t\techo \"expected a directory $1, a file $1/config and $1/refs\"\n+\t\treturn 1\n+\tfi\n+\tbare=$(GIT_CONFIG=\"$1/config\" git config --bool core.bare)\n+\tworktree=$(GIT_CONFIG=\"$1/config\" git config core.worktree) ||\n+\tworktree=unset\n+\n+\ttest \"$bare\" = \"$2\" && test \"$worktree\" = \"$3\" || {\n+\t\techo \"expected bare=$2 worktree=$3\"\n+\t\techo \"     got bare=$bare worktree=$worktree\"\n+\t\treturn 1\n+\t}\n+}\n+\n+test_expect_success 'plain' '\n+\t(\n+\t\tunset GIT_DIR GIT_WORK_TREE &&\n+\t\tmkdir plain &&\n+\t\tcd plain &&\n+\t\tgit init\n+\t) &&\n+\tcheck_config plain/.git false unset\n+'\n+\n+test_expect_success 'plain with GIT_WORK_TREE' '\n+\tif (\n+\t\tunset GIT_DIR &&\n+\t\tmkdir plain-wt &&\n+\t\tcd plain-wt &&\n+\t\tGIT_WORK_TREE=$(pwd) git init\n+\t)\n+\tthen\n+\t\techo Should have failed -- GIT_WORK_TREE should not be used\n+\t\tfalse\n+\tfi\n+'\n+\n+test_expect_success 'plain bare' '\n+\t(\n+\t\tunset GIT_DIR GIT_WORK_TREE &&\n+\t\tmkdir plain-bare &&\n+\t\tcd plain-bare &&\n+\t\tgit --bare init\n+\t) &&\n+\tcheck_config plain-bare true unset\n+'\n+\n+test_expect_success 'plain bare with GIT_WORK_TREE' '\n+\tif (\n+\t\tunset GIT_DIR &&\n+\t\tmkdir plain-bare &&\n+\t\tcd plain-bare &&\n+\t\tGIT_WORK_TREE=$(pwd) git --bare init\n+\t)\n+\tthen\n+\t\techo Should have failed -- GIT_WORK_TREE should not be used\n+\t\tfalse\n+\tfi\n+'\n+\n+test_expect_success 'GIT_DIR bare (1)' '\n+\n+\t(\n+\t\tmkdir git-dir-bare-1.git &&\n+\t\tGIT_DIR=git-dir-bare-1.git git init\n+\t) &&\n+\tcheck_config git-dir-bare-1.git true unset\n+'\n+\n+test_expect_success 'GIT_DIR bare (2)' '\n+\n+\t(\n+\t\tmkdir git-dir-bare-2.git &&\n+\t\tGIT_DIR=git-dir-bare-2.git git --bare init\n+\t) &&\n+\tcheck_config git-dir-bare-2.git true unset\n+'\n+\n+test_expect_success 'GIT_DIR & GIT_WORK_TREE (1)' '\n+\n+\t(\n+\t\tmkdir git-dir-wt-1.git &&\n+\t\tGIT_WORK_TREE=$(pwd) GIT_DIR=git-dir-wt-1.git git init\n+\t) &&\n+\tcheck_config git-dir-wt-1.git false \"$(pwd)\"\n+'\n+\n+test_expect_success 'GIT_DIR & GIT_WORK_TREE (2)' '\n+\n+\tif (\n+\t\tmkdir git-dir-wt-2.git &&\n+\t\tGIT_WORK_TREE=$(pwd) GIT_DIR=git-dir-wt-2.git git --bare init\n+\t)\n+\tthen\n+\t\techo Should have failed -- --bare should not be used\n+\t\tfalse\n+\tfi\n+'\n+\n+test_done\n"},{"id":"50963","messageId":"Pine.LNX.4.64.0708172319480.20400@racer.site","threadId":"9534","inReplyTo":"7vhcn0pm3h.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH] Fix initialization of a bare repository","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-08-17T22:20:21Z","receivedAt":"2007-08-17T22:20:21Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Wed, 15 Aug 2007, Junio C Hamano wrote:\n\n> Wait a minute.\n> \n> Let's step back a bit and think what we want to happen here.\n> \n>  * No GIT_DIR, no --bare.  Having GIT_WORK_TREE is an error.\n> \n>    $ mkdir foo && cd foo && git init\n> \n>    We want to say \"not bare\" and create foo/.git/config and friends. \n> \n>  * No GIT_DIR, with --bare.  Having GIT_WORK_TREE is an error.\n> \n>    $ mkdir foo && cd foo && git --bare init\n> \n>    We want to say \"is bare\" and create foo/config, foo/HEAD and\n>    friends.\n> \n>  * With GIT_DIR but no GIT_WORK_TREE, with or without --bare.\n> \n>    $ mkdir foo.git && GIT_DIR=foo.git git init\n>    $ mkdir foo.git && GIT_DIR=foo.git git --bare init\n> \n>    We want to say \"is bare\" and create foo.git/config and friends.\n> \n>  * With GIT_DIR and GIT_WORK_TREE.  Having --bare is an error.\n> \n>    $ mkdir foo.git foo.work\n>    $ GIT_DIR=foo.git GIT_WORK_TREE=foo.work git init\n> \n>    We want to say \"not bare\", create foo.git/config and friends,\n>    and record core.worktree = /full/path/to/foo.work\n> \n> Is the above list reasonable?\n\nYes.  I'll try to work on it the day after tomorrow.\n\nCiao,\nDscho\n"},{"id":"51642","messageId":"7v7inhmmsx.fsf_-_@gitster.siamese.dyndns.org","threadId":"9534","inReplyTo":"7vhcn0pm3h.fsf@gitster.siamese.dyndns.org","subject":"[PATCH/RFH] Fix initialization of a bare repository","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-08-27T07:58:06Z","receivedAt":"2007-08-27T07:58:06Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Here is my attempt to fix this with a minimally intrusive patch.\n\n * As \"git --bare init\" cannot tell if it was called with --bare or\n   just \"GIT_DIR=. git init\", I added an explicit assignment of\n   is_bare_repository_cfg on the codepath for \"git --bare\".\n\n * GIT_WORK_TREE alone without GIT_DIR does not make any sense,\n   nor GIT_WORK_TREE with an explicit \"git --bare\".  Catch that\n   mistake.  It might make sense to move this check to \"git.c\"\n   side as well, but I tried to shoot for the minimum change for\n   now.\n\n * Some scripts, especially from the olden days, rely on\n   traditional GIT_DIR behaviour in \"git init\".  Namely, these\n   are some notable patterns:\n\n   (create a bare repository)\n   - mkdir some.git && cd some.git && GIT_DIR=. git init\n   - mkdir some.git && cd some.git && git --bare init\n\n   (create a non-bare repository)\n   - mkdir .git && GIT_DIR=.git git init\n   - mkdir .git && GIT_DIR=`pwd`/.git git init\n\nThis comes with a new test script and also passes the existing\ntest suite, but there may be cases that are still broken with\nthe current tip of master and this patch does not yet fix.  I'd\nappreciate help in straightening this mess out.\n\n---\n\n * The test script I sent earlier was botched in some details.\n\n   Most notably, it allowed GIT_CONFIG that is exported by the\n   test scaffolding to affect behaviour of git-init, and tried\n   to see if the resulting repository had correct config, which\n   was nonsense.  Also \"GIT_DIR bare (2)\" test (removed in this\n   iteration) was about \"GIT_DIR=somewhere git --bare init\", but\n   \"git --bare\" is defined as \"export GIT_DIR=`pwd`\" in git.c,\n   which meant that the initial GIT_DIR setting was not honored.\n\n builtin-init-db.c |   63 +++++++++++++++++++++++++++++---\n git.c             |    1 +\n t/t0001-init.sh   |  105 +++++++++++++++++++++++++++++++++++++++++++++++++++++\n 3 files changed, 164 insertions(+), 5 deletions(-)\n create mode 100755 t/t0001-init.sh\n\ndiff --git a/builtin-init-db.c b/builtin-init-db.c\nindex 0d9b1e0..ec90b66 100644\n--- a/builtin-init-db.c\n+++ b/builtin-init-db.c\n@@ -267,6 +267,42 @@ static int create_default_files(const char *git_dir, const char *template_path)\n \treturn reinit;\n }\n \n+static void guess_repository_type(const char *git_dir)\n+{\n+\tchar cwd[PATH_MAX];\n+\tconst char *slash;\n+\n+\tif (0 <= is_bare_repository_cfg)\n+\t\treturn;\n+\tif (!git_dir)\n+\t\treturn;\n+\n+\t/*\n+\t * \"GIT_DIR=. git init\" is always bare.\n+\t * \"GIT_DIR=`pwd` git init\" too.\n+\t */\n+\tif (!strcmp(\".\", git_dir))\n+\t\tgoto force_bare;\n+\tif (!getcwd(cwd, sizeof(cwd)))\n+\t\tdie(\"cannot tell cwd\");\n+\tif (!strcmp(git_dir, cwd))\n+\t\tgoto force_bare;\n+\t/*\n+\t * \"GIT_DIR=something/.git is usually not.\n+\t */\n+\tslash = strrchr(git_dir, '/');\n+\tif (slash && !strcmp(slash, \"/.git\"))\n+\t\treturn;\n+\n+\t/*\n+\t * Otherwise it is often bare.  At this point\n+\t * we are just guessing.\n+\t */\n+ force_bare:\n+\tis_bare_repository_cfg = 1;\n+\treturn;\n+}\n+\n static const char init_db_usage[] =\n \"git-init [-q | --quiet] [--template=<template-directory>] [--shared]\";\n \n@@ -299,11 +335,28 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)\n \t\t\tusage(init_db_usage);\n \t}\n \n-\tgit_work_tree_cfg = xcalloc(PATH_MAX, 1);\n-\tif (!getcwd(git_work_tree_cfg, PATH_MAX))\n-\t\tdie (\"Cannot access current working directory.\");\n-\tif (access(get_git_work_tree(), X_OK))\n-\t\tdie (\"Cannot access work tree '%s'\", get_git_work_tree());\n+\t/*\n+\t * GIT_WORK_TREE makes sense only in conjunction with GIT_DIR\n+\t * without --bare.  Catch the error early.\n+\t */\n+\tgit_dir = getenv(GIT_DIR_ENVIRONMENT);\n+\tif ((!git_dir || is_bare_repository_cfg == 1)\n+\t    && getenv(GIT_WORK_TREE_ENVIRONMENT))\n+\t\tdie(\"%s (or --work-tree=<directory>) not allowed without \"\n+\t\t    \"specifying %s (or --git-dir=<directory>)\",\n+\t\t    GIT_WORK_TREE_ENVIRONMENT,\n+\t\t    GIT_DIR_ENVIRONMENT);\n+\n+\tguess_repository_type(git_dir);\n+\n+\tif (is_bare_repository_cfg <= 0) {\n+\t\tgit_work_tree_cfg = xcalloc(PATH_MAX, 1);\n+\t\tif (!getcwd(git_work_tree_cfg, PATH_MAX))\n+\t\t\tdie (\"Cannot access current working directory.\");\n+\t\tif (access(get_git_work_tree(), X_OK))\n+\t\t\tdie (\"Cannot access work tree '%s'\",\n+\t\t\t     get_git_work_tree());\n+\t}\n \n \t/*\n \t * Set up the default .git directory contents\ndiff --git a/git.c b/git.c\nindex c46691e..b6e292e 100644\n--- a/git.c\n+++ b/git.c\n@@ -93,6 +93,7 @@ static int handle_options(const char*** argv, int* argc, int* envchanged)\n \t\t\t\t*envchanged = 1;\n \t\t} else if (!strcmp(cmd, \"--bare\")) {\n \t\t\tstatic char git_dir[PATH_MAX+1];\n+\t\t\tis_bare_repository_cfg = 1;\n \t\t\tsetenv(GIT_DIR_ENVIRONMENT, getcwd(git_dir, sizeof(git_dir)), 1);\n \t\t\tif (envchanged)\n \t\t\t\t*envchanged = 1;\ndiff --git a/t/t0001-init.sh b/t/t0001-init.sh\nnew file mode 100755\nindex 0000000..333abb2\n--- /dev/null\n+++ b/t/t0001-init.sh\n@@ -0,0 +1,105 @@\n+#!/bin/sh\n+\n+test_description='git init'\n+\n+. ./test-lib.sh\n+\n+check_config () {\n+\tif test -d \"$1\" && test -f \"$1/config\" && test -d \"$1/refs\"\n+\tthen\n+\t\t: happy\n+\telse\n+\t\techo \"expected a directory $1, a file $1/config and $1/refs\"\n+\t\treturn 1\n+\tfi\n+\tbare=$(GIT_CONFIG=\"$1/config\" git config --bool core.bare)\n+\tworktree=$(GIT_CONFIG=\"$1/config\" git config core.worktree) ||\n+\tworktree=unset\n+\n+\ttest \"$bare\" = \"$2\" && test \"$worktree\" = \"$3\" || {\n+\t\techo \"expected bare=$2 worktree=$3\"\n+\t\techo \"     got bare=$bare worktree=$worktree\"\n+\t\treturn 1\n+\t}\n+}\n+\n+test_expect_success 'plain' '\n+\t(\n+\t\tunset GIT_DIR GIT_WORK_TREE &&\n+\t\tmkdir plain &&\n+\t\tcd plain &&\n+\t\tgit init\n+\t) &&\n+\tcheck_config plain/.git false unset\n+'\n+\n+test_expect_success 'plain with GIT_WORK_TREE' '\n+\tif (\n+\t\tunset GIT_DIR &&\n+\t\tmkdir plain-wt &&\n+\t\tcd plain-wt &&\n+\t\tGIT_WORK_TREE=$(pwd) git init\n+\t)\n+\tthen\n+\t\techo Should have failed -- GIT_WORK_TREE should not be used\n+\t\tfalse\n+\tfi\n+'\n+\n+test_expect_success 'plain bare' '\n+\t(\n+\t\tunset GIT_DIR GIT_WORK_TREE GIT_CONFIG &&\n+\t\tmkdir plain-bare-1 &&\n+\t\tcd plain-bare-1 &&\n+\t\tgit --bare init\n+\t) &&\n+\tcheck_config plain-bare-1 true unset\n+'\n+\n+test_expect_success 'plain bare with GIT_WORK_TREE' '\n+\tif (\n+\t\tunset GIT_DIR GIT_CONFIG &&\n+\t\tmkdir plain-bare-2 &&\n+\t\tcd plain-bare-2 &&\n+\t\tGIT_WORK_TREE=$(pwd) git --bare init\n+\t)\n+\tthen\n+\t\techo Should have failed -- GIT_WORK_TREE should not be used\n+\t\tfalse\n+\tfi\n+'\n+\n+test_expect_success 'GIT_DIR bare' '\n+\n+\t(\n+\t\tunset GIT_CONFIG &&\n+\t\tmkdir git-dir-bare.git &&\n+\t\tGIT_DIR=git-dir-bare.git git init\n+\t) &&\n+\tcheck_config git-dir-bare.git true unset\n+'\n+\n+test_expect_success 'GIT_DIR & GIT_WORK_TREE (1)' '\n+\n+\t(\n+\t\tunset GIT_CONFIG &&\n+\t\tmkdir git-dir-wt-1.git &&\n+\t\tGIT_WORK_TREE=$(pwd) GIT_DIR=git-dir-wt-1.git git init\n+\t) &&\n+\tcheck_config git-dir-wt-1.git false \"$(pwd)\"\n+'\n+\n+test_expect_success 'GIT_DIR & GIT_WORK_TREE (2)' '\n+\n+\tif (\n+\t\tunset GIT_CONFIG &&\n+\t\tmkdir git-dir-wt-2.git &&\n+\t\tGIT_WORK_TREE=$(pwd) GIT_DIR=git-dir-wt-2.git git --bare init\n+\t)\n+\tthen\n+\t\techo Should have failed -- --bare should not be used\n+\t\tfalse\n+\tfi\n+'\n+\n+test_done\n"},{"id":"51681","messageId":"Pine.LNX.4.64.0708271154020.28586@racer.site","threadId":"9534","inReplyTo":"7v7inhmmsx.fsf_-_@gitster.siamese.dyndns.org","subject":"Re: [PATCH/RFH] Fix initialization of a bare repository","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-08-27T10:54:48Z","receivedAt":"2007-08-27T10:54:48Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nhow about this on top (or squashed):\n\n-- snipsnap --\n\n builtin-init-db.c |    4 +++-\n t/t0001-init.sh   |   11 +++++++++++\n 2 files changed, 14 insertions(+), 1 deletions(-)\n\ndiff --git a/builtin-init-db.c b/builtin-init-db.c\nindex ec90b66..af15cb2 100644\n--- a/builtin-init-db.c\n+++ b/builtin-init-db.c\n@@ -288,8 +288,10 @@ static void guess_repository_type(const char *git_dir)\n \tif (!strcmp(git_dir, cwd))\n \t\tgoto force_bare;\n \t/*\n-\t * \"GIT_DIR=something/.git is usually not.\n+\t * \"GIT_DIR=.git or GIT_DIR=something/.git is usually not.\n \t */\n+\tif (!strcmp(git_dir, \".git\"))\n+\t\treturn;\n \tslash = strrchr(git_dir, '/');\n \tif (slash && !strcmp(slash, \"/.git\"))\n \t\treturn;\ndiff --git a/t/t0001-init.sh b/t/t0001-init.sh\nindex 333abb2..b14b3ec 100755\n--- a/t/t0001-init.sh\n+++ b/t/t0001-init.sh\n@@ -79,6 +79,17 @@ test_expect_success 'GIT_DIR bare' '\n \tcheck_config git-dir-bare.git true unset\n '\n \n+test_expect_success 'GIT_DIR non-bare' '\n+\n+\t(\n+\t\tunset GIT_CONFIG &&\n+\t\tmkdir non-bare &&\n+\t\tcd non-bare &&\n+\t\tGIT_DIR=.git git init\n+\t) &&\n+\tcheck_config non-bare/.git false unset\n+'\n+\n test_expect_success 'GIT_DIR & GIT_WORK_TREE (1)' '\n \n \t(\n"}]}