Skip to content

Commit

Permalink
diff: update conflict handling for whitespace to issue a warning
Browse files Browse the repository at this point in the history
Modify the conflict resolution between tab-in-indent and
indent-with-non-tab to issue a warning instead of terminating
the operation with `die()`. Update the `git diff --check` test to
capture and verify the warning message output.

Suggested-by: Phillip Wood <[email protected]>
Signed-off-by: Usman Akinyemi <[email protected]>
  • Loading branch information
Unique-Usman committed Nov 11, 2024
1 parent facbe4f commit dfb80a7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion t/t4015-diff-whitespace.sh
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,8 @@ test_expect_success 'ditto, but tabwidth=1 (must be irrelevant)' '
test_expect_success 'check tab-in-indent and indent-with-non-tab conflict' '
git config core.whitespace "tab-in-indent,indent-with-non-tab" &&
echo "foo ();" >x &&
test_must_fail git diff --check
git diff --check 2>error &&
test_grep "warning: cannot enforce both tab-in-indent and indent-with-non-tab, removing tab-in-indent" error
'

test_expect_success 'check tab-in-indent excluded from wildcard whitespace attribute' '
Expand Down
7 changes: 5 additions & 2 deletions ws.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "git-compat-util.h"
#include "attr.h"
#include "strbuf.h"
#include "gettext.h"
#include "ws.h"

unsigned whitespace_rule_cfg = WS_DEFAULT_RULE;
Expand Down Expand Up @@ -70,8 +71,10 @@ unsigned parse_whitespace_rule(const char *string)
string = ep;
}

if (rule & WS_TAB_IN_INDENT && rule & WS_INDENT_WITH_NON_TAB)
die("cannot enforce both tab-in-indent and indent-with-non-tab");
if (rule & WS_TAB_IN_INDENT && rule & WS_INDENT_WITH_NON_TAB) {
warning(_("cannot enforce both tab-in-indent and indent-with-non-tab, removing tab-in-indent"));
rule &= ~WS_TAB_IN_INDENT;
}
return rule;
}

Expand Down

0 comments on commit dfb80a7

Please sign in to comment.