I'm trying to use the merge-doc.js script in my Git config for merge driver and mergetool for .docx, but the TortoiseGit helper script that starts a compare in Word using DCOM requires absolute paths to work.
So after installing TortoiseGit on my Windows system and adding the following to Git .attributes and config, I need to also provide the current path, PWD, somehow.
.gitattributes
*.docx merge=word
config
[merge "word"]
name = Word document merge
driver = "wscript //nologo \"C:/Program Files/TortoiseGit/Diff-Scripts/merge-doc.js\" %A %B %A %O"
[mergetool "word"]
cmd = "wscript //nologo \"C:/Program Files/TortoiseGit/Diff-Scripts/merge-doc.js\" "$MERGED" "$REMOTE" "$LOCAL" "$LOCAL""
trustExitCode = true
I've tried adding PWD in different ways. But the Git trace keep showing that the variable isn't expanded.
This is probably very easy when you know GNU/Git bash.
22:23:26.042283 run-command.c:935
trace: start_command: 'C:/Program Files/Git/usr/bin/sh.exe' -c 'wscript //nologo "C:/Program Files/TortoiseGit/Diff-Scripts/merge-doc.js" "$(pwd.path)/.merge_file_rlnNRU" "%cd%/.merge_file_IiJUOk" "%pwd/.merge_file_rlnNRU" "%pwd/.merge_file_cMl86i"'
22:24:29.183367 run-command.c:674
run_command: 'wscript //nologo "C:/Program Files/TortoiseGit/Diff-Scripts/merge-doc.js" "`pwd`/.merge_file_yHhDa3" "%cd%/.merge_file_orFupt" "%pwd/.merge_file_yHhDa3" "%pwd/.merge_file_spZLIe"'
22:24:29.183367 run-command.c:935
Edit 1
So far I've deducted that sratch file variables presenting absolute paths, depending on what Git version used. Git for Windows apparently does not use absolute paths to avoid the legacy Win32 API issue with long file name limitations of 260 character path limit.
This was resolved in Windows 10 version 1607 (Anniversary Update) in August 2016, bit still has to be manually enabled by setting LongPathsEnabled to 1 under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem.
See MS Learn - Maximum Path Length Limitation.
Edit 2
No environment variables are available to Git bash when starting using only sh.exe.
Besides, according to @phd, I shoudn't be looking for the environment variable $pwd but the command $(pwd).
Edit 3
The merge-doc.js script expects the scratch files to have correct file extensions, where as Git driver provides non.
Edit 4
After I provide renamed scratch files, Git bash doesn't wait for the manual merger and tries to clean up the scratch files prematurely. If I use cscript, instead of wscript, this will at least hand over the work flow to merge-doc.js. But the Tortoise helper script also exits before Word is closed down. I was hoping for being able to integrate the Tortoise helper scripts with Git merge as is.
$(pwd)everywhere instead of$(pwd.path)and%pwd.sh.exe$(pwd)is not an environment variable, it's a call to programpwd. With$(pwd)shell runspwdand replaces$(pwd)with the output (stdout) ofpwd.merge.word.driverandmergetool.word.cmdcould be anything; they could be shell scripts that rename files passed to them and pass renamed files tomerge-doc.js.