views:

79

answers:

2

We'd like to use git to maintain system configurations. Because sometimes configuration data exists outside of /etc, we've started doing something like this on our systems:

  # cd /
  # git init
  # git add etc
  # git add some/other/path
  # git commit -m 'initial import'

And so forth. This works, up to a point. As long as your cwd == '/', git behaves normally. However, if you try, for example, to run git from inside a subdirectory:

cd /etc
git status

You get garbage. In our case, thousands of lines of "deleted:" listings for files that clearly still exist. This behavior appears to be exclusive to running git in /; doing the same thing anywhere else works just fine.

I can "fix" the behavior like this:

GIT_WORK_TREE=/ git status

And hey, everything works the way Linus intended...but this is a pain. I don't want to set it in the environment unilaterally (because this would conflict with the use of git in other repositories), and I'd like to avoid a wrapper script. Do I have any other options?

+4  A: 

This is a complete guess that you could use to investigate further, but I suspect that git's "find the .git directory" behavior is interacting with the fact that / is its own parent directory. Maybe the "stop at the root" logic has a fencepost-type error.

hobbs
Ah, git. Always a new surprise somewhere. I like your guess though. +1
Norman Ramsey
This was also my guess (and why I suspect that setting GIT_WORK_TREE would fix it). I'm just wondering if there's a more graceful way of working around the behavior...a git config option? I see that there's a newer version of git out (we're running 1.63); perhaps I should see if that sill behaves the same way.
larsks
@NR: Hi there! I like git better than the alternatives. I think that they *all* have surprises (like Subversion's "Surprise! You can't actually use svndump/svnload if you've moved things around!").
larsks
@larsks: sounds worthy of having a bug filed to me :)
hobbs
Alas, upgrading to the current release of git does not resolve this problem.
larsks
+2  A: 

Setting the core.worktree option on the repository takes care of this nicely:

git config core.worktree /

This works much better than setting GIT_WORK_TREE in the environment. Yay!

larsks
Also, thanks http://stackoverflow.com/questions/505467/can-i-store-the-git-folder-outside-the-files-i-want-tracked
larsks