Add "core.excludesperdirfile" configuration variable
PATCH 1/1 Add "core.excludesperdirfile" configuration variable
Make it possible to override the ".gitignore" file name with "core.excludesperdirfile" configuration variable.
This is particularly useful for repos that are mirrored from another SCM which uses similar syntax, but different name, for the exclusion patterns files. The most common example is CVS with its .cvsignore.
The change is fairly trivial, since the .gitignore name was hardcoded only in a few places on porcelain level.
Signed-off-by Elvis Pranskevichus <[email protected]>
--- Documentation/config.txt | 12 ++++++++---- Documentation/gitignore.txt | 12 +++++++----- cache.h | 1 + config.c | 7 +++++++ contrib/examples/git-clean.sh | 9 +++++++-- dir.c | 4 +++- environment.c | 1 + git-checkout.sh | 8 +++++++- git-merge.sh | 7 ++++++- t/t3001-ls-files-others-exclude.sh | 19 +++++++++++++++++++ t/t7300-clean.sh | 15 +++++++++++++++ 11 files changed, 81 insertions(+), 14 deletions(-)
Documentation/config.txt +8 -4
@@ -277,11 +277,15 @@ You probably do not need to adjust this value. + Common unit suffixes of 'k', 'm', or 'g' are supported. +core.excludesperdirfile:: + The name of the per-directory file containing patterns + of files which are not meant to be tracked. The default + is ".gitignore". See linkgit:gitignore[5]. + core.excludesfile:: - In addition to '.gitignore' (per-directory) and - '.git/info/exclude', git looks into this file for patterns - of files which are not meant to be tracked. See - linkgit:gitignore[5]. + The name of the file containing exclusion patterns for + git to take into consideration in addition to per-directory + excludes files and '.git/info/exclude'. See linkgit:gitignore[5]. core.editor:: Commands such as `commit` and `tag` that lets you edit
Documentation/gitignore.txt +7 -5
@@ -24,14 +24,16 @@ precedence, the last matching pattern decides the outcome): * Patterns read from the command line for those commands that support them. - * Patterns read from a `.gitignore` file in the same directory + * Patterns read from a special file in the same directory as the path, or in any parent directory, with patterns in the higher level files (up to the root) being overridden by those in lower level files down to the directory containing the file. - These patterns match relative to the location of the - `.gitignore` file. A project normally includes such - `.gitignore` files in its repository, containing patterns for - files generated as part of the project build. + The name of the files containing patterns is `.gitignore` by default, + which can be overridden by the `core.excludesPerDirFile` configuration + variable. + The patterns match relative to the location of the holding file. + A project normally includes such `.gitignore` files in its repository, + containing patterns for files generated as part of the project build. * Patterns read from `$GIT_DIR/info/exclude`.
cache.h +1 -0
@@ -614,6 +614,7 @@ extern int pager_use_color;extern char *editor_program;extern char *excludes_file; +extern char *excludes_per_dir_file;/* base85 */ int decode_85 (char *dst,const char *line,int linelen);
config.c +7 -0
@@ -450,6 +450,13 @@ int git_default_config(const char *var, const char *value)return 0 ; } +if (!strcmp (var,"core.excludesperdirfile" )) { +if (!value) +die ("core.excludesperdirfile without value" ); + excludes_per_dir_file =xstrdup (value); +return 0 ; + } +if (!strcmp (var,"core.whitespace" )) { whitespace_rule_cfg =parse_whitespace_rule (value);return 0 ;
contrib/examples/git-clean.sh +7 -2
@@ -86,8 +86,7 @@ if [ "$ignored,$ignoredonly" = "1,1" ]; then fi if [ -z "$ignored" ]; then - excl="--exclude-per-directory=.gitignore" - excl_info= excludes_file= + excl_info= excludes_file= excludes_per_dir_file= if [ -f "$GIT_DIR/info/exclude" ]; then excl_info="--exclude-from=$GIT_DIR/info/exclude" fi
@@ -95,6 +94,12 @@ if [ -z "$ignored" ]; then then excludes_file="--exclude-from=$cfg_excl" fi + excludes_per_dir_file=$(git config core.excludesperdirfile) + if [ -z "$excludes_per_dir_file" ]; + then + excludes_per_dir_file=".gitignore" + fi + excl="--exclude-per-directory=$excludes_per_dir_file" if [ "$ignoredonly" ]; then excl="$excl --ignored" fi
dir.c +3 -1
@@ -786,7 +786,9 @@ void setup_standard_excludes(struct dir_struct *dir) {const char *path; - dir->exclude_per_dir =".gitignore" ; + dir->exclude_per_dir = excludes_per_dir_file ? + excludes_per_dir_file :".gitignore" ; + path =git_path ("info/exclude" );if (!access (path,R_OK ))add_excludes_from_file (dir, path);
environment.c +1 -0
@@ -34,6 +34,7 @@ char *pager_program;int pager_use_color =1 ;char *editor_program;char *excludes_file; +char *excludes_per_dir_file;int auto_crlf =0 ;/* 1: both ways, -1: only when adding git objects */ unsigned whitespace_rule_cfg =WS_DEFAULT_RULE ;
git-checkout.sh +7 -1
@@ -210,7 +210,13 @@ then git read-tree $v --reset -u $new else git update-index --refresh >/dev/null - merge_error=$(git read-tree -m -u --exclude-per-directory=.gitignore $old $new 2>&1) || ( + excl_per_dir_file=$(git config core.excludesperdirfile) + if [ -z "$excl_per_dir_file" ]; + then + excl_per_dir_file=".gitignore" + fi + + merge_error=$(git read-tree -m -u --exclude-per-directory=$excl_per_dir_file $old $new 2>&1) || ( case "$merge" in '') echo >&2 "$merge_error"
git-merge.sh +6 -1
@@ -348,8 +348,13 @@ t,1,"$head",*) then msg="$msg (no commit created; -m option ignored)" fi + excl_per_dir_file=$(git config core.excludesperdirfile) + if [ -z "$excl_per_dir_file" ]; + then + excl_per_dir_file=".gitignore" + fi new_head=$(git rev-parse --verify "$1^0") && - git read-tree -v -m -u --exclude-per-directory=.gitignore $head "$new_head" && + git read-tree -v -m -u --exclude-per-directory=$excl_per_dir_file $head "$new_head" && finish "$new_head" "$msg" || exit dropsave exit 0
t/t3001-ls-files-others-exclude.sh +19 -0
@@ -99,4 +99,23 @@ EOF test_expect_success 'git-status honours core.excludesfile' \ 'diff -u expect output' + +git config core.excludesperdirfile .myignore +cat > .myignore << EOF +output +!/*.[47] +EOF + +cat > expect << EOF +# .gitignore +# .myignore +# a.4 +# a.7 +# one/ +EOF + +test_expect_success 'git status honours core.excludesperdirfile' \ + 'git status | grep "^# " > output && + git diff expect output' + test_done
t/t7300-clean.sh +15 -0
@@ -316,4 +316,19 @@ test_expect_success 'core.excludesfile' ' ' +test_expect_success 'core.excludesperdirfile' ' + + mkdir -p build docs src && + touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && + git config core.excludesperdirfile .myignore && + echo a.out >.myignore && + echo lib.so >build/.myignore && + git-clean -f && + test ! -f src/part3.c && + test ! -f obj.o && + test -f build/lib.so && + test -f a.out + +' + test_done
Signature · 1 line
1.5.4.GIT