0

I have this snippet in a Powershell script, I can run the script on PSVersion 7.4.7 without error or problem, the git option gets set properly.

$cmd = '"' + $mergeTool + '" merge -p "$BASE" "$REMOTE" "$LOCAL" "$MERGED"'
# $cmd = "`"$mergeTool`" merge -p `"`$BASE`" `"`$REMOTE`" `"`$LOCAL`" `"`$MERGED`""

git config mergetool.unityyamlmerge.cmd "$cmd"

When running the script in VS2022 developer console, PSVersion 5.1.22621.4391, I get

error: invalid pattern: Files\Unity\Hub\Editor\2022.3.29f1\Editor\Data\Tools\UnityYAMLMerge.exe merge -p $BASE $REMOTE $LOCAL $MERGED`

I've tried to rework how the parameters are passed, but I cannot comprehend how the Powershell in VS2022 actually handles them, and thus have no idea how this was ever intended to be implemented. It doesn't seem to care if I quote "$cmd" or not, what is actually happening here which causes this not to work? Is this caused by differences between Powershell versions, and how each does arg handling?

1
  • The sad reality in Windows PowerShell (the legacy edition whose latest and last version is 5.1) and in PowerShell (Core) 7 up to v7.2.x is that an extra, manual layer of \-escaping of embedded " characters is required in arguments passed to external programs. Fortunately, this is no longer necessary in PowerShell 7 v7.3+, with selective exceptions on Windows. See the linked duplicate for details. Commented Apr 27 at 17:30

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.