* GIT_WORK_TREE and GIT_DIR with git clone
@ 2014-01-20 15:59 Cosmin Apreutesei
2014-01-21 20:23 ` Junio C Hamano
0 siblings, 1 reply; 6+ messages in thread
From: Cosmin Apreutesei @ 2014-01-20 15:59 UTC (permalink / raw)
To: git
Hi,
I would like to have git clone respect GIT_DIR (and --git-dir) so I
can clone multiple repos into the same working directory (I know there
was another request for this[1]).
The pattern here is big projects that are modularized into multiple
git repositories, but supposed to be overlaid over a common directory
structure.
I would like to be able to tell my users that they can simply do:
git clone --git-dir=_/git/module1/.git module1-url
git clone --git-dir=_/git/module2/.git module2-url
which will overlay the files from both modules into the current
directory, which from git's perspective is the work-tree for both
modules.
[1] http://article.gmane.org/gmane.comp.version-control.git/170073/match=git_work_tree+git_dir+git+clone
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: GIT_WORK_TREE and GIT_DIR with git clone
2014-01-20 15:59 GIT_WORK_TREE and GIT_DIR with git clone Cosmin Apreutesei
@ 2014-01-21 20:23 ` Junio C Hamano
2014-01-21 21:37 ` Cosmin Apreutesei
0 siblings, 1 reply; 6+ messages in thread
From: Junio C Hamano @ 2014-01-21 20:23 UTC (permalink / raw)
To: Cosmin Apreutesei; +Cc: git
Cosmin Apreutesei <cosmin.apreutesei@gmail.com> writes:
> I would like to be able to tell my users that they can simply do:
>
> git clone --git-dir=_/git/module1/.git module1-url
> git clone --git-dir=_/git/module2/.git module2-url
>
> which will overlay the files from both modules into the current
> directory, which from git's perspective is the work-tree for both
> modules.
Would there be a sensible semantics in the resulting working tree?
Which repository would a new file in such a combined working tree
belong to?
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: GIT_WORK_TREE and GIT_DIR with git clone
2014-01-21 20:23 ` Junio C Hamano
@ 2014-01-21 21:37 ` Cosmin Apreutesei
0 siblings, 0 replies; 6+ messages in thread
From: Cosmin Apreutesei @ 2014-01-21 21:37 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
Hi, thanks for answering.
>> I would like to be able to tell my users that they can simply do:
>>
>> git clone --git-dir=_/git/module1/.git module1-url
>> git clone --git-dir=_/git/module2/.git module2-url
>>
>> which will overlay the files from both modules into the current
>> directory, which from git's perspective is the work-tree for both
>> modules.
>
> Would there be a sensible semantics in the resulting working tree?
> Which repository would a new file in such a combined working tree
> belong to?
The developer would have to decide by way of `git add`.
Ignoring other repos' files would be done by way of local config
option `excludesfile` (.gitignore is out).
To make it easier to work with git this way, a script that creates a
subshell in the context of a repo can be done with something like
`PS1="[$1 $PS1]" GIT_DIR=_git/$1/.git bash -i" -- git would then work
as usual in that subshell for that specific repo, never leaving the
working tree.
I successfully employed the above scheme with luapower[1] packages,
which are all different and mostly unrelated libraries, but which need
to be overlaid over a common directory structure. And that's just an
example. I can think of many projects that are modularized and yet the
modules need to place many files in many places to make a working
system (web frameworks, the linux filesystem, etc.)
Currently, to clone a repo one has to do:
export GIT_DIR=_git/submodule/.git
git init
git config --local core.worktree ../../..
git remote add origin ssh://git@github.com/luapower/submodule.git
git fetch
git branch --track master origin/master
git checkout
That's 6 commands for what could be:
git clone --git-dir=_git/submodule/.git
ssh://git@github.com/luapower/submodule.git
Or even better:
git clone --git-dirs=_git ssh://git@github.com/luapower/submodule.git
[1] http://luapower.com
^ permalink raw reply [flat|nested] 6+ messages in thread
* GIT_WORK_TREE and GIT_DIR with git clone
@ 2011-03-26 12:58 Kacper Kornet
2011-03-26 19:40 ` Junio C Hamano
0 siblings, 1 reply; 6+ messages in thread
From: Kacper Kornet @ 2011-03-26 12:58 UTC (permalink / raw)
To: git
Is there a reason why git clone does not respect GIT_DIR
variable. I have found it confusing that:
GIT_WORK_TREE=repo GIT_DIR=repo/.git git clone <path>/repo.git
is not equivalent to
git clone <path>/repo.git
--
Kacper
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: GIT_WORK_TREE and GIT_DIR with git clone
2011-03-26 12:58 Kacper Kornet
@ 2011-03-26 19:40 ` Junio C Hamano
2011-03-26 23:37 ` Kacper Kornet
0 siblings, 1 reply; 6+ messages in thread
From: Junio C Hamano @ 2011-03-26 19:40 UTC (permalink / raw)
To: Kacper Kornet; +Cc: git
Kacper Kornet <kornet@camk.edu.pl> writes:
> Is there a reason why git clone does not respect GIT_DIR
> variable.
Are you sure it does "not respect GIT_DIR"? When you are running clone
locally, like that:
> GIT_WORK_TREE=repo GIT_DIR=repo/.git git clone <path>/repo.git
you have _two_ repositories that the command operates on on your system,
the one that you are cloning _from_, and the new one that you are
creating.
Which repository does your GIT_DIR talk about?
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: GIT_WORK_TREE and GIT_DIR with git clone
2011-03-26 19:40 ` Junio C Hamano
@ 2011-03-26 23:37 ` Kacper Kornet
0 siblings, 0 replies; 6+ messages in thread
From: Kacper Kornet @ 2011-03-26 23:37 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
On Sat, Mar 26, 2011 at 12:40:58PM -0700, Junio C Hamano wrote:
> Kacper Kornet <kornet@camk.edu.pl> writes:
> > Is there a reason why git clone does not respect GIT_DIR
> > variable.
> Are you sure it does "not respect GIT_DIR"? When you are running clone
> locally, like that:
> > GIT_WORK_TREE=repo GIT_DIR=repo/.git git clone <path>/repo.git
> you have _two_ repositories that the command operates on on your system,
> the one that you are cloning _from_, and the new one that you are
> creating.
> Which repository does your GIT_DIR talk about?
I would expect that GIT_DIR always talks the new one. For example after:
GIT_WORK_TREE=dir GIT_DIR=dir/.git git clone git://git.kernel.org/pub/scm/gitk/gitk
I would expect to have repo in dir/.git. What happens is that in dir
there is a working tree and in local directory gitk there is a bare
repo. The following patch should fix the issue:
diff --git a/builtin/clone.c b/builtin/clone.c
index c6e10bb..082ee53 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -442,11 +442,14 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
die("working tree '%s' already exists.", work_tree);
}
- if (option_bare || work_tree)
- git_dir = xstrdup(dir);
- else {
+ git_dir = getenv("GIT_DIR");
+ if (option_bare || work_tree) {
+ if (!git_dir)
+ git_dir = xstrdup(dir);
+ } else {
work_tree = dir;
- git_dir = xstrdup(mkpath("%s/.git", dir));
+ if (!git_dir)
+ git_dir = xstrdup(mkpath("%s/.git", dir));
}
if (!option_bare) {
--
Kacper
^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2014-01-21 21:37 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-01-20 15:59 GIT_WORK_TREE and GIT_DIR with git clone Cosmin Apreutesei
2014-01-21 20:23 ` Junio C Hamano
2014-01-21 21:37 ` Cosmin Apreutesei
-- strict thread matches above, loose matches on Subject: below --
2011-03-26 12:58 Kacper Kornet
2011-03-26 19:40 ` Junio C Hamano
2011-03-26 23:37 ` Kacper Kornet
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).