# git's is_inside_git_dir too strict?

8 messages from 2007-03-06 to 2007-03-10. Participants: Nguyen Thai Ngoc Duy, Johannes Schindelin, Shawn O. Pearce, Matthias Lederhofer, Junio C Hamano.
Thread: https://gitlist.dev/t/7111

## Nguyen Thai Ngoc Duy, 2007-03-06 15:41

Subject: git's is_inside_git_dir too strict?
Message-ID: <fcaeb9bf0703060741l7cbfd0f3ue443730176606db6@mail.gmail.com>
URL: https://gitlist.dev/e/fcaeb9bf0703060741l7cbfd0f3ue443730176606db6%40mail.gmail.com

```
Hi,

I have a working directory separated from its git repository. When I
work on this directory, I specify --git-dir argument (actually all
happens in script so I don't have to type that much). It used to work
but no longer since git 1.5.0. Complaints include "cannot be used
without a working tree" and "This operation must be run in a work
tree". Can I have the former behaviour back in some ways?
-- 
Duy

```

## Johannes Schindelin, 2007-03-06 21:46

Subject: Re: git's is_inside_git_dir too strict?
Message-ID: <Pine.LNX.4.63.0703062232570.22628@wbgn013.biozentrum.uni-wuerzburg.de>
URL: https://gitlist.dev/e/Pine.LNX.4.63.0703062232570.22628%40wbgn013.biozentrum.uni-wuerzburg.de
In-Reply-To: <fcaeb9bf0703060741l7cbfd0f3ue443730176606db6@mail.gmail.com>

```
Hi,

On Tue, 6 Mar 2007, Nguyen Thai Ngoc Duy wrote:

> I have a working directory separated from its git repository. When I
> work on this directory, I specify --git-dir argument (actually all
> happens in script so I don't have to type that much). It used to work
> but no longer since git 1.5.0.

Yes, we tried to make sure a few common errors were harder to make.

> Complaints include "cannot be used without a working tree" and "This 
> operation must be run in a work tree". Can I have the former behaviour 
> back in some ways?

Well, there is a real problem with "This operation must be run in a work 
tree". What operation is that? We tried to make it hard to overwrite 
things in $GIT_DIR by running Git operations meant for the working tree, 
and it seems like you are running one of them.

However, I think that is_bare_repository() really should check if 
$GIT_DIR is a prefix of $(pwd). Because if it is not, we are likely to run 
in a detached work tree.

If you agree, then is_inside_git_dir() might actually be a better way to 
ask if the repo is bare than is_bare_repository().

Comments?

Ciao,
Dscho

```

## Nguyen Thai Ngoc Duy, 2007-03-07 12:17

Subject: Re: git's is_inside_git_dir too strict?
Message-ID: <fcaeb9bf0703070417n5d3fb168jc7efd4642ad38c92@mail.gmail.com>
URL: https://gitlist.dev/e/fcaeb9bf0703070417n5d3fb168jc7efd4642ad38c92%40mail.gmail.com
In-Reply-To: <Pine.LNX.4.63.0703062232570.22628@wbgn013.biozentrum.uni-wuerzburg.de>

```
On 3/7/07, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
> > Complaints include "cannot be used without a working tree" and "This
> > operation must be run in a work tree". Can I have the former behaviour
> > back in some ways?
>
> Well, there is a real problem with "This operation must be run in a work
> tree". What operation is that? We tried to make it hard to overwrite
> things in $GIT_DIR by running Git operations meant for the working tree,
> and it seems like you are running one of them.

>From this command:

git --git-dir=/home/pclouds/blog/data.git ls-files --others --modified
2007-03-07T18_52_41.txt

It was run in /home/pclouds/blog/data, which is the working directory
of data.git.

By the way, is it plausible to add --git-workdir option to specify
working directory? With that option, I won't need to chdir to the
working directory, run git commands and chdir back.

>
> However, I think that is_bare_repository() really should check if
> $GIT_DIR is a prefix of $(pwd). Because if it is not, we are likely to run
> in a detached work tree.
>
> If you agree, then is_inside_git_dir() might actually be a better way to
> ask if the repo is bare than is_bare_repository().
>
> Comments?

I didn't follow git development lately so I'm afraid I'm incapable to
comment on this :-)

>
> Ciao,
> Dscho
>
>


-- 
Duy

```

## Shawn O. Pearce, 2007-03-07 15:53

Subject: Re: git's is_inside_git_dir too strict?
Message-ID: <20070307155307.GC27596@spearce.org>
URL: https://gitlist.dev/e/20070307155307.GC27596%40spearce.org
In-Reply-To: <fcaeb9bf0703070417n5d3fb168jc7efd4642ad38c92@mail.gmail.com>

