All of lore.kernel.org
 help / color / mirror / Atom feed
* Should 'git status' understand a .git containing "gitdir: dir"?
@ 2011-06-30  9:04 Eric Raible
  2011-06-30 11:46 ` [RFC] status - don't show gitdir Fredrik Gustafsson
  2011-06-30 15:49 ` Should 'git status' understand a .git containing "gitdir: dir"? Junio C Hamano
  0 siblings, 2 replies; 5+ messages in thread
From: Eric Raible @ 2011-06-30  9:04 UTC (permalink / raw)
  To: git, Junio C Hamano

The following sequence sets up a trivial repo that uses "gitdir:":

$ git init gitdir-test
$ cd gitdir-test
$ mv .git real-git-dir
$ echo "gitdir: real-git-dir" > .git
$ git status

Fine so far.  But git-status shows that "real-git-dir" is untracked:

$ git status -sb
## Initial commit on master
?? real-git-dir/

Which strikes one as a bit inconsistent (since other pars of git-status
knows to look in real-git-dir to find the index).

Sorry - no time to investigate.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [RFC] status - don't show gitdir
  2011-06-30  9:04 Should 'git status' understand a .git containing "gitdir: dir"? Eric Raible
@ 2011-06-30 11:46 ` Fredrik Gustafsson
  2011-06-30 12:32   ` Nguyen Thai Ngoc Duy
  2011-06-30 15:49 ` Should 'git status' understand a .git containing "gitdir: dir"? Junio C Hamano
  1 sibling, 1 reply; 5+ messages in thread
From: Fredrik Gustafsson @ 2011-06-30 11:46 UTC (permalink / raw)
  To: raible; +Cc: iveqy, jens.lehmann, hvoigt, git, gitster

When gitdir is inside the working dir, don't show it as a untracked
directory.

Signed-off-by: Fredrik Gustafsson <iveqy@iveqy.com>
---
This patch works but have a few weaknesses. The string manipulations done
is cumbersome and can possible be done nicer (not what I could to with
support of strbuf).

Also, this patch doesn't know why .git isn't showed as untracked. Maybe
this code is at the wrong place.

 dir.c             |   28 ++++++++++++++++++++++++++++
 t/t7508-status.sh |   10 ++++++++++
 2 files changed, 38 insertions(+), 0 deletions(-)

diff --git a/dir.c b/dir.c
index 08281d2..9cabc29 100644
--- a/dir.c
+++ b/dir.c
@@ -1215,6 +1215,13 @@ int remove_dir_recursively(struct strbuf *path, int flag)
 void setup_standard_excludes(struct dir_struct *dir)
 {
 	const char *path;
+	const char *work_tree;
+	const char *git_dir;
+	struct strbuf wt_full;
+	struct strbuf gd_base;
+	struct strbuf gd_relpath;
+	struct strbuf gd;
+	int i = 0;
 
 	dir->exclude_per_dir = ".gitignore";
 	path = git_path("info/exclude");
@@ -1222,6 +1229,27 @@ void setup_standard_excludes(struct dir_struct *dir)
 		add_excludes_from_file(dir, path);
 	if (excludes_file && !access(excludes_file, R_OK))
 		add_excludes_from_file(dir, excludes_file);
+	work_tree = get_git_work_tree();
+	strbuf_init(&wt_full,0);
+	strbuf_addstr(&wt_full,work_tree);
+	strbuf_addstr(&wt_full,"/.git");
+	git_dir = read_gitfile_gently(wt_full.buf);
+	strbuf_remove(&wt_full,wt_full.len-5,5);
+	if(git_dir) {
+		strbuf_init(&gd,0);
+		strbuf_addstr(&gd,git_dir);
+		if(gd.len > wt_full.len) {
+			strbuf_init(&gd_base,0);
+			strbuf_add(&gd_base,wt_full.buf,wt_full.len);
+			if(!strbuf_cmp(&gd_base,&wt_full)) {
+				strbuf_init(&gd_relpath,0);
+				for(i = gd_base.len + 1; i < gd.len; i++) {
+					strbuf_addch(&gd_relpath,gd.buf[i]);
+				}
+				add_exclude(gd_relpath.buf,"",0,&dir->exclude_list[EXC_FILE]);
+			}
+		}
+	}
 }
 
 int remove_path(const char *name)
diff --git a/t/t7508-status.sh b/t/t7508-status.sh
index 1fdfbd3..1fed0cf 100755
--- a/t/t7508-status.sh
+++ b/t/t7508-status.sh
@@ -1139,4 +1139,14 @@ test_expect_failure '.git/config ignore=all suppresses submodule summary' '
 	git config -f .gitmodules  --remove-section submodule.subname
 '
 
+test_expect_success 'Check if git-dir is ignored when gitfile is used' '
+	git init gitdir-test &&
+	cd gitdir-test &&
+	mv .git real-git-dir &&
+	echo "gitdir: real-git-dir" > .git &&
+	git status -s real-git-dir > actual &&
+	> expect &&
+	test_cmp actual expect
+'
+
 test_done
-- 
1.7.6.rc3.dirty

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [RFC] status - don't show gitdir
  2011-06-30 11:46 ` [RFC] status - don't show gitdir Fredrik Gustafsson
