Skip to content

Commit a757c64

Browse files
committed
diff --check: honor conflict-marker-size attribute
Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8588567 commit a757c64

File tree

2 files changed

+33
-14
lines changed

2 files changed

+33
-14
lines changed

diff.c

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "userdiff.h"
1515
#include "sigchain.h"
1616
#include "submodule.h"
17+
#include "ll-merge.h"
1718

1819
#ifdef NO_FAST_WORKING_DIRECTORY
1920
#define FAST_WORKING_DIRECTORY 0
@@ -1364,44 +1365,40 @@ static void free_diffstat_info(struct diffstat_t *diffstat)
13641365
struct checkdiff_t {
13651366
const char *filename;
13661367
int lineno;
1368+
int conflict_marker_size;
13671369
struct diff_options *o;
13681370
unsigned ws_rule;
13691371
unsigned status;
13701372
};
13711373

1372-
static int is_conflict_marker(const char *line, unsigned long len)
1374+
static int is_conflict_marker(const char *line, int marker_size, unsigned long len)
13731375
{
13741376
char firstchar;
13751377
int cnt;
13761378

1377-
if (len < 8)
1379+
if (len < marker_size + 1)
13781380
return 0;
13791381
firstchar = line[0];
13801382
switch (firstchar) {
1381-
case '=': case '>': case '<':
1383+
case '=': case '>': case '<': case '|':
13821384
break;
13831385
default:
13841386
return 0;
13851387
}
1386-
for (cnt = 1; cnt < 7; cnt++)
1388+
for (cnt = 1; cnt < marker_size; cnt++)
13871389
if (line[cnt] != firstchar)
13881390
return 0;
1389-
/* line[0] thru line[6] are same as firstchar */
1390-
if (firstchar == '=') {
1391-
/* divider between ours and theirs? */
1392-
if (len != 8 || line[7] != '\n')
1393-
return 0;
1394-
} else if (len < 8 || !isspace(line[7])) {
1395-
/* not divider before ours nor after theirs */
1391+
/* line[1] thru line[marker_size-1] are same as firstchar */
1392+
if (len < marker_size + 1 || !isspace(line[marker_size]))
13961393
return 0;
1397-
}
13981394
return 1;
13991395
}
14001396

14011397
static void checkdiff_consume(void *priv, char *line, unsigned long len)
14021398
{
14031399
struct checkdiff_t *data = priv;
14041400
int color_diff = DIFF_OPT_TST(data->o, COLOR_DIFF);
1401+
int marker_size = data->conflict_marker_size;
14051402
const char *ws = diff_get_color(color_diff, DIFF_WHITESPACE);
14061403
const char *reset = diff_get_color(color_diff, DIFF_RESET);
14071404
const char *set = diff_get_color(color_diff, DIFF_FILE_NEW);
@@ -1410,7 +1407,7 @@ static void checkdiff_consume(void *priv, char *line, unsigned long len)
14101407
if (line[0] == '+') {
14111408
unsigned bad;
14121409
data->lineno++;
1413-
if (is_conflict_marker(line + 1, len - 1)) {
1410+
if (is_conflict_marker(line + 1, marker_size, len - 1)) {
14141411
data->status |= 1;
14151412
fprintf(data->o->file,
14161413
"%s:%d: leftover conflict marker\n",
@@ -1841,6 +1838,7 @@ static void builtin_checkdiff(const char *name_a, const char *name_b,
18411838
data.lineno = 0;
18421839
data.o = o;
18431840
data.ws_rule = whitespace_rule(attr_path);
1841+
data.conflict_marker_size = ll_merge_marker_size(attr_path);
18441842

18451843
if (fill_mmfile(&mf1, one) < 0 || fill_mmfile(&mf2, two) < 0)
18461844
die("unable to read files to diff");

t/t4017-diff-retval.sh

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ test_expect_success '--check with --no-pager returns 2 for dirty difference' '
105105
106106
'
107107

108-
109108
test_expect_success 'check should test not just the last line' '
110109
echo "" >>a &&
111110
git --no-pager diff --check
@@ -127,4 +126,26 @@ test_expect_success 'check detects leftover conflict markers' '
127126
git reset --hard
128127
'
129128

129+
test_expect_success 'check honors conflict marker length' '
130+
git reset --hard &&
131+
echo ">>>>>>> boo" >>b &&
132+
echo "======" >>a &&
133+
git diff --check a &&
134+
(
135+
git diff --check b
136+
test $? = 2
137+
) &&
138+
git reset --hard &&
139+
echo ">>>>>>>> boo" >>b &&
140+
echo "========" >>a &&
141+
git diff --check &&
142+
echo "b conflict-marker-size=8" >.gitattributes &&
143+
(
144+
git diff --check b
145+
test $? = 2
146+
) &&
147+
git diff --check a &&
148+
git reset --hard
149+
'
150+
130151
test_done

0 commit comments

Comments
 (0)