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?
\-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.