@ 2011-06-30 12:32   ` Nguyen Thai Ngoc Duy
  0 siblings, 0 replies; 5+ messages in thread
From: Nguyen Thai Ngoc Duy @ 2011-06-30 12:32 UTC (permalink / raw)
  To: Fredrik Gustafsson; +Cc: raible, jens.lehmann, hvoigt, git, gitster

On Thu, Jun 30, 2011 at 6:46 PM, Fredrik Gustafsson <iveqy@iveqy.com> wrote:
> When gitdir is inside the working dir, don't show it as a untracked
> directory.

read_directory_recursive() and friends ignore .git by default. I think
if you want to ignore the directory that .git file points to, you
should update there. I'm too lazy to check the code (my
read_directory_recursive is heavily modified currently), but I think
it does not check file type for .git entries now.

But if we step back a bit, why do you want git to automatically ignore
dirs that .git file points to? .git files are used to save real repo
somewhere safe, e.g. outside working directory. You do not handle
another case in your patch, where .git is a real symlink. In both
cases, it's not hard to add "real-git-dir" to .git/info/excludes.
-- 
Duy

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Should 'git status' understand a .git containing "gitdir: dir"?
  2011-06-30  9:04 Should 'git status' understand a .git containing "gitdir: dir"? Eric Raible
  2011-06-30 11:46 ` [RFC] status - don't show gitdir Fredrik Gustafsson
@ 2011-06-30 15:49 ` Junio C Hamano
  2011-06-30 16:48   ` Eric Raible
  1 sibling, 1 reply; 5+ messages in thread
From: Junio C Hamano @ 2011-06-30 15:49 UTC (permalink / raw)
  To: Eric Raible; +Cc: git

Eric Raible <raible@nextest.com> writes:

> The following sequence sets up a trivial repo that uses "gitdir:":
>
> $ git init gitdir-test
> $ cd gitdir-test
> $ mv .git real-git-dir
> $ echo "gitdir: real-git-dir" > .git
> $ git status
>
> Fine so far.  But git-status shows that "real-git-dir" is untracked:
>
> $ git status -sb
> ## Initial commit on master
> ?? real-git-dir/
>
> Which strikes one as a bit inconsistent (since other pars of git-status
> knows to look in real-git-dir to find the index).
>
> Sorry - no time to investigate.

You could even have a real git dir of some completely unrelated repository
in your working tree, it will get reported as untracked, and you would
probably not want to track its contents, either (or you might want to if
you are trying to be funny, I dunno).

So I do not see there is anything to investigate. What you observed looks
perfectly expected to me, except for the "mv .git real-git-dir" bit that
makes a situation that confuses yourself (but not git).

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Should 'git status' understand a .git containing "gitdir: dir"?
  2011-06-30 15:49 ` Should 'git status' understand a .git containing "gitdir: dir"? Junio C Hamano
@ 2011-06-30 16:48   ` Eric Raible
  0 siblings, 0 replies; 5+ messages in thread
From: Eric Raible @ 2011-06-30 16:48 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

On 6/30/2011 8:49 AM, Junio C Hamano wrote:
> Eric Raible <raible@nextest.com> writes:
> 
>> The following sequence sets up a trivial repo that uses "gitdir:":
>>
>> $ git init gitdir-test
>> $ cd gitdir-test
>> $ mv .git real-git-dir
>> $ echo "gitdir: real-git-dir" > .git
>> $ git status
>>
>> Fine so far.  But git-status shows that "real-git-dir" is untracked:
>>
>> $ git status -sb
>> ## Initial commit on master
>> ?? real-git-dir/
>>
>> Which strikes one as a bit inconsistent (since other pars of git-status
>> knows to look in real-git-dir to find the index).
>>
>> Sorry - no time to investigate.
> 
> You could even have a real git dir of some completely unrelated repository
> in your working tree, it will get reported as untracked, and you would
> probably not want to track its contents, either (or you might want to if
> you are trying to be funny, I dunno).
> 
> So I do not see there is anything to investigate. What you observed looks
> perfectly expected to me, except for the "mv .git real-git-dir" bit that
> makes a situation that confuses yourself (but not git).
> .

The fact that the repo is stored in .git is an implementation detail -
and one which git-status knows about (in the normal case).

In the gidir: case one part of git status understands the details
(after all - it reads real-git-dir/index) while another part doesn't
(after all - it show the actual repo as a normal directory).

Sure, git-real-dir could be added to git-real-dir/info/exclude.
But by that logic we could insist on adding .git to .git/info/exclude.

The argument about an unrelated repo in the working tree is irrelevant -
.git wouldn't point to it, so there's nothings special about it.

But it's obviously not a big deal either way and I'm gonna drop it.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-06-30 16:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-30  9:04 Should 'git status' understand a .git containing "gitdir: dir"? Eric Raible
2011-06-30 11:46 ` [RFC] status - don't show gitdir Fredrik Gustafsson
2011-06-30 12:32   ` Nguyen Thai Ngoc Duy
2011-06-30 15:49 ` Should 'git status' understand a .git containing "gitdir: dir"? Junio C Hamano
2011-06-30 16:48   ` Eric Raible

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.