Hi all,
Thanks for bringing up this topic. The git-new-workdir script definitely is a power tool that is a major enabler for custom (but natural) development workflows.
Unfortunately, the proposed solution of embedding Windows support into the existing *nix shell script did not work in my environment, whereas my environment is most likely a bit special, but nevertheless I expected it to work. After studying various public posts and MS docs, it is actually of vast importance to state what exactly the environment conditions are, so for the sake of completeness:
1. UAC is enabled, and the current user has Administrator privileges. This causes mklink to not work without privilege escalation.
2. Both Cygwin and msysgit/mingw32 (via TortoiseGit) are installed, and both participate in %PATH%, whereas Cygwin has precedence.
In order to run the script in an UAC-enabled environment (as a Windows user with administrative privileges), you have to use `runas`:
runas /env /user:administrator "mklink target source"
or to be more on-topic here:
runas /env /user:administrator "git-new-workdir path/to/repo path/to/new/workdir"
Note: The paths used in this example do not work as presented, because this command line has to be invoked from a Windows command shell, but the combined/embedded script does not contain logic to convert *nix paths into Windows paths, so `mklink` receives pathnames that it cannot interpret. At the same time, the rest of the script expects *nix paths. I'm not sure how the proposed script by +Daniel Smith can reasonably work.
After fixing that, the combined/embedded script did manage to create symlinks, but in all possible environments available to me, the symlinks (as well as all files in the working directory checkout) were effectively owned by no one, and not even Administrators had write access. I tried native Cygwin bash and sh, as well as the mingw32/msysgit bash. My environment is definitely prepared for cross-environment interactions, I did not experience this symptom since ~2005 (back then, caused by a missing `set CYGWIN=nontsec`).
Researching and debugging further, that problem appears to stem from the necessary `runas` process invocation call chain, which essentially turns into this:
runas →
cmd → cygwin/mingw32/msysgit →
bash →
cmd →
mklinkThe runas user context seems to get lost in the (ba)sh script execution context. I can only assume that there's just simply a limit of Windows user and security context persistence that can reasonably be expected from ports like msysgit/mingw32 and cygwin. ;-)
In order to resolve this issue and make git-new-workdir available for Windows, I ultimately resorted to +Jörg Rosenkranz's original approach of porting the script into a native .cmd script:
https://github.com/git/git/pull/87However, in order to facilitate ongoing maintenance of the two scripts, I essentially restarted from scratch and re-implemented the bash script 1:1 as batch script, including structure, comments, code, and execution flow. I took over some code from Jörg, but mostly replaced his code with simpler alternatives in order to mirror the existing script.
Let me know what you think,
sun