threads / discuss / 7111

git's is_inside_git_dir too strict?

Subject: git's is_inside_git_dir too strict?

## tl;dr

8 messages between Mar 6, 2007 and Mar 10, 2007.

replies: 7people: 5as markdown or json

Nguyen Thai Ngoc Duy· Mar 6, 2007, 15:41 UTC · lore
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· Mar 6, 2007, 21:46 UTC · re: Nguyen Thai Ngoc Duy · lore

Re: git's is_inside_git_dir too strict?

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· Mar 7, 2007, 12:17 UTC · re: Johannes Schindelin · lore

Re: git's is_inside_git_dir too strict?

On 3/7/07, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
Show 8 quoted lines
> > 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.

Show 9 quoted lines
>
> 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 :-)

Show 5 quoted lines
>
> Ciao,
> Dscho
>
>
-- 
Duy
Shawn O. Pearce· Mar 7, 2007, 15:53 UTC · re: Nguyen Thai Ngoc Duy · lore

Re: git's is_inside_git_dir too strict?

Nguyen Thai Ngoc Duy <pclouds@gmail.com> wrote:
Show 13 quoted lines
> 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· Mar 7, 2007, 16:12 UTC · re: Shawn O. Pearce · lore

Re: git's is_inside_git_dir too strict?

On 3/7/07, Shawn O. Pearce <spearce@spearce.org> wrote:
Show 8 quoted lines
> 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· Mar 9, 2007, 12:00 UTC · re: Nguyen Thai Ngoc Duy · lore

Re: git's is_inside_git_dir too strict?

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· Mar 10, 2007, 01:11 UTC · re: Matthias Lederhofer · lore

Re: git's is_inside_git_dir too strict?

Matthias Lederhofer <matled@gmx.net> writes:
Show 8 quoted lines
> 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· Mar 10, 2007, 11:49 UTC · re: Matthias Lederhofer · lore

Re: git's is_inside_git_dir too strict?

On 3/9/07, Matthias Lederhofer <matled@gmx.net> wrote:
Show 9 quoted lines
> 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

← back to recent threads