{"thread":{"id":"64140","subject":"[QUESTION] mergetool environment variables","startedAt":"2025-09-12T20:16:30Z","lastAt":"2025-09-15T15:36:07Z","messageCount":8,"participants":["rsbecker@nexbridge.com","Johannes Sixt","Junio C Hamano","Phillip Wood","D. Ben Knoble"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"526227","messageId":"074901dc2422$2039a910$60acfb30$@nexbridge.com","threadId":"64140","inReplyTo":null,"subject":"[QUESTION] mergetool environment variables","fromName":"","fromEmail":"rsbecker@nexbridge.com","sentAt":"2025-09-12T20:16:24Z","receivedAt":"2025-09-12T20:16:30Z","isPatch":false,"sender":{"key":"randall.becker@nexbridge.ca","avatar":"https://avatars.githubusercontent.com/u/28956764?v=4"},"body":"I am trying to integrate a custom mergetool with a shell wrapper.\nWhat I get from the online help is the following description referring\nto the command and environment variables.\n\nmergetool.<tool>.cmd \nSpecify the command to invoke the specified merge tool.\nThe specified command is evaluated in shell with the\nfollowing variables available: BASE is the name of a\ntemporary file containing the common base of the files\nto be merged, if available; LOCAL is the name of a\ntemporary file containing the contents of the file on\nthe current branch; REMOTE is the name of a temporary\nfile containing the contents of the file from the branch\nbeing merged; MERGED contains the name of the file\nto which the merge tool should write the results of a\nsuccessful merge.\n\nWhen I try to use this from a shell, simply with:\n#!/bin/sh\nenv\nexit 1\n\nthe described environment variables: BASE, LOCAL,\nREMOTE, and MERGED, are not present.\n\nThe history is trivial, but has a 1 line conflict after a\ngit merge. The file is called a, with two lines at the\nparent commit and the middle line changed in both\nbranches being merged. There are correct temp files\nin the directory while the shell script is being run. The\nmerged file looks as follows:\n\nHello\n<<<<<<< HEAD\nOurs\n=======\nTheirs\n>>>>>>> Incoming\nWorld\n\nThis applies to git 2.45.1 in cygwin and 2.51.0 on NonStop.\nThere are no upstreams. Is this the problem?\n\nAny thoughts on this?\n\nThanks,\nRandall\n\n--\nBrief whoami: NonStop&UNIX developer since approximately\nUNIX(421664400)\nNonStop(211288444200000000)\n-- In real life, I talk too much.\n\n\n"},{"id":"526239","messageId":"a5e01f0f-1789-427c-83c3-90644fa234c9@kdbg.org","threadId":"64140","inReplyTo":"074901dc2422$2039a910$60acfb30$@nexbridge.com","subject":"Re: [QUESTION] mergetool environment variables","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2025-09-13T07:04:50Z","receivedAt":"2025-09-13T07:04:54Z","isPatch":false,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 12.09.25 um 22:16 schrieb rsbecker@nexbridge.com:\n> I am trying to integrate a custom mergetool with a shell wrapper.\n> What I get from the online help is the following description referring\n> to the command and environment variables.\n> \n> mergetool.<tool>.cmd \n> Specify the command to invoke the specified merge tool.\n> The specified command is evaluated in shell with the\n> following variables available: BASE is the name of a\n\nTake note: this talks about \"variables\", not \"environment variables\".\n\n> temporary file containing the common base of the files\n> to be merged, if available; LOCAL is the name of a\n> temporary file containing the contents of the file on\n> the current branch; REMOTE is the name of a temporary\n> file containing the contents of the file from the branch\n> being merged; MERGED contains the name of the file\n> to which the merge tool should write the results of a\n> successful merge.\n> \n> When I try to use this from a shell, simply with:\n> #!/bin/sh\n> env\n> exit 1\n> \n> the described environment variables: BASE, LOCAL,\n> REMOTE, and MERGED, are not present.\n\nLook at the scripts in the directory mergetools/ and note that they are\nonly (large) shell code fragements without a shbang line. They are not\neven executable.\n\n-- Hannes\n\n"},{"id":"526247","messageId":"000201dc24bc$a1b8d9d0$e52a8d70$@nexbridge.com","threadId":"64140","inReplyTo":"a5e01f0f-1789-427c-83c3-90644fa234c9@kdbg.org","subject":"RE: [QUESTION] mergetool environment variables","fromName":"","fromEmail":"rsbecker@nexbridge.com","sentAt":"2025-09-13T14:42:24Z","receivedAt":"2025-09-13T14:42:39Z","isPatch":false,"sender":{"key":"randall.becker@nexbridge.ca","avatar":"https://avatars.githubusercontent.com/u/28956764?v=4"},"body":"On September 13, 2025 3:05 AM, Johannes Sixt wrote:\n>Am 12.09.25 um 22:16 schrieb rsbecker@nexbridge.com:\n>> I am trying to integrate a custom mergetool with a shell wrapper.\n>> What I get from the online help is the following description referring\n>> to the command and environment variables.\n>>\n>> mergetool.<tool>.cmd\n>> Specify the command to invoke the specified merge tool.\n>> The specified command is evaluated in shell with the following\n>> variables available: BASE is the name of a\n>\n>Take note: this talks about \"variables\", not \"environment variables\".\n>\n>> temporary file containing the common base of the files to be merged,\n>> if available; LOCAL is the name of a temporary file containing the\n>> contents of the file on the current branch; REMOTE is the name of a\n>> temporary file containing the contents of the file from the branch\n>> being merged; MERGED contains the name of the file to which the merge\n>> tool should write the results of a successful merge.\n>>\n>> When I try to use this from a shell, simply with:\n>> #!/bin/sh\n>> env\n>> exit 1\n>>\n>> the described environment variables: BASE, LOCAL, REMOTE, and MERGED,\n>> are not present.\n>\n>Look at the scripts in the directory mergetools/ and note that they are only (large)\n>shell code fragements without a shbang line. They are not even executable.\n\nLet me try to infer what is happening and please correct me if my assumptions\nare wrong:\n\nGit includes an existing shell fragment with the appropriate tool name from\ngit-core/mergetools/tool-name instead of creating a dedicated shell in which to\nrun the merge tool script.\n\nIt then uses ${merge-tool-path} to execute the tool based on whether diff_cmd() or\nmerge_cmd() is invoked. Because BASE, LOCAL, REMOTE, and MERGED are not\nexported, they are not visible to sub-shells.\n\nThis does not apply if the tool is unknown to the mergetools directory, so must be\ncontributed and packaged into git to work according to the documentation.\n\nSo a custom mergetool will not have access to these variables and has to hack\nthrough what is in the working index based on file_BASE_num, etc. instead of\nhaving direct information on what is being merged.\n\nThat about right?\n\n"},{"id":"526263","messageId":"9a03a436-8240-4566-9383-7afbf740719e@kdbg.org","threadId":"64140","inReplyTo":"000201dc24bc$a1b8d9d0$e52a8d70$@nexbridge.com","subject":"Re: [QUESTION] mergetool environment variables","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2025-09-13T21:03:56Z","receivedAt":"2025-09-13T21:04:12Z","isPatch":false,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 13.09.25 um 16:42 schrieb rsbecker@nexbridge.com:\n> Let me try to infer what is happening and please correct me if my assumptions\n> are wrong:\nI'm sorry to say that I can't help. I tried to disentangle what is going\non, but this stuff is far too convoluted to be understood in a few\nminutes. I cannot tell if it is possible to write a mergetool that is\nnot installed with Git.\n\nI would just copy one of the existing tool scripts and run `make\ninstall` from the Git source directory.\n\n-- Hannes\n\n"},{"id":"526267","messageId":"004101dc250d$18173950$4845abf0$@nexbridge.com","threadId":"64140","inReplyTo":"9a03a436-8240-4566-9383-7afbf740719e@kdbg.org","subject":"RE: [QUESTION] mergetool environment variables","fromName":"","fromEmail":"rsbecker@nexbridge.com","sentAt":"2025-09-14T00:18:22Z","receivedAt":"2025-09-14T00:18:41Z","isPatch":false,"sender":{"key":"randall.becker@nexbridge.ca","avatar":"https://avatars.githubusercontent.com/u/28956764?v=4"},"body":"On September 13, 2025 5:04 PM, Johannes Sixt wrote:\n>To: rsbecker@nexbridge.com\n>Cc: git@vger.kernel.org\n>Subject: Re: [QUESTION] mergetool environment variables\n>\n>Am 13.09.25 um 16:42 schrieb rsbecker@nexbridge.com:\n>> Let me try to infer what is happening and please correct me if my\n>> assumptions are wrong:\n>I'm sorry to say that I can't help. I tried to disentangle what is going on, but this\n>stuff is far too convoluted to be understood in a few minutes. I cannot tell if it is\n>possible to write a mergetool that is not installed with Git.\n>\n>I would just copy one of the existing tool scripts and run `make install` from the Git\n>source directory.\n\nYes, it needs to be in the git install area. Adding export BASE export LOCAL, etc.,\nworks to resolve the situation. I wonder whether that should be documented.\n\n"},{"id":"526268","messageId":"xmqq8qihk088.fsf@gitster.g","threadId":"64140","inReplyTo":"004101dc250d$18173950$4845abf0$@nexbridge.com","subject":"Re: [QUESTION] mergetool environment variables","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-09-14T06:38:15Z","receivedAt":"2025-09-14T06:38:18Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"<rsbecker@nexbridge.com> writes:\n\n> Yes, it needs to be in the git install area. Adding export BASE export LOCAL, etc.,\n> works to resolve the situation. I wonder whether that should be documented.\n\nI am not a mergetool user, but I do not think that is how the thing\nwas intended to be used in the first place.\n\nThe documentation that may talk about variables BASE etc. (not\n\"environment variables\") are meant for those who add their new tool\nto the existing mergetool/difftool infrastructure, which means that\ntheir tool's definition must be dot-sourceable just like any of\nthese tools defined in mergetools/ directory.  You'd add yours\nthere, mimicking what they do, and add a handful of shell functions\nto be called.  git-mergetool--lib would then use\n\n    . \"$MERGE_TOOLS_DIR/${tool%[0-9]}\"\n\ninside its setup_tool function to read your definition.\n\n"},{"id":"526275","messageId":"a57d5857-b096-4d92-993a-3f09d15cdcb9@gmail.com","threadId":"64140","inReplyTo":"004101dc250d$18173950$4845abf0$@nexbridge.com","subject":"Re: [QUESTION] mergetool environment variables","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2025-09-14T13:48:45Z","receivedAt":"2025-09-14T13:48:49Z","isPatch":false,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"Hi Randall\n\nOn 14/09/2025 01:18, rsbecker@nexbridge.com wrote:\n> On September 13, 2025 5:04 PM, Johannes Sixt wrote:\n>> To: rsbecker@nexbridge.com\n>> Cc: git@vger.kernel.org\n>> Subject: Re: [QUESTION] mergetool environment variables\n>>\n>> Am 13.09.25 um 16:42 schrieb rsbecker@nexbridge.com:\n>>> Let me try to infer what is happening and please correct me if my\n>>> assumptions are wrong:\n>> I'm sorry to say that I can't help. I tried to disentangle what is going on, but this\n>> stuff is far too convoluted to be understood in a few minutes. I cannot tell if it is\n>> possible to write a mergetool that is not installed with Git.\n>>\n>> I would just copy one of the existing tool scripts and run `make install` from the Git\n>> source directory.\n> \n> Yes, it needs to be in the git install area. Adding export BASE export LOCAL, etc.,\n> works to resolve the situation. I wonder whether that should be documented.\n\nLooking at t7610-mergetool.sh I think you can use mergetool.<tool>.cmd \nto call a user defined merge tool. The value of the config variable is \neval'd in the shell so if you run\n\n     git config mergetool.my-tool.cmd 'my-tool \"$BASE\" \"$LOCAL\" \"$REMOTE\"'\n\nthen\n\n     git mergetool --tool=my-tool\n\nwill run\n\n     my-tool <base-file> <local-file> <remote-file>\n\non each unmerged file\n\nThanks\n\nPhillip\n\n"},{"id":"526372","messageId":"CALnO6CDqDWLHfitqxHqOtL5Ej9XMfZUmC9j1dgQG6xiZGHQZMA@mail.gmail.com","threadId":"64140","inReplyTo":"a57d5857-b096-4d92-993a-3f09d15cdcb9@gmail.com","subject":"Re: [QUESTION] mergetool environment variables","fromName":"D. Ben Knoble","fromEmail":"ben.knoble@gmail.com","sentAt":"2025-09-15T15:35:53Z","receivedAt":"2025-09-15T15:36:07Z","isPatch":false,"sender":{"key":"ben.knoble@gmail.com","avatar":"https://avatars.githubusercontent.com/u/22802209?v=4"},"body":"The text of this reply sat in my drafts, so my apologies for getting\nit out later than I intended. I agree with Phillip's reply below, to\nwhich I've moved the text so it makes sense :)\n\nOn Sun, Sep 14, 2025 at 9:51 AM Phillip Wood <phillip.wood123@gmail.com> wrote:\n>\n> Hi Randall\n>\n> On 14/09/2025 01:18, rsbecker@nexbridge.com wrote:\n> > On September 13, 2025 5:04 PM, Johannes Sixt wrote:\n> >> To: rsbecker@nexbridge.com\n> >> Cc: git@vger.kernel.org\n> >> Subject: Re: [QUESTION] mergetool environment variables\n> >>\n> >> Am 13.09.25 um 16:42 schrieb rsbecker@nexbridge.com:\n> >>> Let me try to infer what is happening and please correct me if my\n> >>> assumptions are wrong:\n> >> I'm sorry to say that I can't help. I tried to disentangle what is going on, but this\n> >> stuff is far too convoluted to be understood in a few minutes. I cannot tell if it is\n> >> possible to write a mergetool that is not installed with Git.\n> >>\n> >> I would just copy one of the existing tool scripts and run `make install` from the Git\n> >> source directory.\n> >\n> > Yes, it needs to be in the git install area. Adding export BASE export LOCAL, etc.,\n> > works to resolve the situation. I wonder whether that should be documented.\n>\n> Looking at t7610-mergetool.sh I think you can use mergetool.<tool>.cmd\n> to call a user defined merge tool. The value of the config variable is\n> eval'd in the shell so if you run\n>\n>      git config mergetool.my-tool.cmd 'my-tool \"$BASE\" \"$LOCAL\" \"$REMOTE\"'\n>\n> then\n>\n>      git mergetool --tool=my-tool\n>\n> will run\n>\n>      my-tool <base-file> <local-file> <remote-file>\n>\n> on each unmerged file\n>\n> Thanks\n>\n> Phillip\n\nI run a custom merge tool, and I am fairly certain it has access to\nthese variables. But I pass them in the config defining the tool to\nthe « main » command in the versions where I use them.\n\nSee history around\nhttps://github.com/benknoble/Dotfiles/blob/4a4fe9678bdc5b34dc826058fbe85d29cc4d7722/links/gitconfig#L130.\n\nOtherwise this would seem an unfortunate interface.\n\n-- \nD. Ben Knoble\n"}]}