{"thread":{"id":"27733","subject":"Should 'git status' understand a .git containing \"gitdir: dir\"?","startedAt":"2011-06-30T09:04:29Z","lastAt":"2011-06-30T16:48:57Z","messageCount":5,"participants":["Eric Raible","Fredrik Gustafsson","Nguyen Thai Ngoc Duy","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"170702","messageId":"4E0C3C1D.1050406@nextest.com","threadId":"27733","inReplyTo":null,"subject":"Should 'git status' understand a .git containing \"gitdir: dir\"?","fromName":"Eric Raible","fromEmail":"raible@nextest.com","sentAt":"2011-06-30T09:04:29Z","receivedAt":"2011-06-30T09:04:29Z","isPatch":false,"sender":{"key":"raible@nextest.com","avatar":null},"body":"The following sequence sets up a trivial repo that uses \"gitdir:\":\n\n$ git init gitdir-test\n$ cd gitdir-test\n$ mv .git real-git-dir\n$ echo \"gitdir: real-git-dir\" > .git\n$ git status\n\nFine so far.  But git-status shows that \"real-git-dir\" is untracked:\n\n$ git status -sb\n## Initial commit on master\n?? real-git-dir/\n\nWhich strikes one as a bit inconsistent (since other pars of git-status\nknows to look in real-git-dir to find the index).\n\nSorry - no time to investigate.\n"},{"id":"170707","messageId":"1309434388-3536-1-git-send-email-iveqy@iveqy.com","threadId":"27733","inReplyTo":"4E0C3C1D.1050406@nextest.com","subject":"[RFC] status - don't show gitdir","fromName":"Fredrik Gustafsson","fromEmail":"iveqy@iveqy.com","sentAt":"2011-06-30T11:46:28Z","receivedAt":"2011-06-30T11:46:28Z","isPatch":false,"sender":{"key":"iveqy@iveqy.com","avatar":"https://avatars.githubusercontent.com/u/761743?v=4"},"body":"When gitdir is inside the working dir, don't show it as a untracked\ndirectory.\n\nSigned-off-by: Fredrik Gustafsson <iveqy@iveqy.com>\n---\nThis patch works but have a few weaknesses. The string manipulations done\nis cumbersome and can possible be done nicer (not what I could to with\nsupport of strbuf).\n\nAlso, this patch doesn't know why .git isn't showed as untracked. Maybe\nthis code is at the wrong place.\n\n dir.c             |   28 ++++++++++++++++++++++++++++\n t/t7508-status.sh |   10 ++++++++++\n 2 files changed, 38 insertions(+), 0 deletions(-)\n\ndiff --git a/dir.c b/dir.c\nindex 08281d2..9cabc29 100644\n--- a/dir.c\n+++ b/dir.c\n@@ -1215,6 +1215,13 @@ int remove_dir_recursively(struct strbuf *path, int flag)\n void setup_standard_excludes(struct dir_struct *dir)\n {\n \tconst char *path;\n+\tconst char *work_tree;\n+\tconst char *git_dir;\n+\tstruct strbuf wt_full;\n+\tstruct strbuf gd_base;\n+\tstruct strbuf gd_relpath;\n+\tstruct strbuf gd;\n+\tint i = 0;\n \n \tdir->exclude_per_dir = \".gitignore\";\n \tpath = git_path(\"info/exclude\");\n@@ -1222,6 +1229,27 @@ void setup_standard_excludes(struct dir_struct *dir)\n \t\tadd_excludes_from_file(dir, path);\n \tif (excludes_file && !access(excludes_file, R_OK))\n \t\tadd_excludes_from_file(dir, excludes_file);\n+\twork_tree = get_git_work_tree();\n+\tstrbuf_init(&wt_full,0);\n+\tstrbuf_addstr(&wt_full,work_tree);\n+\tstrbuf_addstr(&wt_full,\"/.git\");\n+\tgit_dir = read_gitfile_gently(wt_full.buf);\n+\tstrbuf_remove(&wt_full,wt_full.len-5,5);\n+\tif(git_dir) {\n+\t\tstrbuf_init(&gd,0);\n+\t\tstrbuf_addstr(&gd,git_dir);\n+\t\tif(gd.len > wt_full.len) {\n+\t\t\tstrbuf_init(&gd_base,0);\n+\t\t\tstrbuf_add(&gd_base,wt_full.buf,wt_full.len);\n+\t\t\tif(!strbuf_cmp(&gd_base,&wt_full)) {\n+\t\t\t\tstrbuf_init(&gd_relpath,0);\n+\t\t\t\tfor(i = gd_base.len + 1; i < gd.len; i++) {\n+\t\t\t\t\tstrbuf_addch(&gd_relpath,gd.buf[i]);\n+\t\t\t\t}\n+\t\t\t\tadd_exclude(gd_relpath.buf,\"\",0,&dir->exclude_list[EXC_FILE]);\n+\t\t\t}\n+\t\t}\n+\t}\n }\n \n int remove_path(const char *name)\ndiff --git a/t/t7508-status.sh b/t/t7508-status.sh\nindex 1fdfbd3..1fed0cf 100755\n--- a/t/t7508-status.sh\n+++ b/t/t7508-status.sh\n@@ -1139,4 +1139,14 @@ test_expect_failure '.git/config ignore=all suppresses submodule summary' '\n \tgit config -f .gitmodules  --remove-section submodule.subname\n '\n \n+test_expect_success 'Check if git-dir is ignored when gitfile is used' '\n+\tgit init gitdir-test &&\n+\tcd gitdir-test &&\n+\tmv .git real-git-dir &&\n+\techo \"gitdir: real-git-dir\" > .git &&\n+\tgit status -s real-git-dir > actual &&\n+\t> expect &&\n+\ttest_cmp actual expect\n+'\n+\n test_done\n-- \n1.7.6.rc3.dirty\n"},{"id":"170709","messageId":"BANLkTikCmWLar4ztZgrWdB-md2X3bUxATg@mail.gmail.com","threadId":"27733","inReplyTo":"1309434388-3536-1-git-send-email-iveqy@iveqy.com","subject":"Re: [RFC] status - don't show gitdir","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2011-06-30T12:32:20Z","receivedAt":"2011-06-30T12:32:20Z","isPatch":false,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Thu, Jun 30, 2011 at 6:46 PM, Fredrik Gustafsson <iveqy@iveqy.com> wrote:\n> When gitdir is inside the working dir, don't show it as a untracked\n> directory.\n\nread_directory_recursive() and friends ignore .git by default. I think\nif you want to ignore the directory that .git file points to, you\nshould update there. I'm too lazy to check the code (my\nread_directory_recursive is heavily modified currently), but I think\nit does not check file type for .git entries now.\n\nBut if we step back a bit, why do you want git to automatically ignore\ndirs that .git file points to? .git files are used to save real repo\nsomewhere safe, e.g. outside working directory. You do not handle\nanother case in your patch, where .git is a real symlink. In both\ncases, it's not hard to add \"real-git-dir\" to .git/info/excludes.\n-- \nDuy\n"},{"id":"170710","messageId":"7vsjqrqpzn.fsf@alter.siamese.dyndns.org","threadId":"27733","inReplyTo":"4E0C3C1D.1050406@nextest.com","subject":"Re: Should 'git status' understand a .git containing \"gitdir: dir\"?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-06-30T15:49:00Z","receivedAt":"2011-06-30T15:49:00Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Eric Raible <raible@nextest.com> writes:\n\n> The following sequence sets up a trivial repo that uses \"gitdir:\":\n>\n> $ git init gitdir-test\n> $ cd gitdir-test\n> $ mv .git real-git-dir\n> $ echo \"gitdir: real-git-dir\" > .git\n> $ git status\n>\n> Fine so far.  But git-status shows that \"real-git-dir\" is untracked:\n>\n> $ git status -sb\n> ## Initial commit on master\n> ?? real-git-dir/\n>\n> Which strikes one as a bit inconsistent (since other pars of git-status\n> knows to look in real-git-dir to find the index).\n>\n> Sorry - no time to investigate.\n\nYou could even have a real git dir of some completely unrelated repository\nin your working tree, it will get reported as untracked, and you would\nprobably not want to track its contents, either (or you might want to if\nyou are trying to be funny, I dunno).\n\nSo I do not see there is anything to investigate. What you observed looks\nperfectly expected to me, except for the \"mv .git real-git-dir\" bit that\nmakes a situation that confuses yourself (but not git).\n"},{"id":"170713","messageId":"4E0CA8F9.1080601@nextest.com","threadId":"27733","inReplyTo":"7vsjqrqpzn.fsf@alter.siamese.dyndns.org","subject":"Re: Should 'git status' understand a .git containing \"gitdir: dir\"?","fromName":"Eric Raible","fromEmail":"raible@nextest.com","sentAt":"2011-06-30T16:48:57Z","receivedAt":"2011-06-30T16:48:57Z","isPatch":false,"sender":{"key":"raible@nextest.com","avatar":null},"body":"On 6/30/2011 8:49 AM, Junio C Hamano wrote:\n> Eric Raible <raible@nextest.com> writes:\n> \n>> The following sequence sets up a trivial repo that uses \"gitdir:\":\n>>\n>> $ git init gitdir-test\n>> $ cd gitdir-test\n>> $ mv .git real-git-dir\n>> $ echo \"gitdir: real-git-dir\" > .git\n>> $ git status\n>>\n>> Fine so far.  But git-status shows that \"real-git-dir\" is untracked:\n>>\n>> $ git status -sb\n>> ## Initial commit on master\n>> ?? real-git-dir/\n>>\n>> Which strikes one as a bit inconsistent (since other pars of git-status\n>> knows to look in real-git-dir to find the index).\n>>\n>> Sorry - no time to investigate.\n> \n> You could even have a real git dir of some completely unrelated repository\n> in your working tree, it will get reported as untracked, and you would\n> probably not want to track its contents, either (or you might want to if\n> you are trying to be funny, I dunno).\n> \n> So I do not see there is anything to investigate. What you observed looks\n> perfectly expected to me, except for the \"mv .git real-git-dir\" bit that\n> makes a situation that confuses yourself (but not git).\n> .\n\nThe fact that the repo is stored in .git is an implementation detail -\nand one which git-status knows about (in the normal case).\n\nIn the gidir: case one part of git status understands the details\n(after all - it reads real-git-dir/index) while another part doesn't\n(after all - it show the actual repo as a normal directory).\n\nSure, git-real-dir could be added to git-real-dir/info/exclude.\nBut by that logic we could insist on adding .git to .git/info/exclude.\n\nThe argument about an unrelated repo in the working tree is irrelevant -\n.git wouldn't point to it, so there's nothings special about it.\n\nBut it's obviously not a big deal either way and I'm gonna drop it.\n"}]}