5

Something went really wrong here. Allow me to give the background.

Today I try to push to our company default bare msysgit windows server and get a dreaded error message duplicated everywhere in SO about pushing to non-bare. I thought the message was weird, since my server was supposed to be bare. And yesterday it was working just fine.

Then I noticed the core.bare is, somehow, set to false! This was a repo inited with --bare and it never had a ".git" folder in it. And then I go check, and there it is, a .git folder, that to me appeared out of nowhere, to my dismay! I ask the only other person who could have done something there and, surely enough, he didn't.

edit: I just noticed it only happens with master branch and the server's .git seem to have been created on october 1st, which can be right since I don't push to master that often.

The folder has 3gb and the bare folder, with all git structures beside the ghostly .git, has 6gb. While my local .git has 16 gb, so I'm not sure what's going on there... Even more, I can't check git log or git reflog. Either setting bare to true or false I get same error fatal: bad default revision 'HEAD'. And now I think it's already time to consider how to recover the repo...

But before I go through all the restoration dogma, I wonder:

  • Is there some kind of git activity log so I can see all commands issued in git, and by who?

Couldn't find anything similar, and I fear there isn't.

Community
  • 1
  • 1
cregox
  • 17,674
  • 15
  • 85
  • 116

2 Answers2

2

That is why we have installed gitolite V3 (by simply cloning its repo and installing it like in this installation script) on our central git repo server.

Gitolite will intercept any git commands, and (in addition of its primary authorization framework feature) will record said commands in ~/.gitolite/logs/gitolite-log-xxx.

Here is an extract of such logs:

