{"thread":{"id":"41286","subject":"Gitignore file exceptions are not applied to untarcked files","startedAt":"2016-01-29T15:25:13Z","lastAt":"2016-01-29T20:54:30Z","messageCount":3,"participants":["Assen Totin","Junio C Hamano","Anatoly Borodin"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"277050","messageId":"CAMrYpX5n1LHBnr+bMhV=8Eu1K2npKctVZrHxJcStBhSVC70OBg@mail.gmail.com","threadId":"41286","inReplyTo":null,"subject":"Gitignore file exceptions are not applied to untarcked files","fromName":"Assen Totin","fromEmail":"assen.totin@gmail.com","sentAt":"2016-01-29T15:25:13Z","receivedAt":"2016-01-29T15:25:13Z","isPatch":false,"sender":{"key":"assen.totin@gmail.com","avatar":null},"body":"Hi,\n\nI'm not sure if the described issue is a bug or a feature; if it is the\nlatter, please, excuse the report.\n\nI'm dealing with git 1.7.12.4. If this has been addressed in the later\nissue, please, point me so.\n\nThe problem: I have a directory tree with lots of files and dirs, of which\nI only track certain files in subdirs of a specific subdir. It goes like\nthis:\n\n/untracted_file1\n/untracked_file2\n/untracked_dir1/...\n/untracked_dir2/...\n/tracked_dir/subdir1/config\n/tracked_dir/subdir1/another_untracked_file\n/tracked_dir/subdir2/config\n/tracked_dir/subdir2/another_untracked_file\n\nI'm only interested in /tracked_dir/.../config files. My .gitignore is as\nfollows:\n\n# Ignore everything first\n*\n# Do not ignore tracked files\n!/tracked_dir/*/config\n# Don't ignore .gitignore\n!.gitignore\n\nThis works fine until a new directory with a config file is created inside\n/tracked_dir:\n\n/tracked_dir/new_subdir/config\n\nThis config file is not seen by git at all (git status returns no changes\nto add), although it matches the exclusion pattern.\n\nWhile I can use various workarounds, I'm interested whether this actual\nphenomenon occurs - why does the exclusion pattern not match an untracked\nfile in untracked directory? Is it because the exclusion pattern is never\napplied to untracked files? Or is it because the directory new_subdir is\nitself untracked?\n\nWWell,\n\nAssen Totin\n"},{"id":"277055","messageId":"xmqqd1skjkyp.fsf@gitster.mtv.corp.google.com","threadId":"41286","inReplyTo":"CAMrYpX5n1LHBnr+bMhV=8Eu1K2npKctVZrHxJcStBhSVC70OBg@mail.gmail.com","subject":"Re: Gitignore file exceptions are not applied to untarcked files","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-01-29T18:31:58Z","receivedAt":"2016-01-29T18:31:58Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Assen Totin <assen.totin@gmail.com> writes:\n\n> I'm not sure if the described issue is a bug or a feature; if it is the\n> latter, please, excuse the report.\n>\n> I'm dealing with git 1.7.12.4. If this has been addressed in the later\n> issue, please, point me so.\n\nThat is a bit too ancient version, so I am not sure how it behaved\nback then.\n\n> I'm only interested in /tracked_dir/.../config files. My .gitignore is as\n> follows:\n>\n> # Ignore everything first\n> *\n> # Do not ignore tracked files\n> !/tracked_dir/*/config\n> # Don't ignore .gitignore\n> !.gitignore\n>\n> This works fine until a new directory with a config file is created inside\n> /tracked_dir:\n\nI am not sure if that is \"working fine\".  First, aren't these 'config'\nfiles tracked?  \"!/tracked_dir/*/config\" or whatever you have in the\ngitignore files have no effect on what is already tracked.\n\nThat is, if you replace your .gitignore with a single line,\n\n\t# ignore everything\n        *\n\nyour /tracked_dir/foo/config that is already in the index (i.e. \"git\nls-files tracked_dir/foo/config\" would show it) would not be ignored.\n\n> Is it because the exclusion pattern is never\n> applied to untracked files? Or is it because the directory new_subdir is\n> itself untracked?\n\nSo my suspicion is that (1) you do see tracked_dir/subdir1/config is\nnot ignored not because of any of your !tracked_dir/*/config lines\nbut because tracked_dir/subdir1/config is already in the index, and\n(2) your tracked_dir/new_subdir/config is shown as ignored because\nit is not tracked yet, and '*' tells Git that new_subdir is ignored.\n\nBy the way, this area did have a recent regression at v2.7.0, to\nwhich a fix is percolating down to the v2.7.x maintenance track.\n"},{"id":"277066","messageId":"n8gji4$bf1$1@ger.gmane.org","threadId":"41286","inReplyTo":"xmqqd1skjkyp.fsf@gitster.mtv.corp.google.com","subject":"Re: Gitignore file exceptions are not applied to untarcked files","fromName":"Anatoly Borodin","fromEmail":"anatoly.borodin@gmail.com","sentAt":"2016-01-29T20:54:30Z","receivedAt":"2016-01-29T20:54:30Z","isPatch":false,"sender":{"key":"anatoly.borodin@gmail.com","avatar":"https://gravatar.com/avatar/59f11f1f45cf5ebb7bcca8da94b43cfe5f596d91c0a3e27ad0d2a861cc2bbce7?d=mp&s=160"},"body":"Hi Junio,\n\n\nI've tested it with many older versions of git, as well as with the recent\nv2.7.0 - it seems like this feature has been never working properly.\n\nThe script https://gist.github.com/anatolyborodin/9c581b50c584534fff28\n\n#!/bin/sh\n\nset -e\n\n# a\n# b\n# c\n# D/a\n# D/b\n# D/c\n# E/F/a\n# E/F/b\n# E/F/c\n\nmkdir -p D E/F\ntouch a b c D/a D/b D/c E/F/a E/F/b E/F/c\n\necho && echo '.gitignore' && echo '----------'\necho '*\\n!b\\n!D/b\\n!/D/b\\n!/E/*/b' > .gitignore\ncat .gitignore\n\necho && echo 'With `--ignored`' && echo '----------'\ngit status --ignored\n\necho && echo 'Without `--ignored`' && echo '----------'\ngit status\n\n\nThe output:\n\n\n.gitignore\n----------\n*\n!b\n/D/b\n!/D/b\n!/E/*/b\n\nWith `--ignored`\n----------\nOn branch master\nYour branch is up-to-date with 'origin/master'.\nUntracked files:\n  (use \"git add <file>...\" to include in what will be committed)\n\n        b\n\nIgnored files:\n  (use \"git add -f <file>...\" to include in what will be committed)\n\n        .gitignore\n        D/\n        E/\n        a\n        c\n\nnothing added to commit but untracked files present (use \"git add\" to track)\n\nWithout `--ignored`\n----------\nOn branch master\nYour branch is up-to-date with 'origin/master'.\nUntracked files:\n  (use \"git add <file>...\" to include in what will be committed)\n\n        b\n\nnothing added to commit but untracked files present (use \"git add\" to track)\n\n\n\nAll files in the subdirectories are ignored, no matter what.\n\n\n-- \nMit freundlichen Grüßen,\nAnatoly Borodin\n"}]}