{"thread":{"id":"11846","subject":"[PATCH] Add \"core.excludesperdirfile\" configuration variable","startedAt":"2008-02-03T06:56:31Z","lastAt":"2008-02-03T06:56:31Z","messageCount":1,"participants":["Elvis Pranskevichus"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"67191","messageId":"1202021791-5469-1-git-send-email-el@prans.net","threadId":"11846","inReplyTo":null,"subject":"[PATCH] Add \"core.excludesperdirfile\" configuration variable","fromName":"Elvis Pranskevichus","fromEmail":"el@prans.net","sentAt":"2008-02-03T06:56:31Z","receivedAt":"2008-02-03T06:56:31Z","isPatch":true,"sender":{"key":"el@prans.net","avatar":null},"body":"Make it possible to override the \".gitignore\" file name\nwith \"core.excludesperdirfile\" configuration variable.\n\nThis is particularly useful for repos that are mirrored\nfrom another SCM which uses similar syntax, but different\nname, for the exclusion patterns files. The most common\nexample is CVS with its .cvsignore.\n\nThe change is fairly trivial, since the .gitignore name\nwas hardcoded only in a few places on porcelain level.\n\nSigned-off-by: Elvis Pranskevichus <el@prans.net>\n---\n Documentation/config.txt           |   12 ++++++++----\n Documentation/gitignore.txt        |   12 +++++++-----\n cache.h                            |    1 +\n config.c                           |    7 +++++++\n contrib/examples/git-clean.sh      |    9 +++++++--\n dir.c                              |    4 +++-\n environment.c                      |    1 +\n git-checkout.sh                    |    8 +++++++-\n git-merge.sh                       |    7 ++++++-\n t/t3001-ls-files-others-exclude.sh |   19 +++++++++++++++++++\n t/t7300-clean.sh                   |   15 +++++++++++++++\n 11 files changed, 81 insertions(+), 14 deletions(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex 4e222f1..b076bea 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -277,11 +277,15 @@ You probably do not need to adjust this value.\n +\n Common unit suffixes of 'k', 'm', or 'g' are supported.\n \n+core.excludesperdirfile::\n+\tThe name of the per-directory file containing patterns\n+\tof files which are not meant to be tracked. The default\n+\tis \".gitignore\".  See linkgit:gitignore[5].\n+\n core.excludesfile::\n-\tIn addition to '.gitignore' (per-directory) and\n-\t'.git/info/exclude', git looks into this file for patterns\n-\tof files which are not meant to be tracked.  See\n-\tlinkgit:gitignore[5].\n+\tThe name of the file containing exclusion patterns for\n+\tgit to take into consideration in addition to per-directory\n+\texcludes files and '.git/info/exclude'.  See linkgit:gitignore[5].\n \n core.editor::\n \tCommands such as `commit` and `tag` that lets you edit\ndiff --git a/Documentation/gitignore.txt b/Documentation/gitignore.txt\nindex 08373f5..533be1f 100644\n--- a/Documentation/gitignore.txt\n+++ b/Documentation/gitignore.txt\n@@ -24,14 +24,16 @@ precedence, the last matching pattern decides the outcome):\n  * Patterns read from the command line for those commands that support\n    them.\n \n- * Patterns read from a `.gitignore` file in the same directory\n+ * Patterns read from a special file in the same directory\n    as the path, or in any parent directory, with patterns in the\n    higher level files (up to the root) being overridden by those in\n    lower level files down to the directory containing the file.\n-   These patterns match relative to the location of the\n-   `.gitignore` file.  A project normally includes such\n-   `.gitignore` files in its repository, containing patterns for\n-   files generated as part of the project build.\n+   The name of the files containing patterns is `.gitignore` by default,\n+   which can be overridden by the `core.excludesPerDirFile` configuration\n+   variable.\n+   The patterns match relative to the location of the holding file.\n+   A project normally includes such `.gitignore` files in its repository,\n+   containing patterns for files generated as part of the project build.\n \n  * Patterns read from `$GIT_DIR/info/exclude`.\n \ndiff --git a/cache.h b/cache.h\nindex 549f4bb..33cb1ff 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -614,6 +614,7 @@ extern int pager_use_color;\n \n extern char *editor_program;\n extern char *excludes_file;\n+extern char *excludes_per_dir_file;\n \n /* base85 */\n int decode_85(char *dst, const char *line, int linelen);\ndiff --git a/config.c b/config.c\nindex 526a3f4..be1f80b 100644\n--- a/config.c\n+++ b/config.c\n@@ -450,6 +450,13 @@ int git_default_config(const char *var, const char *value)\n \t\treturn 0;\n \t}\n \n+\tif (!strcmp(var, \"core.excludesperdirfile\")) {\n+\t\tif (!value)\n+\t\t\tdie(\"core.excludesperdirfile without value\");\n+\t\texcludes_per_dir_file = xstrdup(value);\n+\t\treturn 0;\n+\t}\n+\n \tif (!strcmp(var, \"core.whitespace\")) {\n \t\twhitespace_rule_cfg = parse_whitespace_rule(value);\n \t\treturn 0;\ndiff --git a/contrib/examples/git-clean.sh b/contrib/examples/git-clean.sh\nindex 01c95e9..3e2e936 100755\n--- a/contrib/examples/git-clean.sh\n+++ b/contrib/examples/git-clean.sh\n@@ -86,8 +86,7 @@ if [ \"$ignored,$ignoredonly\" = \"1,1\" ]; then\n fi\n \n if [ -z \"$ignored\" ]; then\n-\texcl=\"--exclude-per-directory=.gitignore\"\n-\texcl_info= excludes_file=\n+\texcl_info= excludes_file= excludes_per_dir_file=\n \tif [ -f \"$GIT_DIR/info/exclude\" ]; then\n \t\texcl_info=\"--exclude-from=$GIT_DIR/info/exclude\"\n \tfi\n@@ -95,6 +94,12 @@ if [ -z \"$ignored\" ]; then\n \tthen\n \t\texcludes_file=\"--exclude-from=$cfg_excl\"\n \tfi\n+\texcludes_per_dir_file=$(git config core.excludesperdirfile)\n+\tif [ -z \"$excludes_per_dir_file\" ];\n+\tthen\n+\t\texcludes_per_dir_file=\".gitignore\"\n+\tfi\n+\texcl=\"--exclude-per-directory=$excludes_per_dir_file\"\n \tif [ \"$ignoredonly\" ]; then\n \t\texcl=\"$excl --ignored\"\n \tfi\ndiff --git a/dir.c b/dir.c\nindex 3e345c2..e8c1ea7 100644\n--- a/dir.c\n+++ b/dir.c\n@@ -786,7 +786,9 @@ void setup_standard_excludes(struct dir_struct *dir)\n {\n \tconst char *path;\n \n-\tdir->exclude_per_dir = \".gitignore\";\n+\tdir->exclude_per_dir = excludes_per_dir_file ?\n+\t\t\t\texcludes_per_dir_file : \".gitignore\";\n+\n \tpath = git_path(\"info/exclude\");\n \tif (!access(path, R_OK))\n \t\tadd_excludes_from_file(dir, path);\ndiff --git a/environment.c b/environment.c\nindex 18a1c4e..ee3871f 100644\n--- a/environment.c\n+++ b/environment.c\n@@ -34,6 +34,7 @@ char *pager_program;\n int pager_use_color = 1;\n char *editor_program;\n char *excludes_file;\n+char *excludes_per_dir_file;\n int auto_crlf = 0;\t/* 1: both ways, -1: only when adding git objects */\n unsigned whitespace_rule_cfg = WS_DEFAULT_RULE;\n \ndiff --git a/git-checkout.sh b/git-checkout.sh\nindex bd74d70..ac56085 100755\n--- a/git-checkout.sh\n+++ b/git-checkout.sh\n@@ -210,7 +210,13 @@ then\n     git read-tree $v --reset -u $new\n else\n     git update-index --refresh >/dev/null\n-    merge_error=$(git read-tree -m -u --exclude-per-directory=.gitignore $old $new 2>&1) || (\n+    excl_per_dir_file=$(git config core.excludesperdirfile)\n+    if [ -z \"$excl_per_dir_file\" ];\n+    then\n+        excl_per_dir_file=\".gitignore\"\n+    fi\n+\n+    merge_error=$(git read-tree -m -u --exclude-per-directory=$excl_per_dir_file $old $new 2>&1) || (\n \tcase \"$merge\" in\n \t'')\n \t\techo >&2 \"$merge_error\"\ndiff --git a/git-merge.sh b/git-merge.sh\nindex 1c123a3..30b5f0d 100755\n--- a/git-merge.sh\n+++ b/git-merge.sh\n@@ -348,8 +348,13 @@ t,1,\"$head\",*)\n \tthen\n \t\tmsg=\"$msg (no commit created; -m option ignored)\"\n \tfi\n+\texcl_per_dir_file=$(git config core.excludesperdirfile)\n+\tif [ -z \"$excl_per_dir_file\" ];\n+\tthen\n+\t\texcl_per_dir_file=\".gitignore\"\n+\tfi\n \tnew_head=$(git rev-parse --verify \"$1^0\") &&\n-\tgit read-tree -v -m -u --exclude-per-directory=.gitignore $head \"$new_head\" &&\n+\tgit read-tree -v -m -u --exclude-per-directory=$excl_per_dir_file $head \"$new_head\" &&\n \tfinish \"$new_head\" \"$msg\" || exit\n \tdropsave\n \texit 0\ndiff --git a/t/t3001-ls-files-others-exclude.sh b/t/t3001-ls-files-others-exclude.sh\nindex e25b255..3c99a60 100755\n--- a/t/t3001-ls-files-others-exclude.sh\n+++ b/t/t3001-ls-files-others-exclude.sh\n@@ -99,4 +99,23 @@ EOF\n test_expect_success 'git-status honours core.excludesfile' \\\n \t'diff -u expect output'\n \n+\n+git config core.excludesperdirfile .myignore\n+cat > .myignore << EOF\n+output\n+!/*.[47]\n+EOF\n+\n+cat > expect << EOF\n+#\t.gitignore\n+#\t.myignore\n+#\ta.4\n+#\ta.7\n+#\tone/\n+EOF\n+\n+test_expect_success 'git status honours core.excludesperdirfile' \\\n+\t'git status | grep \"^#\t\" > output &&\n+\t git diff expect output'\n+\n test_done\ndiff --git a/t/t7300-clean.sh b/t/t7300-clean.sh\nindex dfd1188..500abed 100755\n--- a/t/t7300-clean.sh\n+++ b/t/t7300-clean.sh\n@@ -316,4 +316,19 @@ test_expect_success 'core.excludesfile' '\n \n '\n \n+test_expect_success 'core.excludesperdirfile' '\n+\n+\tmkdir -p build docs src &&\n+\ttouch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&\n+\tgit config core.excludesperdirfile .myignore &&\n+\techo a.out >.myignore &&\n+\techo lib.so >build/.myignore &&\n+\tgit-clean -f &&\n+\ttest ! -f src/part3.c &&\n+\ttest ! -f obj.o &&\n+\ttest -f build/lib.so &&\n+\ttest -f a.out\n+\n+'\n+\n test_done\n-- \n1.5.4.GIT\n"}]}