{"thread":{"id":"10422","subject":"[PATCH] Let users override name of per-directory ignore file","startedAt":"2007-10-15T12:09:32Z","lastAt":"2007-10-22T11:18:14Z","messageCount":3,"participants":["Andreas Ericsson","Karl Hasselström"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"56836","messageId":"20071021144542.8855A5BB85@nox.op5.se","threadId":"10422","inReplyTo":null,"subject":"[PATCH] Let users override name of per-directory ignore file","fromName":"Andreas Ericsson","fromEmail":"ae@op5.se","sentAt":"2007-10-15T12:09:32Z","receivedAt":"2007-10-15T12:09:32Z","isPatch":true,"sender":{"key":"ae@op5.se","avatar":"https://gravatar.com/avatar/426e89595c75a8f5252dd0c989e5fabe5bcac616e68557427ad9aef6b0ca342a?d=mp&s=160"},"body":"When collaborating with projects managed by some other\nscm, it often makes sense to have git read that other\nscm's ignore-files. This patch lets git do just that, if\nthe user only tells it the name of the per-directory\nignore file by specifying the newly introduced git config\noption 'core.ignorefile'.\n\nTheoretically, this could cause problems when projects get\nported from some other scm to git, but in practice that\nis a moot point, as such changes are always followed by a\nflagday anyway.\n\nSigned-off-by: Andreas Ericsson <ae@op5.se>\n---\n Documentation/config.txt    |   10 ++++++++++\n Documentation/gitignore.txt |    5 +++++\n builtin-add.c               |   11 +++++++++--\n wt-status.c                 |    9 ++++++++-\n 4 files changed, 32 insertions(+), 3 deletions(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex edf50cd..5170e27 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -275,6 +275,16 @@ You probably do not need to adjust this value.\n +\n Common unit suffixes of 'k', 'm', or 'g' are supported.\n \n+core.ignorefile::\n+\tTells git to use a different file for per-directory ignores.\n+\tThis is useful when one wishes to use git for a project\n+\twhen the upstream repository is managed by some other SCM\n+\twhose ignore-file formats are the same as that of git.\n+\tFor example, setting core.ignorefile to .svnignore in\n+\trepos where one interacts with the upstream project repo\n+\tusing gitlink:git-svn[1] will make a both SVN users and\n+\tyour own repo ignore the same files.\n+\n core.excludesfile::\n \tIn addition to '.gitignore' (per-directory) and\n \t'.git/info/exclude', git looks into this file for patterns\ndiff --git a/Documentation/gitignore.txt b/Documentation/gitignore.txt\nindex e8b8581..f82eac6 100644\n--- a/Documentation/gitignore.txt\n+++ b/Documentation/gitignore.txt\n@@ -32,6 +32,11 @@ precedence, the last matching pattern decides the outcome):\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 `.gitignore` file can be changed by setting\n+   the configuration variable 'core.ignorefile'. This is useful\n+   when using git for projects where upstream is using some other\n+   SCM. For example, setting 'core.ignorefile' to `.cvsignore`\n+   will make git ignore the same files CVS would.\n \n  * Patterns read from `$GIT_DIR/info/exclude`.\n \ndiff --git a/builtin-add.c b/builtin-add.c\nindex 966e145..c785d99 100644\n--- a/builtin-add.c\n+++ b/builtin-add.c\n@@ -19,6 +19,7 @@ static const char builtin_add_usage[] =\n \n static int take_worktree_changes;\n static const char *excludes_file;\n+static const char *ignore_file = \".gitignore\";\n \n static void prune_directory(struct dir_struct *dir, const char **pathspec, int prefix)\n {\n@@ -57,7 +58,7 @@ static void fill_directory(struct dir_struct *dir, const char **pathspec,\n \tmemset(dir, 0, sizeof(*dir));\n \tif (!ignored_too) {\n \t\tdir->collect_ignored = 1;\n-\t\tdir->exclude_per_dir = \".gitignore\";\n+\t\tdir->exclude_per_dir = ignore_file;\n \t\tpath = git_path(\"info/exclude\");\n \t\tif (!access(path, R_OK))\n \t\t\tadd_excludes_from_file(dir, path);\n@@ -144,6 +145,12 @@ static int git_add_config(const char *var, const char *value)\n \t\texcludes_file = xstrdup(value);\n \t\treturn 0;\n \t}\n+\tif (!strcmp(var, \"core.ignorefile\")) {\n+\t\tif (!value)\n+\t\t\tdie(\"core.ignorefile without value\");\n+\t\tignore_file = xstrdup(value);\n+\t\treturn 0;\n+\t}\n \n \treturn git_default_config(var, value);\n }\n@@ -158,7 +165,7 @@ int interactive_add(void)\n static struct lock_file lock_file;\n \n static const char ignore_error[] =\n-\"The following paths are ignored by one of your .gitignore files:\\n\";\n+\"The following paths are ignored:\\n\";\n \n int cmd_add(int argc, const char **argv, const char *prefix)\n {\ndiff --git a/wt-status.c b/wt-status.c\nindex 03b5ec4..103aefe 100644\n--- a/wt-status.c\n+++ b/wt-status.c\n@@ -23,6 +23,7 @@ static const char use_add_rm_msg[] =\n static const char use_add_to_include_msg[] =\n \"use \\\"git add <file>...\\\" to include in what will be committed\";\n static const char *excludes_file;\n+static const char *ignore_file = \".gitignore\";\n \n static int parse_status_slot(const char *var, int offset)\n {\n@@ -257,7 +258,7 @@ static void wt_status_print_untracked(struct wt_status *s)\n \n \tmemset(&dir, 0, sizeof(dir));\n \n-\tdir.exclude_per_dir = \".gitignore\";\n+\tdir.exclude_per_dir = ignore_file;\n \tif (!s->untracked) {\n \t\tdir.show_other_directories = 1;\n \t\tdir.hide_empty_directories = 1;\n@@ -370,5 +371,11 @@ int git_status_config(const char *k, const char *v)\n \t\texcludes_file = xstrdup(v);\n \t\treturn 0;\n \t}\n+\tif (!strcmp(k, \"core.ignorefile\")) {\n+\t\tif (!v)\n+\t\t\tdie(\"core.ignorefile without value\");\n+\t\tignore_file = xstrdup(v);\n+\t\treturn 0;\n+\t}\n \treturn git_default_config(k, v);\n }\n-- \n1.5.3.4.1273.g725c19\n"},{"id":"56853","messageId":"20071022105029.GB31862@diana.vm.bytemark.co.uk","threadId":"10422","inReplyTo":"20071021144542.8855A5BB85@nox.op5.se","subject":"Re: [PATCH] Let users override name of per-directory ignore file","fromName":"Karl Hasselström","fromEmail":"kha@treskal.com","sentAt":"2007-10-22T10:50:29Z","receivedAt":"2007-10-22T10:50:29Z","isPatch":true,"sender":{"key":"kha@treskal.com","avatar":"https://gravatar.com/avatar/f0120c734b5279b345075a28521e1ac66acb20c9913ffe9bf6ae97e53f7f3f13?d=mp&s=160"},"body":"On 2007-10-15 14:09:32 +0200, Andreas Ericsson wrote:\n\n> When collaborating with projects managed by some other scm, it often\n> makes sense to have git read that other scm's ignore-files. This\n> patch lets git do just that, if the user only tells it the name of\n> the per-directory ignore file by specifying the newly introduced git\n> config option 'core.ignorefile'.\n\n> +\tFor example, setting core.ignorefile to .svnignore in\n> +\trepos where one interacts with the upstream project repo\n> +\tusing gitlink:git-svn[1] will make a both SVN users and\n> +\tyour own repo ignore the same files.\n\n> +   The name of the `.gitignore` file can be changed by setting\n> +   the configuration variable 'core.ignorefile'. This is useful\n> +   when using git for projects where upstream is using some other\n> +   SCM. For example, setting 'core.ignorefile' to `.cvsignore`\n> +   will make git ignore the same files CVS would.\n\nI agree with what you're trying to do, but you're ignoring the fact\nthat Subversion's ignore patterns (and possibly cvs's too -- I haven't\nchecked) are not recursive, while the patterns in .gitignore are\nrecursive per default. So using ignore patterns directly from\nSubversion ignores more files under git than the same patterns did\nunder Subversion.\n\nOne possible way to solve that would be to optionally have\nnon-recursive per-directory ignore files. I haven't looked at how this\nis implemented, though, so I don't know if it's a good suggestion or\nnot.\n\n-- \nKarl Hasselström, kha@treskal.com\n      www.treskal.com/kalle\n"},{"id":"56857","messageId":"471C86F6.6010705@op5.se","threadId":"10422","inReplyTo":"20071022105029.GB31862@diana.vm.bytemark.co.uk","subject":"Re: [PATCH] Let users override name of per-directory ignore file","fromName":"Andreas Ericsson","fromEmail":"ae@op5.se","sentAt":"2007-10-22T11:18:14Z","receivedAt":"2007-10-22T11:18:14Z","isPatch":true,"sender":{"key":"ae@op5.se","avatar":"https://gravatar.com/avatar/426e89595c75a8f5252dd0c989e5fabe5bcac616e68557427ad9aef6b0ca342a?d=mp&s=160"},"body":"Karl Hasselström wrote:\n> On 2007-10-15 14:09:32 +0200, Andreas Ericsson wrote:\n> \n>> When collaborating with projects managed by some other scm, it often\n>> makes sense to have git read that other scm's ignore-files. This\n>> patch lets git do just that, if the user only tells it the name of\n>> the per-directory ignore file by specifying the newly introduced git\n>> config option 'core.ignorefile'.\n> \n>> +\tFor example, setting core.ignorefile to .svnignore in\n>> +\trepos where one interacts with the upstream project repo\n>> +\tusing gitlink:git-svn[1] will make a both SVN users and\n>> +\tyour own repo ignore the same files.\n> \n>> +   The name of the `.gitignore` file can be changed by setting\n>> +   the configuration variable 'core.ignorefile'. This is useful\n>> +   when using git for projects where upstream is using some other\n>> +   SCM. For example, setting 'core.ignorefile' to `.cvsignore`\n>> +   will make git ignore the same files CVS would.\n> \n> I agree with what you're trying to do, but you're ignoring the fact\n> that Subversion's ignore patterns (and possibly cvs's too -- I haven't\n> checked) are not recursive, while the patterns in .gitignore are\n> recursive per default. So using ignore patterns directly from\n> Subversion ignores more files under git than the same patterns did\n> under Subversion.\n> \n\nYes, I just got bitten by this. The top-level .cvsignore file ignores \nMakefile (since it's generated from ./configure), but Makefile exists in \nseveral subdirectories where it's *not* generated, but adding !Makefile \nto all those places doesn't sit too well with some of the project \nmaintainers, and cvs doesn't grok /Makefile to mean \"toplevel Makefile\" \n(and it shouldn't since it has no notion of recursive ignores).\n\n> One possible way to solve that would be to optionally have\n> non-recursive per-directory ignore files. I haven't looked at how this\n> is implemented, though, so I don't know if it's a good suggestion or\n> not.\n> \n\nI'll have a look at it. Thanks for the review.\n\n-- \nAndreas Ericsson                   andreas.ericsson@op5.se\nOP5 AB                             www.op5.se\nTel: +46 8-230225                  Fax: +46 8-230231\n"}]}