git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re* [PATCH v2] fixup! mergetool: add automerge configuration

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 10, 2021, 06:40 UTC
Message-ID
<xmqqa6thcn1n.fsf_-_@gitster.c.googlers.com>
In-Reply-To
<xmqqmtxhd1zx.fsf@gitster.c.googlers.com>
Junio C Hamano <gitster@pobox.com> writes:
Show 14 quoted lines
> Seth House <seth@eseth.com> writes:
>
>> On Sat, Jan 09, 2021 at 02:42:36PM -0800, David Aguilar wrote:
>>> Replace "\r" with a substituted variable that contains "\r".
>>> Replace "\?" with "\{0,1\}".
>>
>> Nice. I was (very slowly) converging on that as the culprit. Thanks for
>> the elegant fix! I'm running the test suite on Windows and OSX (now that
>> they're set up locally) with this included and I'll send a v10 once
>> complete.
>
> Note that the topic fails t7800.5 even with the fix-up (and without
> these fix-up on a platform with sed that do not need the portability
> fix-up).

It seems that 51b27370 (mergetool: break setup_tool out into separate initialization function, 2020-12-28) is the culprit.

git-difftool--helper is taught to do this:
    diff --git a/git-difftool--helper.sh b/git-difftool--helper.sh
    index 46af3e60b7..234dd6944e 100755
    --- a/git-difftool--helper.sh
    +++ b/git-difftool--helper.sh
     ...
    @@ -79,6 +80,7 @@ if test -n "$GIT_DIFFTOOL_DIRDIFF"
     then
            LOCAL="$1"
            REMOTE="$2"
    +	initialize_merge_tool "$merge_tool" &&
            run_merge_tool "$merge_tool" false
     else
            # Launch the merge tool on each path provided by 'git diff'

But the thing is, t7800.5 gives a name of merge-tool that does not exist, and expects difftool to notice it and error out. The callchain starting from the above "run_merge_tool" should look like

    run_merge_tool () {
        merge_tool_path=$(get_merge_tool_path ...) || exit
	...
which in turn calls
    get_merge_tool_path () {
        # A merge tool has been set, so verify that it's valid.
        merge_tool="$1"
        if ! valid_tool "$merge_tool"
        then
                echo >&2 "Unknown merge tool $merge_tool"
                exit 1
        fi

and "valid_tool bad-tool" would return false, which lets us safely exit with the error message.

But the call to initialize_merge_tool inserted above, that makes us to SKIP the call to run_merge_tool, would defeat the error detection.

An ugly workaround patch that caters only to difftool breakage is attached at the end; I did not look if a similar treatment is necessary for the mergetool side.

By the way, debugging this was somewhat painful as difftool is partly rewritten in C. If it were still pure script, it would have been a lot easier to diagnose with a single "set -x" somewhere X-<.

----- >8 ---------- >8 ---------- >8 ---------- >8 -----
From: Junio C Hamano <gitster@pobox.com>
Date: Sat, 9 Jan 2021 22:35:18 -0800
Subject: [PATCH] fixup! mergetool: break setup_tool out into
    separate initialization function

At least difftool wants to see even a broken tool name in its call to run_merge_tool and have it diagnose an error. &&-cascading the call to initialize_merge_tool and run_merge_tool means that a bogus tool name that does not please initialize_merge_tool is not even seen by run_merge_tool and the error goes unnoticed.

I didn't audit the original commit for its use of initialize_merge_tool on the merge-tool side. It may share the same issue, or it may not.

This should fix the errors we've been seeing in t7800.5 (and
possibly others) with this topic.
---
 git-difftool--helper.sh | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/git-difftool--helper.sh b/git-difftool--helper.sh
index 234dd6944e..992124cc67 100755
--- a/git-difftool--helper.sh
+++ b/git-difftool--helper.sh
@@ -61,7 +61,9 @@ launch_merge_tool () {
 		export BASE
 		eval $GIT_DIFFTOOL_EXTCMD '"$LOCAL"' '"$REMOTE"'
 	else
-		initialize_merge_tool "$merge_tool" &&
+		initialize_merge_tool "$merge_tool"
+		# ignore the error from the above --- run_merge_tool
+		# will diagnose unusable tool by itself
 		run_merge_tool "$merge_tool"
 	fi
 }
@@ -80,7 +82,9 @@ if test -n "$GIT_DIFFTOOL_DIRDIFF"
 then
 	LOCAL="$1"
 	REMOTE="$2"
-	initialize_merge_tool "$merge_tool" &&
+	initialize_merge_tool "$merge_tool"
+	# ignore the error from the above --- run_merge_tool
+	# will diagnose unusable tool by itself
 	run_merge_tool "$merge_tool" false
 else
 	# Launch the merge tool on each path provided by 'git diff'
-- 
2.30.0-311-g8a3956654a
Previous: Junio C HamanoNext: Seth House
Message 6 of 24 in “fixup! mergetool: add automerge configuration”
  1. fixup! mergetool: add automerge configurationDavid Aguilar, Jan 9, 2021
  2. brian m. carlsonJan 9, 2021
  3. fixup! mergetool: add automerge configurationDavid Aguilar, Jan 9, 2021
  4. Seth HouseJan 9, 2021
  5. Junio C HamanoJan 10, 2021
  6. Re* [PATCH v2] fixup! mergetool: add automerge configurationJunio C Hamano, Jan 10, 2021
  7. Seth HouseJan 10, 2021
  8. Junio C HamanoJan 10, 2021
  9. Seth HouseJan 16, 2021
  10. automerge implementation ideas for WindowsSeth House, Jan 20, 2021
  11. Junio C HamanoJan 21, 2021
  12. Seth HouseJan 22, 2021
  13. Junio C HamanoJan 22, 2021
  14. brian m. carlsonJan 22, 2021
  15. Johannes SchindelinJan 22, 2021
  16. brian m. carlsonJan 22, 2021
  17. Johannes SchindelinJan 26, 2021
  18. Seth HouseJan 26, 2021
  19. Junio C HamanoJan 26, 2021
  20. Seth HouseJan 27, 2021
  21. Junio C HamanoJan 29, 2021
  22. Junio C HamanoJan 9, 2021
  23. Junio C HamanoJan 10, 2021
  24. Junio C HamanoJan 9, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.