Skip to content

Commit 54bc414

Browse files
committed
Merge branch 'jk/merge-file-exit-code'
"git merge-file" tried to signal how many conflicts it found, which obviously would not work well when there are too many of them. * jk/merge-file-exit-code: merge-file: clamp exit code to maximum 127
2 parents f60b5dc + e34f802 commit 54bc414

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

Documentation/git-merge-file.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ lines from `<other-file>`, or lines from both respectively. The length of the
4141
conflict markers can be given with the `--marker-size` option.
4242

4343
The exit value of this program is negative on error, and the number of
44-
conflicts otherwise. If the merge was clean, the exit value is 0.
44+
conflicts otherwise (truncated to 127 if there are more than that many
45+
conflicts). If the merge was clean, the exit value is 0.
4546

4647
'git merge-file' is designed to be a minimal clone of RCS 'merge'; that is, it
4748
implements all of RCS 'merge''s functionality which is needed by

builtin/merge-file.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,5 +104,8 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)
104104
free(result.ptr);
105105
}
106106

107+
if (ret > 127)
108+
ret = 127;
109+
107110
return ret;
108111
}

t/t7600-merge.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,4 +692,37 @@ test_expect_success GPG 'merge --no-edit tag should skip editor' '
692692
test_cmp actual expect
693693
'
694694

695+
test_expect_success 'set up mod-256 conflict scenario' '
696+
# 256 near-identical stanzas...
697+
for i in $(test_seq 1 256); do
698+
for j in 1 2 3 4 5; do
699+
echo $i-$j
700+
done
701+
done >file &&
702+
git add file &&
703+
git commit -m base &&
704+
705+
# one side changes the first line of each to "master"
706+
sed s/-1/-master/ <file >tmp &&
707+
mv tmp file &&
708+
git commit -am master &&
709+
710+
# and the other to "side"; merging the two will
711+
# yield 256 separate conflicts
712+
git checkout -b side HEAD^ &&
713+
sed s/-1/-side/ <file >tmp &&
714+
mv tmp file &&
715+
git commit -am side
716+
'
717+
718+
test_expect_success 'merge detects mod-256 conflicts (recursive)' '
719+
git reset --hard &&
720+
test_must_fail git merge -s recursive master
721+
'
722+
723+
test_expect_success 'merge detects mod-256 conflicts (resolve)' '
724+
git reset --hard &&
725+
test_must_fail git merge -s resolve master
726+
'
727+
695728
test_done

0 commit comments

Comments
 (0)