{"thread":{"id":"26860","subject":"Confusing error message due to Git trusting is_bare_repository()","startedAt":"2011-03-25T10:56:20Z","lastAt":"2011-03-25T18:25:36Z","messageCount":3,"participants":["Ævar Arnfjörð Bjarmason","Junio C Hamano","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"164291","messageId":"AANLkTi=9CpMU9aZs2zuvRyv3rpECkRAvYA0Srnc61whg@mail.gmail.com","threadId":"26860","inReplyTo":null,"subject":"Confusing error message due to Git trusting is_bare_repository()","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2011-03-25T10:56:20Z","receivedAt":"2011-03-25T10:56:20Z","isPatch":false,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"I had a co-worker git this well-known error message:\n\n    error: refusing to update checked out branch: refs/heads/master\n    error: By default, updating the current branch in a non-bare repository\n    error: is denied, because it will make the index and work tree inconsistent\n    error: with what you pushed, and will require 'git reset --hard' to match\n    error: the work tree to HEAD.\n\nIt *was* a bare repo, but the config file had bare=false because\nsomeone had simply copied a .git tree from a non-bare repo to make it.\n\nThe issue is that we just use this:\n\n    int is_bare_repository(void)\n    {\n        /* if core.bare is not 'false', let's see if there is a work tree */\n        return is_bare_repository_cfg && !get_git_work_tree();\n    }\n\nFor the purposes of the error message it would be helpful if we also\ndetected whether something didn't have a working tree, but was set to\nbare=false, and tell the user to updatet he bare=false to bare=true\nfor his almost-bare repository.\n"},{"id":"164314","messageId":"7vwrjn5bhd.fsf@alter.siamese.dyndns.org","threadId":"26860","inReplyTo":"AANLkTi=9CpMU9aZs2zuvRyv3rpECkRAvYA0Srnc61whg@mail.gmail.com","subject":"Re: Confusing error message due to Git trusting is_bare_repository()","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-03-25T17:57:50Z","receivedAt":"2011-03-25T17:57:50Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:\n\n> I had a co-worker git this well-known error message:\n>\n>     error: refusing to update checked out branch: refs/heads/master\n>     error: By default, updating the current branch in a non-bare repository\n>     error: is denied, because it will make the index and work tree inconsistent\n>     error: with what you pushed, and will require 'git reset --hard' to match\n>     error: the work tree to HEAD.\n>\n> It *was* a bare repo, but the config file had bare=false because\n> someone had simply copied a .git tree from a non-bare repo to make it.\n>\n> The issue is that we just use this:\n>\n>     int is_bare_repository(void)\n>     {\n>         /* if core.bare is not 'false', let's see if there is a work tree */\n>         return is_bare_repository_cfg && !get_git_work_tree();\n>     }\n>\n> For the purposes of the error message it would be helpful if we also\n> detected whether something didn't have a working tree, but was set to\n> bare=false, and tell the user to updatet he bare=false to bare=true\n> for his almost-bare repository.\n\nThe only reason we have it as a config variable is because there isn't a\nway to make that determination.\n\nHow would you propose to detect that?\n\nAs a trivial and obvious example, is the result \"git clone -n\" a bare\nrepository?\n\nNote that it is a perfectly valid workflow to:\n\n\t$ git clone -n github.com:gitster/git.git temp\n        $ cd temp ;# no checkout, but is .git/ in it a bare repository?\n        $ git read-tree origin/master ;# now with the index, but no checkout\n        $ git merge origin/jc/diff-dotdot\n\t$ git show -m --first-parent\n\nto make a merge with minimum number of paths checked out in a temporary\nrepository that should still be considered non-bare.\n\nOf course, you cannot base the determination on \"do we see $GIT_DIR/index\nfile there?\"  Most likely people who renamed foo/.git to foo.git and then\nremoved foo directory didn't bother to remove foo.git/index.\n"},{"id":"164322","messageId":"20110325182536.GC25851@sigill.intra.peff.net","threadId":"26860","inReplyTo":"AANLkTi=9CpMU9aZs2zuvRyv3rpECkRAvYA0Srnc61whg@mail.gmail.com","subject":"Re: Confusing error message due to Git trusting is_bare_repository()","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2011-03-25T18:25:36Z","receivedAt":"2011-03-25T18:25:36Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Mar 25, 2011 at 11:56:20AM +0100, Ævar Arnfjörð Bjarmason wrote:\n\n> I had a co-worker git this well-known error message:\n> \n>     error: refusing to update checked out branch: refs/heads/master\n>     error: By default, updating the current branch in a non-bare repository\n>     error: is denied, because it will make the index and work tree inconsistent\n>     error: with what you pushed, and will require 'git reset --hard' to match\n>     error: the work tree to HEAD.\n> \n> It *was* a bare repo, but the config file had bare=false because\n> someone had simply copied a .git tree from a non-bare repo to make it.\n\nThat seems like the problem there. I'm not blaming the user; what they\nexpected to happen is reasonable, and even used to work. But I wonder if\nbetter education is possible.\n\n> The issue is that we just use this:\n> \n>     int is_bare_repository(void)\n>     {\n>         /* if core.bare is not 'false', let's see if there is a work tree */\n>         return is_bare_repository_cfg && !get_git_work_tree();\n>     }\n\n> For the purposes of the error message it would be helpful if we also\n> detected whether something didn't have a working tree, but was set to\n> bare=false, and tell the user to updatet he bare=false to bare=true\n> for his almost-bare repository.\n\nHow do we know whether or not it has a working tree? Can't I do\nsomething like:\n\n  cd /var/working-trees/foo\n  git init\n  mv .git /var/repositories/foo.git\n  export GIT_DIR=/var/repositories/foo.git\n  echo content >file && git add file && git commit -m foo\n\nI thought the reason that core.bare was introduced was to handle weird\ncases like this.\n\n-Peff\n"}]}