Let core.excludesfile default to $XDG_CONFIG_HOME/git/ignore
To use the feature of core.excludesfile, the user needs: 1. to create such a file, 2. and add configuration variable to point at it. Instead, we can make this a one-step process by choosing a default value which points to a filename in the user's $HOME, that is unlikely to already exist on the system, and only use the presence of the file as a cue that the user wants to use that feature. And we use "${XDG_CONFIG_HOME:-$HOME/.config/git}/ignore" as such a file, in the same directory as the newly added configuration file ("${XDG_CONFIG_HOME:-$HOME/.config/git}/config). The use of this directory is in line with XDG specification as a location to store such application specific files. Signed-off-by: Huynh Khoi Nguyen Nguyen <Huynh-Khoi-Nguyen.Nguyen@ensimag.imag.fr> Signed-off-by: Valentin Duperray <Valentin.Duperray@ensimag.imag.fr> Signed-off-by: Franck Jonas <Franck.Jonas@ensimag.imag.fr> Signed-off-by: Lucien Kong <Lucien.Kong@ensimag.imag.fr> Signed-off-by: Thomas Nguy <Thomas.Nguy@ensimag.imag.fr> Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
21cf322791
commit
dc79687e0b
@ -483,7 +483,9 @@ core.excludesfile::
|
|||||||
'.git/info/exclude', git looks into this file for patterns
|
'.git/info/exclude', git looks into this file for patterns
|
||||||
of files which are not meant to be tracked. "`~/`" is expanded
|
of files which are not meant to be tracked. "`~/`" is expanded
|
||||||
to the value of `$HOME` and "`~user/`" to the specified user's
|
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
|
||||||
|
is used instead. See linkgit:gitignore[5].
|
||||||
|
|
||||||
core.askpass::
|
core.askpass::
|
||||||
Some commands (e.g. svn and http interfaces) that interactively
|
Some commands (e.g. svn and http interfaces) that interactively
|
||||||
|
@ -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
|
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
|
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
|
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 is used instead.
|
||||||
|
|
||||||
The underlying git plumbing tools, such as
|
The underlying git plumbing tools, such as
|
||||||
'git ls-files' and 'git read-tree', read
|
'git ls-files' and 'git read-tree', read
|
||||||
|
7
dir.c
7
dir.c
@ -1292,12 +1292,17 @@ int remove_dir_recursively(struct strbuf *path, int flag)
|
|||||||
void setup_standard_excludes(struct dir_struct *dir)
|
void setup_standard_excludes(struct dir_struct *dir)
|
||||||
{
|
{
|
||||||
const char *path;
|
const char *path;
|
||||||
|
char *xdg_path;
|
||||||
|
|
||||||
dir->exclude_per_dir = ".gitignore";
|
dir->exclude_per_dir = ".gitignore";
|
||||||
path = git_path("info/exclude");
|
path = git_path("info/exclude");
|
||||||
|
if (!excludes_file) {
|
||||||
|
home_config_paths(NULL, &xdg_path, "ignore");
|
||||||
|
excludes_file = xdg_path;
|
||||||
|
}
|
||||||
if (!access(path, R_OK))
|
if (!access(path, R_OK))
|
||||||
add_excludes_from_file(dir, path);
|
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);
|
add_excludes_from_file(dir, excludes_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,4 +67,33 @@ test_expect_success 'read with --list: xdg file exists and ~/.gitconfig exists'
|
|||||||
'
|
'
|
||||||
|
|
||||||
|
|
||||||
|
test_expect_success 'Setup' '
|
||||||
|
git init git &&
|
||||||
|
cd git &&
|
||||||
|
echo foo >to_be_excluded
|
||||||
|
'
|
||||||
|
|
||||||
|
|
||||||
|
test_expect_success 'Exclusion of a file in the XDG ignore file' '
|
||||||
|
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' '
|
||||||
|
echo to_be_excluded >.gitignore &&
|
||||||
|
test_must_fail git add to_be_excluded
|
||||||
|
'
|
||||||
|
|
||||||
|
|
||||||
|
test_expect_success 'Exclusion in a non-XDG global ignore file' '
|
||||||
|
rm .gitignore &&
|
||||||
|
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
|
test_done
|
||||||
|
Loading…
Reference in New Issue
Block a user