# Error "fatal: not a git repository" after auto packing

4 messages from 2014-08-11 to 2014-08-12. Participants: Luke Campagnola, Duy Nguyen, Dennis Kaarsemaker.
Thread: https://gitlist.dev/t/37332

## Luke Campagnola, 2014-08-11 22:56

Subject: Error "fatal: not a git repository" after auto packing
Message-ID: <CACZXET_qPzBtqJLXBbou+iZ_Muj=VqCBe5qMADN72VScsuHRVQ@mail.gmail.com>
URL: https://gitlist.dev/e/CACZXET_qPzBtqJLXBbou%2BiZ_Muj%3DVqCBe5qMADN72VScsuHRVQ%40mail.gmail.com

```
Greetings,

I have been working happily with git for a couple of years, and ran
into a mysterious issue today: after running a git-pull during which I
saw the message "Auto packing the repository for optimum performance".
I now receive the error "Fatal: not a git repository" when running any
git commands, and a little investigation revealed that my .git/refs
directory has gone missing, presumably because the refs were all
combined into .git/packed-refs. To restore access to the repository,
all I needed was to `mkdir .git/refs`. Is this a known bug? It seems
like either git should tolerate the absence of a .git/refs directory,
or the auto packer should not remove it.

I am using git 1.9.1 on kubuntu 14.04. The surrounding console output follows:

raven:/home/luke/vispy (transform-cache)$ git commit -a
[transform-cache 15a0fe3] Optimizations for grid_large
 6 files changed, 91 insertions(+), 52 deletions(-)

raven:/home/luke/vispy (transform-cache)$ git push lcampagn transform-cache
Counting objects: 114, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (31/31), done.
Writing objects: 100% (31/31), 4.00 KiB | 0 bytes/s, done.
Total 31 (delta 25), reused 0 (delta 0)
To git@github.com:lcampagn/vispy.git
   24b37a6..15a0fe3  transform-cache -> transform-cache

raven:/home/luke/vispy (transform-cache)$ git fetch vispy
remote: Counting objects: 78, done.
remote: Compressing objects: 100% (78/78), done.
remote: Total 78 (delta 34), reused 0 (delta 0)
Unpacking objects: 100% (78/78), done.
From https://github.com/vispy/vispy
   ec740af..fd8aa37  master     -> vispy/master
Auto packing the repository for optimum performance. You may also
run "git gc" manually. See "git help gc" for more information.
Counting objects: 5349, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (5315/5315), done.
Writing objects: 100% (5349/5349), done.
Total 5349 (delta 3977), reused 0 (delta 0)
Removing duplicate objects: 100% (256/256), done.

raven:/home/luke/vispy (transform-cache)$ git checkout master
Switched to branch 'master'
Deleted 103 .pyc files
Deleted 11 empty directories

raven:/home/luke/vispy$ git pull vispy master
fatal: Not a git repository (or any of the parent directories): .git

raven:/home/luke/vispy$ git status
fatal: Not a git repository (or any of the parent directories): .git

raven:/home/luke/vispy$ ls -al .git
total 288
drwxr-xr-x   6 luke luke   4096 Aug 11 17:09 .
drwxr-xr-x   9 luke luke   4096 Aug 11 09:25 ..
-rw-r--r--   1 luke luke    601 Aug 11 12:22 COMMIT_EDITMSG
-rw-rw-r--   1 luke luke   1088 Aug 11 09:21 config
-rw-r--r--   1 luke luke     73 Mar  2 08:41 description
-rw-r--r--   1 luke luke    323 Aug 11 16:56 FETCH_HEAD
-rw-r--r--   1 luke luke    337 Mar  3 10:18 GIT_COLA_MSG
-rw-r--r--   1 luke luke 193478 Aug 11 11:14 gitk.cache
-rw-rw-r--   1 luke luke     23 Aug 11 17:09 HEAD
drwxr-xr-x   2 luke luke   4096 Mar  8 07:30 hooks
-rw-rw-r--   1 luke luke  31104 Aug 11 17:09 index
drwxr-xr-x   2 luke luke   4096 Aug 11 16:57 info
drwxr-xr-x   3 luke luke   4096 Aug 11 16:56 logs
drwxr-xr-x 105 luke luke   4096 Aug 11 16:57 objects
-rw-rw-r--   1 luke luke     41 Aug 11 09:25 ORIG_HEAD
-rw-rw-r--   1 luke luke   8210 Aug 11 16:56 packed-refs

```

