Thread (2 messages) flat view 2 messages, 2 authors, 2016-06-15

Re: [PATCH] Solve git-submodule issues with detached work trees

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:54:18

Jens Lehmann [off-list ref] writes:
Am 23.07.2012 07:09, schrieb Junio C Hamano:
quoted
Daniel Graña [off-list ref] writes:
quoted
A common way to track dotfiles with git is using GIT_DIR and
GIT_WORK_TREE to move repository out of ~/.git with something like:

    git init --bare ~/.dotfiles
    alias dotfiles="GIT_DIR=~/.dotfiles GIT_WORK_TREE=~ git"

    dotfiles add ~/.bashrc
    dotfiles commit -a -m "add my bashrc"
    ...

but git-submodule complains when trying to add submodules:

    dotfiles submodule add http://path.to/submodule
    fatal: working tree '/home/user' already exists.

    git --git-dir ~/.dotfiles submodule add http://path.to/submodule
    fatal: /usr/lib/git-core/git-submodule cannot be used without a
working tree.

Signed-off-by: Daniel Graña <redacted>
---
I think this is in line with what we discussed earlier on list when
the interaction between GIT_DIR/GIT_WORK_TREE and submodules came up
the last time.  Jens?
Yes, I think this is the only way submodules in current git can
be used with the GIT_DIR and GIT_WORK_TREE environment variables:
set them when adding or initializing the submodule and always use
the same settings when accessing them later. Daniel's dotfile
alias achieves exactly that, so his fix looks good. But I agree
the tests should be improved as you already pointed out.
Thanks for a quick review.  The "the only way ... in current git can
be used" part makes it sound as if it is a somewhat suboptimal ugly
workaround, but if that is what you meant, what is a more optimal
and less ugly way that you have in mind?

If you want to move .git out of way with GIT_DIR and if you want to
sit somewhere different from the top of your working tree, you must
use GIT_WORK_TREE (or core.worktree) to tell where the top resides,
whether your project use submodules or not, so I do not think it is
an ugly workaround but is the one true way to use such a dismembered
layout, I would think.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help