git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Confusing error message due to Git trusting is_bare_repository()
@ 2011-03-25 10:56 Ævar Arnfjörð Bjarmason
  2011-03-25 17:57 ` Junio C Hamano
  2011-03-25 18:25 ` Jeff King
  0 siblings, 2 replies; 3+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2011-03-25 10:56 UTC (permalink / raw)
  To: Git Mailing List

I had a co-worker git this well-known error message:

    error: refusing to update checked out branch: refs/heads/master
    error: By default, updating the current branch in a non-bare repository
    error: is denied, because it will make the index and work tree inconsistent
    error: with what you pushed, and will require 'git reset --hard' to match
    error: the work tree to HEAD.

It *was* a bare repo, but the config file had bare=false because
someone had simply copied a .git tree from a non-bare repo to make it.

The issue is that we just use this:

    int is_bare_repository(void)
    {
        /* if core.bare is not 'false', let's see if there is a work tree */
        return is_bare_repository_cfg && !get_git_work_tree();
    }

For the purposes of the error message it would be helpful if we also
detected whether something didn't have a working tree, but was set to
bare=false, and tell the user to updatet he bare=false to bare=true
for his almost-bare repository.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Confusing error message due to Git trusting is_bare_repository()
  2011-03-25 10:56 Confusing error message due to Git trusting is_bare_repository() Ævar Arnfjörð Bjarmason
@ 2011-03-25 17:57 ` Junio C Hamano
  2011-03-25 18:25 ` Jeff King
  1 sibling, 0 replies; 3+ messages in thread
From: Junio C Hamano @ 2011-03-25 17:57 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason; +Cc: Git Mailing List

Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:

> I had a co-worker git this well-known error message:
>
>     error: refusing to update checked out branch: refs/heads/master
>     error: By default, updating the current branch in a non-bare repository
>     error: is denied, because it will make the index and work tree inconsistent
>     error: with what you pushed, and will require 'git reset --hard' to match
>     error: the work tree to HEAD.
>
> It *was* a bare repo, but the config file had bare=false because
> someone had simply copied a .git tree from a non-bare repo to make it.
>
> The issue is that we just use this:
>
>     int is_bare_repository(void)
>     {
>         /* if core.bare is not 'false', let's see if there is a work tree */
>         return is_bare_repository_cfg && !get_git_work_tree();
>     }
>
> For the purposes of the error message it would be helpful if we also
> detected whether something didn't have a working tree, but was set to
> bare=false, and tell the user to updatet he bare=false to bare=true
> for his almost-bare repository.

The only reason we have it as a config variable is because there isn't a
way to make that determination.

How would you propose to detect that?

As a trivial and obvious example, is the result "git clone -n" a bare
repository?

Note that it is a perfectly valid workflow to:

	$ git clone -n github.com:gitster/git.git temp
        $ cd temp ;# no checkout, but is .git/ in it a bare repository?
        $ git read-tree origin/master ;# now with the index, but no checkout
        $ git merge origin/jc/diff-dotdot
	$ git show -m --first-parent

to make a merge with minimum number of paths checked out in a temporary
repository that should still be considered non-bare.

Of course, you cannot base the determination on "do we see $GIT_DIR/index
file there?"  Most likely people who renamed foo/.git to foo.git and then
removed foo directory didn't bother to remove foo.git/index.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Confusing error message due to Git trusting is_bare_repository()
  2011-03-25 10:56 Confusing error message due to Git trusting is_bare_repository() Ævar Arnfjörð Bjarmason
  2011-03-25 17:57 ` Junio C Hamano
@ 2011-03-25 18:25 ` Jeff King
  1 sibling, 0 replies; 3+ messages in thread
From: Jeff King @ 2011-03-25 18:25 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason; +Cc: Git Mailing List

On Fri, Mar 25, 2011 at 11:56:20AM +0100, Ævar Arnfjörð Bjarmason wrote:

> I had a co-worker git this well-known error message:
> 
>     error: refusing to update checked out branch: refs/heads/master
>     error: By default, updating the current branch in a non-bare repository
>     error: is denied, because it will make the index and work tree inconsistent
>     error: with what you pushed, and will require 'git reset --hard' to match
>     error: the work tree to HEAD.
> 
> It *was* a bare repo, but the config file had bare=false because
> someone had simply copied a .git tree from a non-bare repo to make it.

That seems like the problem there. I'm not blaming the user; what they
expected to happen is reasonable, and even used to work. But I wonder if
better education is possible.

> The issue is that we just use this:
> 
>     int is_bare_repository(void)
>     {
>         /* if core.bare is not 'false', let's see if there is a work tree */
>         return is_bare_repository_cfg && !get_git_work_tree();
>     }

> For the purposes of the error message it would be helpful if we also
> detected whether something didn't have a working tree, but was set to
> bare=false, and tell the user to updatet he bare=false to bare=true
> for his almost-bare repository.

How do we know whether or not it has a working tree? Can't I do
something like:

  cd /var/working-trees/foo
  git init
  mv .git /var/repositories/foo.git
  export GIT_DIR=/var/repositories/foo.git
  echo content >file && git add file && git commit -m foo

I thought the reason that core.bare was introduced was to handle weird
cases like this.

-Peff

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-03-25 18:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-25 10:56 Confusing error message due to Git trusting is_bare_repository() Ævar Arnfjörð Bjarmason
2011-03-25 17:57 ` Junio C Hamano
2011-03-25 18:25 ` Jeff King

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).