]> git.ipfire.org Git - thirdparty/git.git/commit
dir, clean: avoid disallowed behavior
authorElijah Newren <newren@gmail.com>
Thu, 11 Jun 2020 06:59:31 +0000 (06:59 +0000)
committerJunio C Hamano <gitster@pobox.com>
Sat, 13 Jun 2020 00:27:16 +0000 (17:27 -0700)
commit351ea1c3cbf416b40cb999ea7426da633fa64918
treedea4c3b1cd726f6b8fcf84a154a1e4d88bbb3ed0
parente6c0be92394ee658d97fd02a517d22192ac1eb55
dir, clean: avoid disallowed behavior

dir.h documented quite clearly that DIR_SHOW_IGNORED and
DIR_SHOW_IGNORED_TOO are mutually exclusive, with a big comment to this
effect by the definition of both enum values.  However, a command like
   git clean -fx $DIR
would set both values for dir.flags.  I _think_ it happened to work
because:
  * As dir.h points out, DIR_KEEP_UNTRACKED_CONTENTS only takes effect
    if DIR_SHOW_IGNORED_TOO is set.
  * As coded, I believe DIR_SHOW_IGNORED would just happen to take
    precedence over DIR_SHOW_IGNORED_TOO in the code as currently
    constructed.
Which is a long way of saying "we just got lucky".

Fix clean.c to avoid setting these mutually exclusive values at the same
time, and add a check to dir.c that will throw a BUG() to prevent anyone
else from making this mistake.

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/clean.c
dir.c