From: Felipe Contreras <felipe.contreras@gmail.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>,
David Aguilar <davvid@gmail.com>, Johannes Sixt <j6t@kdbg.org>,
Seth House <seth@eseth.com>,
Felipe Contreras <felipe.contreras@gmail.com>
Subject: [PATCH v4 0/1] mergetool: add configuration to remove unconflicted lines
Date: Fri, 18 Dec 2020 06:49:04 -0600 [thread overview]
Message-ID: <20201218124905.1072514-1-felipe.contreras@gmail.com> (raw)
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
next reply other threads:[~2020-12-18 12:51 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-18 12:49 Felipe Contreras [this message]
2020-12-18 12:49 ` [PATCH v4 1/1] mergetool: add automerge configuration Felipe Contreras
2020-12-19 11:14 ` Phillip Wood
2020-12-19 12:53 ` Felipe Contreras
2020-12-20 19:21 ` Phillip Wood
2020-12-21 3:04 ` Felipe Contreras
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201218124905.1072514-1-felipe.contreras@gmail.com \
--to=felipe.contreras@gmail.com \
--cc=davvid@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=j6t@kdbg.org \
--cc=seth@eseth.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).