Skip to content

Commit b57321f

Browse files
committed
git-clean: honor core.excludesfile
git-clean did not honor core.excludesfile configuration variable, although some other commands such as git-add and git-status did. Fix this inconsistency. Original report and patch from Shun'ichi Fuji. Rewritten by me and bugs and tests are mine. Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 7f55cf4 commit b57321f

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

git-clean.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,22 @@ esac
7575

7676
if [ -z "$ignored" ]; then
7777
excl="--exclude-per-directory=.gitignore"
78+
excl_info= excludes_file=
7879
if [ -f "$GIT_DIR/info/exclude" ]; then
7980
excl_info="--exclude-from=$GIT_DIR/info/exclude"
8081
fi
82+
if cfg_excl=$(git config core.excludesfile) && test -f "$cfg_excl"
83+
then
84+
excludes_file="--exclude-from=$cfg_excl"
85+
fi
8186
if [ "$ignoredonly" ]; then
8287
excl="$excl --ignored"
8388
fi
8489
fi
8590

86-
git ls-files --others --directory $excl ${excl_info:+"$excl_info"} -- "$@" |
91+
git ls-files --others --directory \
92+
$excl ${excl_info:+"$excl_info"} ${excludes_file:+"$excludes_file"} \
93+
-- "$@" |
8794
while read -r file; do
8895
if [ -d "$file" -a ! -L "$file" ]; then
8996
if [ -z "$cleandir" ]; then

t/t7300-clean.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,4 +177,15 @@ test_expect_success 'clean.requireForce and -f' '
177177
178178
'
179179

180+
test_expect_success 'core.excludesfile' '
181+
182+
echo excludes >excludes &&
183+
echo included >included &&
184+
git config core.excludesfile excludes &&
185+
output=$(git clean -n excludes included 2>&1) &&
186+
expr "$output" : ".*included" >/dev/null &&
187+
! expr "$output" : ".*excludes" >/dev/null
188+
189+
'
190+
180191
test_done

0 commit comments

Comments
 (0)