Skip to content

Commit 3f3f8d9

Browse files
committed
Merge branch 'jc/conflict-marker-size'
* jc/conflict-marker-size: diff --check: honor conflict-marker-size attribute
2 parents f9bdf9b + a757c64 commit 3f3f8d9

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
@@ -1370,44 +1371,40 @@ static void free_diffstat_info(struct diffstat_t *diffstat)
13701371
struct checkdiff_t {
13711372
const char *filename;
13721373
int lineno;
1374+
int conflict_marker_size;
13731375
struct diff_options *o;
13741376
unsigned ws_rule;
13751377
unsigned status;
13761378
};
13771379

1378-
static int is_conflict_marker(const char *line, unsigned long len)
1380+
static int is_conflict_marker(const char *line, int marker_size, unsigned long len)
13791381
{
13801382
char firstchar;
13811383
int cnt;
13821384

1383-
if (len < 8)
1385+
if (len < marker_size + 1)
13841386
return 0;
13851387
firstchar = line[0];
13861388
switch (firstchar) {
1387-
case '=': case '>': case '<':
1389+
case '=': case '>': case '<': case '|':
13881390
break;
13891391
default:
13901392
return 0;
13911393
}
1392-
for (cnt = 1; cnt < 7; cnt++)
1394+
for (cnt = 1; cnt < marker_size; cnt++)
13931395
if (line[cnt] != firstchar)
13941396
return 0;
1395-
/* line[0] thru line[6] are same as firstchar */
1396-
if (firstchar == '=') {
1397-
/* divider between ours and theirs? */
1398-
if (len != 8 || line[7] != '\n')
1399-
return 0;
1400-
} else if (len < 8 || !isspace(line[7])) {
1401-
/* not divider before ours nor after theirs */
1397+
/* line[1] thru line[marker_size-1] are same as firstchar */
1398+
if (len < marker_size + 1 || !isspace(line[marker_size]))
14021399
return 0;
1403-
}
14041400
return 1;
14051401
}
14061402

14071403
static void checkdiff_consume(void *priv, char *line, unsigned long len)
14081404
{
14091405
struct checkdiff_t *data = priv;
14101406
int color_diff = DIFF_OPT_TST(data->o, COLOR_DIFF);
1407+
int marker_size = data->conflict_marker_size;
14111408
const char *ws = diff_get_color(color_diff, DIFF_WHITESPACE);
14121409
const char *reset = diff_get_color(color_diff, DIFF_RESET);
14131410
const char *set = diff_get_color(color_diff, DIFF_FILE_NEW);
@@ -1416,7 +1413,7 @@ static void checkdiff_consume(void *priv, char *line, unsigned long len)
14161413
if (line[0] == '+') {
14171414
unsigned bad;
14181415
data->lineno++;
1419-
if (is_conflict_marker(line + 1, len - 1)) {
1416+
if (is_conflict_marker(line + 1, marker_size, len - 1)) {
14201417
data->status |= 1;
14211418
fprintf(data->o->file,
14221419
"%s:%d: leftover conflict marker\n",
@@ -1860,6 +1857,7 @@ static void builtin_checkdiff(const char *name_a, const char *name_b,
18601857
data.lineno = 0;
18611858
data.o = o;
18621859
data.ws_rule = whitespace_rule(attr_path);
1860+
data.conflict_marker_size = ll_merge_marker_size(attr_path);
18631861

18641862
if (fill_mmfile(&mf1, one) < 0 || fill_mmfile(&mf2, two) < 0)
18651863
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
@@ -120,7 +120,6 @@ test_expect_success '--check with --no-pager returns 2 for dirty difference' '
120120
121121
'
122122

123-
124123
test_expect_success 'check should test not just the last line' '
125124
echo "" >>a &&
126125
git --no-pager diff --check
@@ -142,4 +141,26 @@ test_expect_success 'check detects leftover conflict markers' '
142141
git reset --hard
143142
'
144143

144+
test_expect_success 'check honors conflict marker length' '
145+
git reset --hard &&
146+
echo ">>>>>>> boo" >>b &&
147+
echo "======" >>a &&
148+
git diff --check a &&
149+
(
150+
git diff --check b
151+
test $? = 2
152+
) &&
153+
git reset --hard &&
154+
echo ">>>>>>>> boo" >>b &&
155+
echo "========" >>a &&
156+
git diff --check &&
157+
echo "b conflict-marker-size=8" >.gitattributes &&
158+
(
159+
git diff --check b
160+
test $? = 2
161+
) &&
162+
git diff --check a &&
163+
git reset --hard
164+
'
165+
145166
test_done

0 commit comments

Comments
 (0)