2012-08-16.12:20:19     29507           system,/home/gitadmin/gitolite/bin/triggers/post-compile/update-git-configs,POST_COMPILE
2012-08-16.12:20:19     29507           system,/home/gitadmin/gitolite/bin/triggers/post-compile/update-gitweb-access-list,POST_COMPILE
2012-08-16.12:20:19     29507           system,/home/gitadmin/gitolite/bin/commands/access,%,gitweb,R,any
2012-08-16.12:20:19     29507           system,/home/gitadmin/gitolite/bin/commands/git-config,-r,%,gitweb\.
2012-08-16.12:20:19     29507           system,/home/gitadmin/gitolite/bin/triggers/post-compile/update-git-daemon-access-list,POST_COMPILE
2012-08-16.12:20:20     29507           system,/home/gitadmin/gitolite/bin/commands/access,%,daemon,R,any
2012-08-16.12:20:20     29507   END
2012-08-20.07:39:12     17683   ssh     ARGV=gitoliteadm        SOC=git-upload-pack 'gitolite-admin'    FROM=127.0.0.1
2012-08-20.07:39:12     17683           access(gitolite-admin, gitoliteadm, R, 'any'),-> refs/.*
2012-08-20.07:39:12     17683           trigger,Writable,access_1,ACCESS_1,gitolite-admin,gitoliteadm,R,any,refs/.*
2012-08-20.07:39:12     17683   pre_git gitolite-admin  gitoliteadm     R       any     -> refs/.*
2012-08-20.07:39:12     17683           system,git,shell,-c,git-upload-pack '/home/gitadmin/repositories/gitolite-admin.git'
2012-08-20.07:39:12     17683   END
2012-08-16.12:20:19     29507           system,/home/gitadmin/gitolite/bin/triggers/post-compile/update-git-configs,POST_COMPILE
2012-08-16.12:20:19     29507           system,/home/gitadmin/gitolite/bin/triggers/post-compile/update-gitweb-access-list,POST_COMPILE
2012-08-16.12:20:19     29507           system,/home/gitadmin/gitolite/bin/commands/access,%,gitweb,R,any
2012-08-16.12:20:19     29507           system,/home/gitadmin/gitolite/bin/commands/git-config,-r,%,gitweb\.
2012-08-16.12:20:19     29507           system,/home/gitadmin/gitolite/bin/triggers/post-compile/update-git-daemon-access-list,POST_COMPILE
2012-08-16.12:20:20     29507           system,/home/gitadmin/gitolite/bin/commands/access,%,daemon,R,any
2012-08-16.12:20:20     29507   END
2012-08-20.07:39:12     17683   ssh     ARGV=gitoliteadm        SOC=git-upload-pack 'gitolite-admin'    FROM=127.0.0.1
2012-08-20.07:39:12     17683           access(gitolite-admin, gitoliteadm, R, 'any'),-> refs/.*
2012-08-20.07:39:12     17683           trigger,Writable,access_1,ACCESS_1,gitolite-admin,gitoliteadm,R,any,refs/.*
2012-08-20.07:39:12     17683   pre_git gitolite-admin  gitoliteadm     R       any     -> refs/.*
2012-08-20.07:39:12     17683           system,git,shell,-c,git-upload-pack '/home/gitadmin/repositories/gitolite-admin.git'
2012-08-20.07:39:12     17683   END
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • hmm... I did forget to mention it's a windows server. maybe with this I can convince people here to try getting at least VM ubuntu... :P – cregox Oct 11 '12 at 12:18
  • 1
    @Cawas but you can install a Gitolite on windows: http://therightstuff.de/CommentView,guid,b969ea4d-8d2c-42af-9806-de3631f4df68.aspx That being said, yes, a git server On Unix makes more sense. – VonC Oct 11 '12 at 12:24
  • I still got 2 open sub questions there @VonC... Maybe you can help! Would you know what could have caused the server to become non-bare like that and why I can't see the reflog on any of my bare repos? – cregox Oct 11 '12 at 12:30
  • @Cawas I am not sure what has cause a bare repo into a non-bare one, unless a `.git` has been copied in your bare repo. And in that case, a `git reflog` might be confused, looking for the `.git/logs` in the wrong place. So, no definitive answer here. – VonC Oct 11 '12 at 12:51
  • `git reflog` won't work in any repo. it just brings no message, nothing. and the `.git` didn't appear in any other repo - so that doesn't seem to be related. I never tried `git reflog` directly on the bare repo before, so maybe there's even some issue related to *msysgit* for all I know. But your hypothesis about it getting confuse seem to hold true for `git log`, which began to work after removing the `.git` and never seem to have got any issues on any other repo. – cregox Oct 11 '12 at 13:43
  • 1
    @Cawas interesting, but knowing where the git reflog look for its logs (see comments of http://stackoverflow.com/a/6142054/6309), is it possible said logs are empty on all repo, which would explain the empty result? – VonC Oct 11 '12 at 14:29
  • Well, yeah, they're all empty indeed. And I didn't know bare repos don't enable reflogs by default! Sounds good enough. Thanks again!! :D – cregox Oct 11 '12 at 14:40
1

you can use reflog to see how the references were moving, that registers activity sometimes not visible from usual git log (like fast-forward merges) but i don't think it should matter in your case.

I believe you have structure like that (it is by the way recommended to put .git extension to bare repo name, so it is easy to distinguish): ../core.bare.git/ containing branches, config, HEAD, hooks, info, objects, etc ../core.bare.git/.git containing its own set of branches, config etc I think you repo on the server is totally fine, you just have to remove the .git folder from it and double check that the config file is still saying it is a bare repo.

Eugene Sajine
  • 8,104
  • 3
  • 23
  • 28
  • Good idea on the standards, but no big deal there. Ok, after removing the `.git` I can now see `git log` and the push works! Even the `reflog` doesn't bring any errors anymore... But it doesn't bring anything at all! Such a weird behavior. And, while I'm assuming you say *there's no such "activity log"*, there remains one implicit question: What could have caused all this mess? How a bare repo suddenly became non-bare?! – cregox Oct 11 '12 at 10:43
  • I can only assume that somebody issued git init in wrong folder - that's how you got it. – Eugene Sajine Oct 11 '12 at 16:39
  • 1
    it works as it should - i just tested it: mkdir test; cd test; touch file1; touch file2; git init otherwise it would be very weird limitation. – Eugene Sajine Oct 11 '12 at 18:11
  • I should have tested it myself before my bold assertion there... I did a different and slightly more robust test and, indeed, it works. And, indeed, it would turn a bare repo into non-bare, oddly enough. So, although very unlikely, this might have happened. That's where I wished I had that `gitolite` installed. – cregox Oct 15 '12 at 12:46