## Duy Nguyen, 2014-08-12 15:41

Subject: Re: Error "fatal: not a git repository" after auto packing
Message-ID: <CACsJy8A576_OxXNKpsar5DiJ3Z=YsG4DURxL_JceknhRxBjB+g@mail.gmail.com>
URL: https://gitlist.dev/e/CACsJy8A576_OxXNKpsar5DiJ3Z%3DYsG4DURxL_JceknhRxBjB%2Bg%40mail.gmail.com
In-Reply-To: <CACZXET_qPzBtqJLXBbou+iZ_Muj=VqCBe5qMADN72VScsuHRVQ@mail.gmail.com>

```
On Tue, Aug 12, 2014 at 5:56 AM, Luke Campagnola
<luke.campagnola@gmail.com> wrote:
> Greetings,
>
> I have been working happily with git for a couple of years, and ran
> into a mysterious issue today: after running a git-pull during which I
> saw the message "Auto packing the repository for optimum performance".
> I now receive the error "Fatal: not a git repository" when running any
> git commands, and a little investigation revealed that my .git/refs
> directory has gone missing, presumably because the refs were all
> combined into .git/packed-refs. To restore access to the repository,
> all I needed was to `mkdir .git/refs`. Is this a known bug?

Not to me.

> It seems
> like either git should tolerate the absence of a .git/refs directory,
> or the auto packer should not remove it.

I tried to clone from vispy.git, running 'git gc' manually and
'pack-refs' (which should be in charge of removing empty dirs with
v1.9.1. Things worked fine. Looked at
refs.c:try_remove_empty_parents() as well. Still could not find any
bug there.. So no good news. I don't suppose that if you run "git gc"
again, it would remove $GIT_DIR/refs one more time?
-- 
Duy

```

## Dennis Kaarsemaker, 2014-08-12 16:11

Subject: Re: Error "fatal: not a git repository" after auto packing
Message-ID: <1407859882.17965.1.camel@spirit>
URL: https://gitlist.dev/e/1407859882.17965.1.camel%40spirit
In-Reply-To: <CACZXET_qPzBtqJLXBbou+iZ_Muj=VqCBe5qMADN72VScsuHRVQ@mail.gmail.com>

```
On ma, 2014-08-11 at 18:56 -0400, Luke Campagnola wrote:
> 
> raven:/home/luke/vispy (transform-cache)$ git checkout master
> Switched to branch 'master'
> Deleted 103 .pyc files
> Deleted 11 empty directories

This looks like you have a local post-checkout hook that deletes empty
directories. Fix that hook to not do anything in .git and it should be
fine.
-- 
Dennis Kaarsemaker
www.kaarsemaker.net

```

## Luke Campagnola, 2014-08-12 16:16

Subject: Re: Error "fatal: not a git repository" after auto packing
Message-ID: <CACZXET-O0SZnJp_LWg_v8ZFfkUXbYtS-j96UYmMkDtbv+NZM5w@mail.gmail.com>
URL: https://gitlist.dev/e/CACZXET-O0SZnJp_LWg_v8ZFfkUXbYtS-j96UYmMkDtbv%2BNZM5w%40mail.gmail.com
In-Reply-To: <1407859882.17965.1.camel@spirit>

```
On Tue, Aug 12, 2014 at 12:11 PM, Dennis Kaarsemaker
<dennis@kaarsemaker.net> wrote:
> On ma, 2014-08-11 at 18:56 -0400, Luke Campagnola wrote:
>>
>> raven:/home/luke/vispy (transform-cache)$ git checkout master
>> Switched to branch 'master'
>> Deleted 103 .pyc files
>> Deleted 11 empty directories
>
> This looks like you have a local post-checkout hook that deletes empty
> directories. Fix that hook to not do anything in .git and it should be
> fine.

Of course you are correct. Sorry for the noise.

```
