There's not much to say other that what the commit message of the patch says. Changes since v3: * Turned on by default * Added a check for binary files since Junio brought them up * Added the marker-size implicitly as Junio requested * Changed the way files are generated in the tests, as Junio said * Improved the documentation diff --git a/Documentation/config/mergetool.txt b/Documentation/config/mergetool.txt index 43af7a96f9..7ce6d0d3ac 100644 --- a/Documentation/config/mergetool.txt +++ b/Documentation/config/mergetool.txt @@ -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`. diff --git a/git-mergetool.sh b/git-mergetool.sh index 6e86d3b492..f4db0cac8d 100755 --- a/git-mergetool.sh +++ b/git-mergetool.sh @@ -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" diff --git a/t/t7610-mergetool.sh b/t/t7610-mergetool.sh index b75c91199b..ccabd04823 100755 --- a/t/t7610-mergetool.sh +++ b/t/t7610-mergetool.sh @@ -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" ' Felipe Contreras (1): mergetool: add automerge configuration Documentation/config/mergetool.txt | 3 +++ git-mergetool.sh | 17 +++++++++++++++++ t/t7610-mergetool.sh | 18 ++++++++++++++++++ 3 files changed, 38 insertions(+) -- 2.30.0.rc0