{"thread":{"id":"10290","subject":"[PATCH] Let users override name of per-directory ignore file","startedAt":"2007-10-15T12:30:35Z","lastAt":"2007-10-15T12:30:35Z","messageCount":1,"participants":["Andreas Ericsson"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"55856","messageId":"47135D6B.5070308@op5.se","threadId":"10290","inReplyTo":null,"subject":"[PATCH] Let users override name of per-directory ignore file","fromName":"Andreas Ericsson","fromEmail":"ae@op5.se","sentAt":"2007-10-15T12:30:35Z","receivedAt":"2007-10-15T12:30:35Z","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\nI'm in the unfortunate position of being forced to work on a large\namount of projects where the upstream repo is in either CVS or SVN,\nand fiddling with exclude-files gets more than just a little tedious.\nI've tested this patch lightly. git-status and git-add pick up the\noption. \"make test\" passes as well, and the patch is small enough to\nseem obviously correct, so I left it at that.\n\ngit-svn should probably set this option by default after a successful\nclone, and it has the smell of fruit so low-hanging it's practically\nalready dropped from the tree, but unfortunately my perl-fu is so weak\nI can't even find where to add it. Volunteers?\n\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 6b2fc82..267f93c 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.1155.gfe96ee-dirty\n"}]}