@@ -63,4 +63,4 @@ mergetool.prompt::
Prompt before each invocation of the merge resolution program.
mergetool.autoMerge::
- Automatically resolve conflicts that don't require user intervention.
+ Remove lines without conflicts from all the files. Defaults to `true`.
@@ -239,6 +239,17 @@ checkout_staged_file () {
fi
}
+auto_merge () {
+ git merge-file --diff3 --marker-size=7 -q -p "$LOCAL" "$BASE" "$REMOTE" >"$DIFF3"
+ if test -s "$DIFF3"
+ then
+ sed -e '/^<<<<<<< /,/^||||||| /d' -e '/^=======\r\?$/,/^>>>>>>> /d' "$DIFF3" >"$BASE"
+ sed -e '/^||||||| /,/^>>>>>>> /d' -e '/^<<<<<<< /d' "$DIFF3" >"$LOCAL"
+ sed -e '/^<<<<<<< /,/^=======\r\?$/d' -e '/^>>>>>>> /d' "$DIFF3" >"$REMOTE"
+ fi
+ rm -- "$DIFF3"
+}
+
merge_file () {
MERGED="$1"
@@ -323,13 +334,9 @@ merge_file () {
checkout_staged_file 2 "$MERGED" "$LOCAL"
checkout_staged_file 3 "$MERGED" "$REMOTE"
- if test "$(git config --bool mergetool.autoMerge)" = "true"
+ if test "$(git config --bool mergetool.autoMerge)" != "false"
then
- git merge-file --diff3 -q -p "$LOCAL" "$BASE" "$REMOTE" >"$DIFF3"
- sed -e '/^<<<<<<< /,/^||||||| /d' -e '/^=======\r\?$/,/^>>>>>>> /d' "$DIFF3" >"$BASE"
- sed -e '/^||||||| /,/^>>>>>>> /d' -e '/^<<<<<<< /d' "$DIFF3" >"$LOCAL"
- sed -e '/^<<<<<<< /,/^=======\r\?$/d' -e '/^>>>>>>> /d' "$DIFF3" >"$REMOTE"
- rm -- "$DIFF3"
+ auto_merge
fi
if test -z "$local_mode" || test -z "$remote_mode"
@@ -832,16 +832,16 @@ test_expect_success 'mergetool automerge' '
test_config mergetool.automerge true &&
test_when_finished "git reset --hard" &&
git checkout -b test${test_count}_b master &&
- echo -e "base\n\na" >file1 &&
+ test_write_lines >file1 base "" a &&
git commit -a -m "base" &&
- echo -e "base\n\nc" >file1 &&
+ test_write_lines >file1 base "" c &&
git commit -a -m "remote update" &&
git checkout -b test${test_count}_a HEAD~ &&
- echo -e "local\n\nb" >file1 &&
+ test_write_lines >file1 local "" b &&
git commit -a -m "local update" &&
test_must_fail git merge test${test_count}_b &&
yes "" | git mergetool file1 &&
- echo -e "local\n\nc" >expect &&
+ test_write_lines >expect local "" c &&
test_cmp expect file1 &&
git commit -m "test resolved with mergetool"
'