{"thread":{"id":"36716","subject":"[PATCH] Add an explicit GIT_DIR to the list of excludes","startedAt":"2014-05-20T23:26:27Z","lastAt":"2014-05-20T23:26:27Z","messageCount":1,"participants":["Pasha Bolokhov"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"242341","messageId":"1400628387-9557-1-git-send-email-pasha.bolokhov@gmail.com","threadId":"36716","inReplyTo":null,"subject":"[PATCH] Add an explicit GIT_DIR to the list of excludes","fromName":"Pasha Bolokhov","fromEmail":"pasha.bolokhov@gmail.com","sentAt":"2014-05-20T23:26:27Z","receivedAt":"2014-05-20T23:26:27Z","isPatch":true,"sender":{"key":"pasha.bolokhov@gmail.com","avatar":null},"body":"When an explicit '--git-dir' option points to a directory inside\nthe work tree, git treats it as if it were any other directory.\nIn particular, 'git status' lists it as untracked, while 'git add -A'\nstages the metadata directory entirely\n\nAdd GIT_DIR to the list of excludes in setup_standard_excludes(),\nwhile checking that GIT_DIR is not just '.git', in which case it\nwould be ignored by default, and that GIT_DIR is inside GIT_WORK_TREE\n\nAlthough an analogous comparison of any given path against '.git'\nis done in treat_path(), this does not seem to be the right place\nto compare against GIT_DIR. Instead, the excludes provide an\neffective mechanism of ignoring a file/directory, and adding GIT_DIR\nas an exclude is equivalent of putting it into '.gitignore'. Function\nsetup_standard_excludes() was chosen because that is the place where\nthe excludes are initialized by the commands that are concerned about\nexcludes\n\nSigned-off-by: Pasha Bolokhov <pasha.bolokhov@gmail.com>\n---\n dir.c | 20 ++++++++++++++++++++\n 1 file changed, 20 insertions(+)\n\ndiff --git a/dir.c b/dir.c\nindex 98bb50f..07e36f3 100644\n--- a/dir.c\n+++ b/dir.c\n@@ -1588,6 +1588,26 @@ void setup_standard_excludes(struct dir_struct *dir)\n {\n \tconst char *path;\n \tchar *xdg_path;\n+\tconst char *gitdir = get_git_dir();\n+\n+\t/* Add git directory to the ignores first */\n+\tif (strcmp(gitdir, \".git\") != 0) { /* \"--git-dir\" has been given */\n+\t\tchar ngit[PATH_MAX + 1];\n+\n+\t\t/*\n+\t\t * See if GIT_DIR is inside the work tree; need to normalize\n+\t\t * 'gitdir' but 'get_git_work_tree()' always appears absolute\n+\t\t * and normalized\n+\t\t */\n+\t\tnormalize_path_copy(ngit, real_path(absolute_path(gitdir)));\n+\n+\t\tif (dir_inside_of(ngit, get_git_work_tree()) >= 0) {\n+\t\t\tstruct exclude_list *el = add_exclude_list(dir, EXC_CMDL,\n+\t\t\t\t\t\t\t\"--git-dir option\");\n+\n+\t\t\tadd_exclude(gitdir, \"\", 0, el, 0);\n+\t\t}\n+\t}\n \n \tdir->exclude_per_dir = \".gitignore\";\n \tpath = git_path(\"info/exclude\");\n-- \n1.9.1\n"}]}