git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] let core.excludesfile default to ~/.gitignore.

From
Matthieu Moy <matthieu.moy@imag.fr>
Date
Nov 20, 2009, 13:23 UTC
Message-ID
<1258723430-31684-1-git-send-email-Matthieu.Moy@imag.fr>
It seems this is the value most users set, so let's make it the default.
Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
---
A funny experiment:

http://www.google.com/search?q=core.excludesfile+-%22~/.gitignore%22 Results 1 - 10 of about 3,890 for core.excludesfile -"~/.gitignore"

http://www.google.com/search?q=core.excludesfile+%22~/.gitignore%22 Results 1 - 10 of about 7,990 for core.excludesfile "~/.gitignore"

So, most of the time someone mentions core.excludesfile on the web, ~/.gitignore is mentionned right after.

I'd have expected a place near config.c to set the default value for any config variable, but I can't find such thing, so I guess the caller is the one that should set the default, which is what I do in the patch.

 Documentation/config.txt |    1 +
 dir.c                    |    9 ++++++++-
 2 files changed, 9 insertions(+), 1 deletions(-)
diff --git a/Documentation/config.txt b/Documentation/config.txt
index 39d1226..0c55e52 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -384,6 +384,7 @@ core.excludesfile::
 	of files which are not meant to be tracked.  "~/" is expanded
 	to the value of `$HOME` and "~user/" to the specified user's
 	home directory.  See linkgit:gitignore[5].
+	Default: ~/.gitignore.
 
 core.editor::
 	Commands such as `commit` and `tag` that lets you edit
diff --git a/dir.c b/dir.c
index d0999ba..dcea6ad 100644
--- a/dir.c
+++ b/dir.c
@@ -914,9 +914,16 @@ void setup_standard_excludes(struct dir_struct *dir)
 
 	dir->exclude_per_dir = ".gitignore";
 	path = git_path("info/exclude");
+	if (!excludes_file) {
+		const char *home = getenv("HOME");
+		char *user_gitignore = malloc(strlen(home) + strlen("/.gitignore") + 1);
+		strcpy(user_gitignore, home);
+		strcat(user_gitignore, "/.gitignore");
+		excludes_file = user_gitignore;
+	}
 	if (!access(path, R_OK))
 		add_excludes_from_file(dir, path);
-	if (excludes_file && !access(excludes_file, R_OK))
+	if (!access(excludes_file, R_OK))
 		add_excludes_from_file(dir, excludes_file);
 }
 
-- 
1.6.5.2.152.gbbe9e
Next: Stefan Naewe
Message 1 of 17 in “let core.excludesfile default to ~/.gitignore.”
  1. let core.excludesfile default to ~/.gitignore.Matthieu Moy, Nov 20, 2009
  2. Stefan NaeweNov 20, 2009
  3. David AguilarNov 20, 2009
  4. Let core.excludesfile default to ~/.gitexcludes.Matthieu Moy, Nov 21, 2009
  5. Let core.excludesfile default to ~/.gitexcludes.Matthieu Moy, Nov 26, 2009
  6. Michael J GruberNov 26, 2009
  7. Paolo BonziniNov 26, 2009
  8. Michael J GruberNov 26, 2009
  9. Bert WesargNov 26, 2009
  10. Michael J GruberNov 26, 2009
  11. David AguilarNov 26, 2009
  12. Junio C HamanoNov 26, 2009
  13. Nanako ShiraishiDec 30, 2009
  14. Matthieu MoyDec 30, 2009
  15. Junio C HamanoDec 30, 2009
  16. User-wide Git config directory (was Re: [PATCH v2] Let core.excludesfile default to ~/.gitexcludes.)Matthieu Moy, Jan 2, 2010
  17. Junio C HamanoNov 20, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.