{"thread":{"id":"9605","subject":"[PATCH] Fix new-workdir (again) to work on bare repositories","startedAt":"2007-08-22T01:50:12Z","lastAt":"2007-08-22T05:33:49Z","messageCount":6,"participants":["Shawn O. Pearce","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"51214","messageId":"20070822015012.GA11085@spearce.org","threadId":"9605","inReplyTo":null,"subject":"[PATCH] Fix new-workdir (again) to work on bare repositories","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2007-08-22T01:50:12Z","receivedAt":"2007-08-22T01:50:12Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"My day-job workflow involves using multiple workdirs attached to a\nbunch of bare repositories.  Such repositories are stored inside of\na directory called \"foo.git\", which means `git rev-parse --git-dir`\nwill return \".\" and not \".git\".  Under such conditions new-workdir\nwas getting confused about where the Git repository it was supplied\nis actually located.\n\nIf we get \".\" for the result of --git-dir query it means we should\nuse the user supplied path as-is, and not attempt to perform any\nmagic on it, as the path is directly to the repository.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n contrib/workdir/git-new-workdir |   10 +++++++---\n 1 files changed, 7 insertions(+), 3 deletions(-)\n\ndiff --git a/contrib/workdir/git-new-workdir b/contrib/workdir/git-new-workdir\nindex 3ff6bd1..119cff9 100755\n--- a/contrib/workdir/git-new-workdir\n+++ b/contrib/workdir/git-new-workdir\n@@ -24,10 +24,14 @@ git_dir=$(cd \"$orig_git\" 2>/dev/null &&\n   git rev-parse --git-dir 2>/dev/null) ||\n   die \"\\\"$orig_git\\\" is not a git repository!\"\n \n-if test \"$git_dir\" = \".git\"\n-then\n+case \"$git_dir\" in\n+.git)\n \tgit_dir=\"$orig_git/.git\"\n-fi\n+\t;;\n+.)\n+\tgit_dir=$orig_git\n+\t;;\n+esac\n \n # don't link to a workdir\n if test -L \"$git_dir/config\"\n-- \n1.5.3.rc6\n"},{"id":"51215","messageId":"7v1wdwntc6.fsf@gitster.siamese.dyndns.org","threadId":"9605","inReplyTo":"20070822015012.GA11085@spearce.org","subject":"Re: [PATCH] Fix new-workdir (again) to work on bare repositories","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-08-22T03:25:45Z","receivedAt":"2007-08-22T03:25:45Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Shawn O. Pearce\" <spearce@spearce.org> writes:\n\n> My day-job workflow involves using multiple workdirs attached to a\n> bunch of bare repositories.\n\nAre you sure the patch would help?\n\nFor one thing, I do not think we supported such a layout,\nofficially or unofficially --- the thing is in contrib so it\ncould not be official, but that is besides the point ;-).  Older\ngit might have worked by accident, though.\n\nYou may have made the part to create the new directory and make\nbunch of symbolic links to work with your patch, but as far as I\nknow, new-workdir is designed to share the .git/config file with\nthe borrowed repository, which means the configuration would say\n\"core.bare = yes\" for a bare repository.  So I suspect that the\ninitial checkout after creating the new directory and populating\nits .git would barf, although I haven't tested it.\n"},{"id":"51216","messageId":"20070822033625.GN27913@spearce.org","threadId":"9605","inReplyTo":"7v1wdwntc6.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH] Fix new-workdir (again) to work on bare repositories","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2007-08-22T03:36:26Z","receivedAt":"2007-08-22T03:36:26Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Junio C Hamano <gitster@pobox.com> wrote:\n> \"Shawn O. Pearce\" <spearce@spearce.org> writes:\n> > My day-job workflow involves using multiple workdirs attached to a\n> > bunch of bare repositories.\n> \n> Are you sure the patch would help?\n\nYes.  I tested it in this use case.  It works with the patch, it\nfails rather nicely without.  Fun errors about not being able to\ncp HEAD from a directory that shouldn't have a HEAD...\n\n> For one thing, I do not think we supported such a layout,\n> officially or unofficially --- the thing is in contrib so it\n> could not be official, but that is besides the point ;-).  Older\n> git might have worked by accident, though.\n\nTrue, but it works, and uh, we have this new fangled --work-tree\nthing to go along with --git-dir, so why can't I symlink my entire\n.git content over to somewhere else and pretend like the mess that\nis --work-tree doesn't exist?\n \n> You may have made the part to create the new directory and make\n> bunch of symbolic links to work with your patch, but as far as I\n> know, new-workdir is designed to share the .git/config file with\n> the borrowed repository, which means the configuration would say\n> \"core.bare = yes\" for a bare repository.  So I suspect that the\n> initial checkout after creating the new directory and populating\n> its .git would barf, although I haven't tested it.\n\nIndeed.  I have a driver script that sets up my bare repos, it\nremoves core.bare from their configs.  So if you go into the bare\nrepo our auto-sensing bare thing gets activated and says \"Hmm, it\nends in .git but isn't exactly .git so its bare!\" (correct answer).\nIf you cd into a workdir created by git-new-workdir the auto-sensing\nbare thing gets activated and says \"Hmm, it is exactly .git so its\nnot-bare!\" (correct answer).\n\nSo removing that core.bare thing makes the magic work.  But if you\nleave core.bare in foo.git/config, yes, a workdir created from it\nis mighty confused.\n\n-- \nShawn.\n"},{"id":"51217","messageId":"7vtzqsme6x.fsf@gitster.siamese.dyndns.org","threadId":"9605","inReplyTo":"7v1wdwntc6.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH] Fix new-workdir (again) to work on bare repositories","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-08-22T03:38:14Z","receivedAt":"2007-08-22T03:38:14Z","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> \"Shawn O. Pearce\" <spearce@spearce.org> writes:\n>\n>> My day-job workflow involves using multiple workdirs attached to a\n>> bunch of bare repositories.\n>\n> Are you sure the patch would help?\n>\n> For one thing, I do not think we supported such a layout,\n> officially or unofficially --- the thing is in contrib so it\n> could not be official, but that is besides the point ;-).  Older\n> git might have worked by accident, though.\n>\n> You may have made the part to create the new directory and make\n> bunch of symbolic links to work with your patch, but as far as I\n> know, new-workdir is designed to share the .git/config file with\n> the borrowed repository, which means the configuration would say\n> \"core.bare = yes\" for a bare repository.  So I suspect that the\n> initial checkout after creating the new directory and populating\n> its .git would barf, although I haven't tested it.\n\nHaving said that, I am not saying that we should forbid such a\nlayout that uses a work tree or more attached to a bare\nrepository.  We need to figure out what the best practice should\nbe.\n\n * Maybe using such a layout needs GIT_WORK_TREE environment to\n   be set?\n\n * Maybe using such a layout needs \"core.bare = false\" even\n   though the true repository is a bare repository?  This has an\n   obvious drawback that git-fetch cannot update the branch\n   pointed by HEAD even though it is a bare repository.\n\n * Maybe ignore \"core.bare = true\" if $GIT_DIR ends with\n   \"/.git\"?  I do not like relying on names too much, though.\n\n * Maybe ignore \"core.bare = true\" if $GIT_DIR/index exists?\n   This is almost right, except that there is a chicken and egg\n   problem -- the index does not exist until the initial\n   checkout, and checkout wants to make sure you are not in a\n   bare repository.\n"},{"id":"51220","messageId":"7v3ayckx1m.fsf@gitster.siamese.dyndns.org","threadId":"9605","inReplyTo":"20070822033625.GN27913@spearce.org","subject":"Re: [PATCH] Fix new-workdir (again) to work on bare repositories","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-08-22T04:33:57Z","receivedAt":"2007-08-22T04:33:57Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Shawn O. Pearce\" <spearce@spearce.org> writes:\n\n>> You may have made the part to create the new directory and make\n>> bunch of symbolic links to work with your patch, but as far as I\n>> know, new-workdir is designed to share the .git/config file with\n>> the borrowed repository, which means the configuration would say\n>> \"core.bare = yes\" for a bare repository.  So I suspect that the\n>> initial checkout after creating the new directory and populating\n>> its .git would barf, although I haven't tested it.\n>\n> Indeed.  I have a driver script that sets up my bare repos, it\n> removes core.bare from their configs.  So if you go into the bare\n> repo our auto-sensing bare thing gets activated and says \"Hmm, it\n> ends in .git but isn't exactly .git so its bare!\" (correct answer).\n> If you cd into a workdir created by git-new-workdir the auto-sensing\n> bare thing gets activated and says \"Hmm, it is exactly .git so its\n> not-bare!\" (correct answer).\n>\n> So removing that core.bare thing makes the magic work.\n\nOk, that is better than the response I sent (our messages\ncrossed).  In that case, perhaps you would want a warning or a\nsuggestion at the end of new-workdir script, probably before\ncheckout, to teach the user about that magic?\n"},{"id":"51224","messageId":"20070822053349.GO27913@spearce.org","threadId":"9605","inReplyTo":"7v3ayckx1m.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH] Fix new-workdir (again) to work on bare repositories","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2007-08-22T05:33:49Z","receivedAt":"2007-08-22T05:33:49Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Junio C Hamano <gitster@pobox.com> wrote:\n> \"Shawn O. Pearce\" <spearce@spearce.org> writes:\n> > So removing that core.bare thing makes the magic work.\n> \n> Ok, that is better than the response I sent (our messages\n> crossed).  In that case, perhaps you would want a warning or a\n> suggestion at the end of new-workdir script, probably before\n> checkout, to teach the user about that magic?\n\n-->8--\nSuggest unsetting core.bare when using new-workdir on a bare repository\n\nIf core.bare is set to true in the config file of a repository that\nthe user is trying to create a working directory from we should\nabort and suggest to the user that they remove the option first.\n\nIf we leave the core.bare=true setting in the config file then\nworking tree operations will get confused when they attempt to\nexecute in the new workdir, as it shares its config file with the\nbare repository.  The working tree operations will assume that the\nworkdir is bare and abort, which is not what the user wants.\n\nIf we changed core.bare to be false then working tree operations\nwill function in the workdir but other operations may fail in the\nbare repository, as it claims to not be bare.\n\nIf we remove core.bare from the config then Git can fallback on\nthe legacy guessing behavior.  This allows operations in the bare\nrepository to work as though it were bare, while operations in the\nworkdirs to act as though they are not bare.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n contrib/workdir/git-new-workdir |    8 ++++++++\n 1 files changed, 8 insertions(+), 0 deletions(-)\n\ndiff --git a/contrib/workdir/git-new-workdir b/contrib/workdir/git-new-workdir\nindex 119cff9..c6e154a 100755\n--- a/contrib/workdir/git-new-workdir\n+++ b/contrib/workdir/git-new-workdir\n@@ -33,6 +33,14 @@ case \"$git_dir\" in\n \t;;\n esac\n \n+# don't link to a configured bare repository\n+isbare=$(git --git-dir=\"$git_dir\" config --bool --get core.bare)\n+if test ztrue = z$isbare\n+then\n+\tdie \"\\\"$git_dir\\\" has core.bare set to true,\" \\\n+\t\t\" remove from \\\"$git_dir/config\\\" to use $0\"\n+fi\n+\n # don't link to a workdir\n if test -L \"$git_dir/config\"\n then\n-- \n1.5.3.rc6\n\n\n-- \nShawn.\n"}]}