* Need to set GIT_WORK_TREE when setting GIT_DIR !?
@ 2012-03-09 22:51 Frédéric Heitzmann
2012-03-09 23:06 ` Junio C Hamano
2012-03-10 14:11 ` Jonathan Nieder
0 siblings, 2 replies; 7+ messages in thread
From: Frédéric Heitzmann @ 2012-03-09 22:51 UTC (permalink / raw)
To: Git Mailing List
Hi all,
I want to set GIT_DIR to another path than <project_dir>/.git.
Unfortunately, git add or git status failed with the following error:
fatal: This operation must be run in a work tree
Unless I also set GIT_WORK_TREE, git status|add|stash|clean|... always fail.
git or git-config man pages does not state anything like this.
Did I miss something ?
#test-case :
export GIT_DIR=$PWD/.gita &&
git init
echo "file a" >> a.txt &&
git add a.txt #fail
git status #fail
export GIT_WORK_TREE=$PWD
git status #pass
git add a.txt &&
git commit -m'file a' #pass
unset GIT_WORK_TREE
git status #fail, it does not look like some bug related to a newly
created, empty repository
Note: that using --git-dir instead of GIT_DIR give the same errors.
--
Fred
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Need to set GIT_WORK_TREE when setting GIT_DIR !?
2012-03-09 22:51 Need to set GIT_WORK_TREE when setting GIT_DIR !? Frédéric Heitzmann
@ 2012-03-09 23:06 ` Junio C Hamano
2012-03-10 13:23 ` Frédéric Heitzmann
2012-03-10 14:11 ` Jonathan Nieder
1 sibling, 1 reply; 7+ messages in thread
From: Junio C Hamano @ 2012-03-09 23:06 UTC (permalink / raw)
To: Frédéric Heitzmann; +Cc: Git Mailing List
Frédéric Heitzmann <frederic.heitzmann@gmail.com> writes:
Yes, to the question on the Subject line. But you can also say
[core] worktree = /path/to/the/work/tree
in $GIT_DIR/config. Make sure your $GIT_DIR/config does *NOT* say
that the repository is a bare repository.
> ...
> Note: that using --git-dir instead of GIT_DIR give the same errors.
Yes, that is the intended behaviour; the command line option and the
environment variable should give you the same consistent effect).
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Need to set GIT_WORK_TREE when setting GIT_DIR !?
2012-03-09 23:06 ` Junio C Hamano
@ 2012-03-10 13:23 ` Frédéric Heitzmann
2012-03-10 14:05 ` Nguyen Thai Ngoc Duy
0 siblings, 1 reply; 7+ messages in thread
From: Frédéric Heitzmann @ 2012-03-10 13:23 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Git Mailing List
Le 10/03/2012 00:06, Junio C Hamano a écrit :
> Yes, to the question on the Subject line. But you can also say
>
> [core] worktree = /path/to/the/work/tree
>
> in $GIT_DIR/config. Make sure your $GIT_DIR/config does *NOT* say
> that the repository is a bare repository.
Thanks for clarification.
However man git-config says :
"If --git-dir or GIT_DIR is specified but none of --work-tree,
GIT_WORK_TREE and core.worktree is specified, the
current working directory is regarded as the top level of your working
tree."
Some more context on my precise problem :
I have a project, with source files managed with git.
I also use some Makefiles that I would like to manage with git _in a
separate repository_
$ GIT_DIR=<project_path>/.git git add some_file.c ...
$ GIT_DIR=<project_path>/.git_mk git add Makefile ...
Setting worktree in each GIT_DIR/config will fix that but I can't figure
out why current git implementation actually needs this.
--
Fred
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Need to set GIT_WORK_TREE when setting GIT_DIR !?
2012-03-10 13:23 ` Frédéric Heitzmann
@ 2012-03-10 14:05 ` Nguyen Thai Ngoc Duy
2012-03-10 21:20 ` Junio C Hamano
0 siblings, 1 reply; 7+ messages in thread
From: Nguyen Thai Ngoc Duy @ 2012-03-10 14:05 UTC (permalink / raw)
To: Frédéric Heitzmann; +Cc: Junio C Hamano, Git Mailing List
2012/3/10 Frédéric Heitzmann <frederic.heitzmann@gmail.com>:
> However man git-config says :
>
> "If --git-dir or GIT_DIR is specified but none of --work-tree, GIT_WORK_TREE
> and core.worktree is specified, the
> current working directory is regarded as the top level of your working
> tree."
>
> Some more context on my precise problem :
> I have a project, with source files managed with git.
> I also use some Makefiles that I would like to manage with git _in a
> separate repository_
>
> $ GIT_DIR=<project_path>/.git git add some_file.c ...
> $ GIT_DIR=<project_path>/.git_mk git add Makefile ...
>
> Setting worktree in each GIT_DIR/config will fix that but I can't figure out
> why current git implementation actually needs this.
Historical reason: before separate worktree feature was introduced,
git assumed worktree was at $GIT_DIR's parent directory. Old scripts
may rely on that behavior.
--
Duy
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Need to set GIT_WORK_TREE when setting GIT_DIR !?
2012-03-09 22:51 Need to set GIT_WORK_TREE when setting GIT_DIR !? Frédéric Heitzmann
2012-03-09 23:06 ` Junio C Hamano
@ 2012-03-10 14:11 ` Jonathan Nieder
1 sibling, 0 replies; 7+ messages in thread
From: Jonathan Nieder @ 2012-03-10 14:11 UTC (permalink / raw)
To: Frédéric Heitzmann; +Cc: Git Mailing List
Hi,
Frédéric Heitzmann wrote:
> export GIT_DIR=$PWD/.gita &&
> git init
This is where the recipe goes wrong. It creates a bare repository.
Using vi or "git config" to edit its configuration to set the "[core]
bare" setting to false would change that.
The git-config(1) manpage says:
By default a repository that ends in "/.git" is assumed to be
not bare (bare = false), while all other repositories are
assumed to be bare (bare = true).
and the logic in builtin/init-db.c seems to agree.
Maybe there is a better place to document this. Improvements
welcome.
Thanks,
Jonathan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Need to set GIT_WORK_TREE when setting GIT_DIR !?
2012-03-10 14:05 ` Nguyen Thai Ngoc Duy
@ 2012-03-10 21:20 ` Junio C Hamano
[not found] ` <CALeToSVPWPwJTYxRgy0BW4TBfBJrb+LXC+QJDWjceQ=4f2_tRw@mail.gmail.com>
0 siblings, 1 reply; 7+ messages in thread
From: Junio C Hamano @ 2012-03-10 21:20 UTC (permalink / raw)
To: Nguyen Thai Ngoc Duy; +Cc: Frédéric Heitzmann, Git Mailing List
Nguyen Thai Ngoc Duy <pclouds@gmail.com> writes:
> Historical reason: before separate worktree feature was introduced,
> git assumed worktree was at $GIT_DIR's parent directory.
Isn't the rule that the current directory becomes the root of the
working tree if you did not have GIT_WORK_TREE?
In any case, the way I read Frédéric is that the other repository's
files will be accessed only from the root of the working tree, so as
long as the GIT_DIR/config says it is not a bare repository, it
should be OK.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Need to set GIT_WORK_TREE when setting GIT_DIR !?
[not found] ` <CALeToSV6xx=Vfw8gRbmeKWDzcHFaYvgFhMqx5cwtCYKdASJptw@mail.gmail.com>
@ 2012-03-11 21:13 ` Frédéric Heitzmann
0 siblings, 0 replies; 7+ messages in thread
From: Frédéric Heitzmann @ 2012-03-11 21:13 UTC (permalink / raw)
To: Git Mailing List
Hi all,
My initial mistake was that I unintenionnaly created a bare repo (which
is really not what I want to do).
If I change that - GIt_DIR=.gita git init --no-bare - everything runs fine.
Lessons learned :
1/ the kind of repo - bare or not bare - that git init creates depends
on GIT_DIR.
This _is_ documented - I should have read more carefully - but it is
surprising for someone not aware of the history of GIT_DIR,
GIT_WORK_TREE, and so on.
Don't know if it 's worth changing this semantic though.
I let more experienced git hackers decide on this.
2/ Calling a git command that needs a working tree (add, status, commit,
...) in a bare repo should probably trigger a more explicit message.
Using the current directory if GIT_WORK_TREE is not set would actually
hide a potential configuration problem.
Thanks for your help,
--
Fred
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2012-03-11 21:14 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-09 22:51 Need to set GIT_WORK_TREE when setting GIT_DIR !? Frédéric Heitzmann
2012-03-09 23:06 ` Junio C Hamano
2012-03-10 13:23 ` Frédéric Heitzmann
2012-03-10 14:05 ` Nguyen Thai Ngoc Duy
2012-03-10 21:20 ` Junio C Hamano
[not found] ` <CALeToSVPWPwJTYxRgy0BW4TBfBJrb+LXC+QJDWjceQ=4f2_tRw@mail.gmail.com>
[not found] ` <CALeToSV6xx=Vfw8gRbmeKWDzcHFaYvgFhMqx5cwtCYKdASJptw@mail.gmail.com>
2012-03-11 21:13 ` Frédéric Heitzmann
2012-03-10 14:11 ` Jonathan Nieder
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).