Skip to content

Commit dfb80a7

Browse files
committed
diff: update conflict handling for whitespace to issue a warning
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]>
1 parent facbe4f commit dfb80a7

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

t/t4015-diff-whitespace.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,8 @@ test_expect_success 'ditto, but tabwidth=1 (must be irrelevant)' '
808808
test_expect_success 'check tab-in-indent and indent-with-non-tab conflict' '
809809
git config core.whitespace "tab-in-indent,indent-with-non-tab" &&
810810
echo "foo ();" >x &&
811-
test_must_fail git diff --check
811+
git diff --check 2>error &&
812+
test_grep "warning: cannot enforce both tab-in-indent and indent-with-non-tab, removing tab-in-indent" error
812813
'
813814

814815
test_expect_success 'check tab-in-indent excluded from wildcard whitespace attribute' '

ws.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "git-compat-util.h"
77
#include "attr.h"
88
#include "strbuf.h"
9+
#include "gettext.h"
910
#include "ws.h"
1011

1112
unsigned whitespace_rule_cfg = WS_DEFAULT_RULE;
@@ -70,8 +71,10 @@ unsigned parse_whitespace_rule(const char *string)
7071
string = ep;
7172
}
7273

73-
if (rule & WS_TAB_IN_INDENT && rule & WS_INDENT_WITH_NON_TAB)
74-
die("cannot enforce both tab-in-indent and indent-with-non-tab");
74+
if (rule & WS_TAB_IN_INDENT && rule & WS_INDENT_WITH_NON_TAB) {
75+
warning(_("cannot enforce both tab-in-indent and indent-with-non-tab, removing tab-in-indent"));
76+
rule &= ~WS_TAB_IN_INDENT;
77+
}
7578
return rule;
7679
}
7780

0 commit comments

Comments
 (0)