[PATCHv6 2/4] Let core.excludesfile default to $XDG_CONFIG_HOME/git/ignore

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: NGUYEN Huynh Khoi Nguyen <nguyenhu@xxxxxxxxxxxxxx>

If core.excludesfile is not defined, its default value will be
$XDG_CONFIG_HOME/git/ignore in order to follow XDG specification. If
$XDG_CONFIG_HOME is either not set or emty, $HOME/.config/git/ignore
will be used.

Signed-off-by: Huynh Khoi Nguyen NGUYEN <Huynh-Khoi-Nguyen.Nguyen@xxxxxxxxxxxxxxx>
Signed-off-by: Valentin Duperray <Valentin.Duperray@xxxxxxxxxxxxxxx>
Signed-off-by: Franck Jonas <Franck.Jonas@xxxxxxxxxxxxxxx>
Signed-off-by: Lucien Kong <Lucien.Kong@xxxxxxxxxxxxxxx>
Signed-off-by: Thomas Nguy <Thomas.Nguy@xxxxxxxxxxxxxxx>
Signed-off-by: Matthieu Moy <Matthieu.Moy@xxxxxxxxxxxxxxx>
---
 Documentation/config.txt    |    4 +++-
 Documentation/gitignore.txt |    4 +++-
 dir.c                       |    7 ++++++-
 t/t1306-xdg-files.sh        |   40 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 52 insertions(+), 3 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 915cb5a..509bf25 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -483,7 +483,9 @@ core.excludesfile::
 	'.git/info/exclude', git looks into this file for patterns
 	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].
+	home directory. Its default value is $XDG_CONFIG_HOME/git/ignore.
+	If $XDG_CONFIG_HOME is either not set or empty, $HOME/.config/git/ignore
+	will be used. See linkgit:gitignore[5].
 
 core.askpass::
 	Some commands (e.g. svn and http interfaces) that interactively
diff --git a/Documentation/gitignore.txt b/Documentation/gitignore.txt
index 2e7328b..a5c9b93 100644
--- a/Documentation/gitignore.txt
+++ b/Documentation/gitignore.txt
@@ -50,7 +50,9 @@ the repository but are specific to one user's workflow) should go into
 the `$GIT_DIR/info/exclude` file.  Patterns which a user wants git to
 ignore in all situations (e.g., backup or temporary files generated by
 the user's editor of choice) generally go into a file specified by
-`core.excludesfile` in the user's `~/.gitconfig`.
+`core.excludesfile` in the user's `~/.gitconfig`. Its default value is
+$XDG_CONFIG_HOME/git/ignore. If $XDG_CONFIG_HOME is either not set or empty,
+$HOME/.config/git/ignore will be used.
 
 The underlying git plumbing tools, such as
 'git ls-files' and 'git read-tree', read
diff --git a/dir.c b/dir.c
index ed1510f..8c6f47f 100644
--- a/dir.c
+++ b/dir.c
@@ -1234,12 +1234,17 @@ int remove_dir_recursively(struct strbuf *path, int flag)
 void setup_standard_excludes(struct dir_struct *dir)
 {
 	const char *path;
+	char *xdg_path;
 
 	dir->exclude_per_dir = ".gitignore";
 	path = git_path("info/exclude");
+	if (!excludes_file) {
+		home_config_paths(NULL, &xdg_path, "ignore");
+		excludes_file = xdg_path;
+	}
 	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);
 }
 
diff --git a/t/t1306-xdg-files.sh b/t/t1306-xdg-files.sh
index 5b971d9..873bbcf 100755
--- a/t/t1306-xdg-files.sh
+++ b/t/t1306-xdg-files.sh
@@ -67,4 +67,44 @@ test_expect_success 'read with --list: xdg file exists and ~/.gitconfig exists'
 '
 
 
+test_expect_success 'Exclusion of a file in the XDG ignore file' '
+	test_when_finished "rm -rf git" &&
+	git init git &&
+	(
+		cd git &&
+		echo foo >to_be_excluded &&
+		mkdir -p "$HOME"/.config/git/ &&
+		echo to_be_excluded >"$HOME"/.config/git/ignore &&
+		test_must_fail git add to_be_excluded
+	)
+'
+
+
+test_expect_success 'Exclusion in both XDG and local ignore files' '
+	test_when_finished "rm -rf git" &&
+	git init git &&
+	(
+		cd git &&
+		echo foo >to_be_excluded &&
+		echo to_be_excluded >"$HOME"/.config/git/ignore &&
+		echo to_be_excluded >.gitignore &&
+		test_must_fail git add to_be_excluded
+	)
+'
+
+
+test_expect_success 'Exclusion in a non-XDG global ignore file' '
+	test_when_finished "rm -rf git" &&
+	git init git &&
+	(
+		cd git &&
+		echo foo >to_be_excluded &&
+		echo >"$HOME"/.config/git/ignore &&
+		echo to_be_excluded >"$HOME"/my_gitignore &&
+		git config core.excludesfile "$HOME"/my_gitignore &&
+		test_must_fail git add to_be_excluded
+	)
+'
+
+
 test_done
-- 
1.7.8

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]