```
Nguyen Thai Ngoc Duy <pclouds@gmail.com> wrote:
> On 3/7/07, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
> >Well, there is a real problem with "This operation must be run in a work
> >tree". What operation is that? We tried to make it hard to overwrite
> >things in $GIT_DIR by running Git operations meant for the working tree,
> >and it seems like you are running one of them.
> 
> From this command:
> 
> git --git-dir=/home/pclouds/blog/data.git ls-files --others --modified
> 2007-03-07T18_52_41.txt
> 
> It was run in /home/pclouds/blog/data, which is the working directory
> of data.git.

Why not just symlink it?

	cd /home/pclouds/blog/data
	ln -s ../data.git .git

But really, why is your Git repository for the working directory
outside of the working directory?  Why not just move data.git to
data/.git ?

-- 
Shawn.

```

## Nguyen Thai Ngoc Duy, 2007-03-07 16:12

Subject: Re: git's is_inside_git_dir too strict?
Message-ID: <fcaeb9bf0703070812y27425b07pf78fbdf14898b360@mail.gmail.com>
URL: https://gitlist.dev/e/fcaeb9bf0703070812y27425b07pf78fbdf14898b360%40mail.gmail.com
In-Reply-To: <20070307155307.GC27596@spearce.org>

```
On 3/7/07, Shawn O. Pearce <spearce@spearce.org> wrote:
> Nguyen Thai Ngoc Duy <pclouds@gmail.com> wrote:
> > It was run in /home/pclouds/blog/data, which is the working directory
> > of data.git.
>
> Why not just symlink it?
>
>         cd /home/pclouds/blog/data
>         ln -s ../data.git .git

It's currently my workaround.

> But really, why is your Git repository for the working directory
> outside of the working directory?  Why not just move data.git to
> data/.git ?

The directory "data" is  automatically manipulated by scripts. I feel
it safer for data.git being outside of data so if I make any mistake,
data.git _might_ remain intact. You see, if I link data/.git to
data.git, my scripts' bugs might affect data.git too.

> --
> Shawn.
>


-- 
Duy

```

## Matthias Lederhofer, 2007-03-09 12:00

Subject: Re: git's is_inside_git_dir too strict?
Message-ID: <20070309120001.GA32300@moooo.ath.cx>
URL: https://gitlist.dev/e/20070309120001.GA32300%40moooo.ath.cx
In-Reply-To: <fcaeb9bf0703070417n5d3fb168jc7efd4642ad38c92@mail.gmail.com>

```
Nguyen Thai Ngoc Duy <pclouds@gmail.com> wrote:
> By the way, is it plausible to add --git-workdir option to specify
> working directory? With that option, I won't need to chdir to the
> working directory, run git commands and chdir back.

http://article.gmane.org/gmane.comp.version-control.git/38382
Since I did not need this feature that much and no one replied that
there is any interest I did not look any further into it.

```

## Junio C Hamano, 2007-03-10 01:11

Subject: Re: git's is_inside_git_dir too strict?
Message-ID: <7vzm6l2982.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vzm6l2982.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <20070309120001.GA32300@moooo.ath.cx>

```
Matthias Lederhofer <matled@gmx.net> writes:

> Nguyen Thai Ngoc Duy <pclouds@gmail.com> wrote:
>> By the way, is it plausible to add --git-workdir option to specify
>> working directory? With that option, I won't need to chdir to the
>> working directory, run git commands and chdir back.
>
> http://article.gmane.org/gmane.comp.version-control.git/38382
> Since I did not need this feature that much and no one replied that
> there is any interest I did not look any further into it.

FWIW, I was once in favor of that, and currently I am neutral.
I vaguely recall that I suggested something like that back when
I was still a contributor.  The proposal was shot down by people
on the list, but I do not recall the details of why.

```

## Nguyen Thai Ngoc Duy, 2007-03-10 11:49

Subject: Re: git's is_inside_git_dir too strict?
Message-ID: <fcaeb9bf0703100349h329bbc1dn41e65531a8d1e5b9@mail.gmail.com>
URL: https://gitlist.dev/e/fcaeb9bf0703100349h329bbc1dn41e65531a8d1e5b9%40mail.gmail.com
In-Reply-To: <20070309120001.GA32300@moooo.ath.cx>

```
On 3/9/07, Matthias Lederhofer <matled@gmx.net> wrote:
> Nguyen Thai Ngoc Duy <pclouds@gmail.com> wrote:
> > By the way, is it plausible to add --git-workdir option to specify
> > working directory? With that option, I won't need to chdir to the
> > working directory, run git commands and chdir back.
>
> http://article.gmane.org/gmane.comp.version-control.git/38382
> Since I did not need this feature that much and no one replied that
> there is any interest I did not look any further into it.
>

You obviously have a fan now :) Are you going to rework the patch? I
think I could finish it if you don't have time for it. FYI, the patch
seems not working ("Not below specified working directory")

-- 
Duy

```
