{"thread":{"id":"39424","subject":"Re: [PATCH] git-new-workdir: add windows compatibility","startedAt":"2015-05-26T04:03:20Z","lastAt":"2015-05-29T10:52:13Z","messageCount":9,"participants":["Junio C Hamano","Johannes Schindelin","Paul Smith","Karsten Blees","Michael J Gruber","Duy Nguyen"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"262114","messageId":"xmqqfv6k7zp3.fsf@gitster.dls.corp.google.com","threadId":"39424","inReplyTo":"CADBZQ5iAKsSrdvBnFcdPcm9psaJo5B-H1zqJj0aRc+xx6cCFMQ@mail.gmail.com","subject":"Re: [PATCH] git-new-workdir: add windows compatibility","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-05-26T04:03:20Z","receivedAt":"2015-05-26T04:03:20Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Daniel Smith <dansmith65@gmail.com> writes:\n\n> When running on Windows in MinGW, creating symbolic links via ln always\n> failed.\n>\n> Using mklink instead of ln is the recommended method of creating links on\n> Windows:\n> http://stackoverflow.com/questions/18641864/git-bash-shell-fails-to-create-symbolic-links\n>\n> Script now branches on Windows to use mklink. This change should not affect\n> unix systems.\n>\n> Signed-off-by: Daniel Smith <dansmith65@gmail.com>\n>\n> Has been tested on Windows 8.1 and OS X Yosemite.\n> ---\n\nSwap the \"Has been tested...\" and \"Signed-off-by:\" lines.\n\nI'll defer to Windows folks if \"mklink\" is a sensible thing to use\nor not; I have no first-hand experience with Windows, but only heard\nthat links are for admin user only or something like that, so I want\nto hear from people whose judgement on Windows matters I trust.\n\n>\n> +iswindows () {\n> + [[ -n \"$WINDIR\" ]];\n> +}\n\nPlease don't add unnecessary bash-isms.  We have kept this script\nusable without stepping out of POSIX.\n\n\ttest -n \"$WINDIR\"\n\n> -git_dir=$(cd \"$git_dir\" && pwd) || exit 1\n> +if iswindows\n> +then\n> + git_dir=$(cd \"$git_dir\"; cmd.exe /c cd) || exit 1\n> +else\n> + git_dir=$(cd \"$git_dir\" && pwd) || exit 1\n> +fi\n\nIndentation of lines inside a new block is done with one more level\nof HT in our scripts, not with just one SP.\n\n> - ln -s \"$git_dir/$x\" \"$new_workdir/.git/$x\" || failed\n> + if iswindows\n> + then\n\nMove these into a helper shell function, starting from here...\n\n> + if test -d \"$git_dir/$x\"\n> + then\n> + # create directory symbolic link\n> + isdir=\"/d\"\n> + fi\n> + # convert path separator to backslash\n> + targetPath=$(sed -e 's#^J:##' -e 's#/#\\\\#g' <<< \"$git_dir/$x\")\n> + cmd.exe /c \"mklink $isdir \\\"$new_workdir/.git/$x\\\" \\\"$targetPath\\\"\" || failed\n\n... up to here.  Also a few points about these new lines:\n\n * Use indentation when doing nested if/then/if/then/fi/fi block,\n   i.e.\n\n\tif isWindows\n        then\n\t\tif test -d \"...\"\n                then\n\t\t\tisdir=/d\n                fi\n                target=..\n                cmd.exe /c ...\n\tfi\n\n * \"<<<\" is a bash-ism, isn't it?\n\n * Use of \"#\" as s/// separator, when slash is not involved, looks\n   ugly and makes it harder to read.\n\n * Is \"J:\" drive something special (unlike C: or D: drives)?\n\n * Can computation of targetPath fail?  IOW, shouldn't that line end\n   with &&?\n\n * Share || failed between this part and POSIX part, i.e.\n\n\tif isWindows\n        then\n\t\tln_s_win \"$new_workdir\" \"$x\"\n\telse\n\t\tln -s \"$git_dir/$x\" \"$new_workdir'.git/$x\"\n\tfi || failed\n\n   where ln_s_win would be the \"helper shell function\" I suggested.\n\n\tln_s_win () {\n\t\tif test -d \"$git_dir/$2\"\n\t\tthen\n                \tisdir=/d\n\t\tfi\n                target=$(printf \"%s\" \"$git_dir/$2\" | sed -e \"...\") &&\n\t\tcmd.exe /c \"mklink $isdir ...\"\n\t}\n\n> + else\n> + ln -s \"$git_dir/$x\" \"$new_workdir/.git/$x\" || failed\n> + fi\n>  done\n>\n>  # commands below this are run in the context of the new workdir\n\nThanks.\n"},{"id":"262126","messageId":"cbfbf842705637b52cde9c6b61f89a75@www.dscho.org","threadId":"39424","inReplyTo":"xmqqfv6k7zp3.fsf@gitster.dls.corp.google.com","subject":"Re: [PATCH] git-new-workdir: add windows compatibility","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2015-05-26T09:53:09Z","receivedAt":"2015-05-26T09:53:09Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn 2015-05-26 06:03, Junio C Hamano wrote:\n> Daniel Smith <dansmith65@gmail.com> writes:\n> \n>> When running on Windows in MinGW, creating symbolic links via ln always\n>> failed.\n>>\n>> Using mklink instead of ln is the recommended method of creating links on\n>> Windows:\n>> http://stackoverflow.com/questions/18641864/git-bash-shell-fails-to-create-symbolic-links\n>>\n>> Script now branches on Windows to use mklink. This change should not affect\n>> unix systems.\n>>\n>> Signed-off-by: Daniel Smith <dansmith65@gmail.com>\n>>\n>> Has been tested on Windows 8.1 and OS X Yosemite.\n>> ---\n> \n> Swap the \"Has been tested...\" and \"Signed-off-by:\" lines.\n> \n> I'll defer to Windows folks if \"mklink\" is a sensible thing to use\n> or not; I have no first-hand experience with Windows, but only heard\n> that links are for admin user only or something like that, so I want\n> to hear from people whose judgement on Windows matters I trust.\n\nThe biggest problem with `mklink` is that it is only supported on Windows Vista and later, while I really like to keep Windows XP support in Git for Windows.\n\nThat is why Karsten Blees' symlink support (emulated via NTFS reparse points) which I just merged into Git for Windows yesterday is so careful about everything.\n\nBut git-new-workdir is in `contrib/`, anyway, and not installed in Git for Windows by default, therefore it is less critical: interested parties will have to be a bit knowledgeable in any case.\n\nSo I am fine with it!\n\nCiao,\nDscho\n"},{"id":"262123","messageId":"1432642835.17513.22.camel@mad-scientist.net","threadId":"39424","inReplyTo":"cbfbf842705637b52cde9c6b61f89a75@www.dscho.org","subject":"Re: [PATCH] git-new-workdir: add windows compatibility","fromName":"Paul Smith","fromEmail":"paul@mad-scientist.net","sentAt":"2015-05-26T12:20:35Z","receivedAt":"2015-05-26T12:20:35Z","isPatch":true,"sender":{"key":"paul@mad-scientist.net","avatar":"https://avatars.githubusercontent.com/u/109636?v=4"},"body":"On Tue, 2015-05-26 at 11:53 +0200, Johannes Schindelin wrote:\n> The biggest problem with `mklink` is that it is only supported on\n> Windows Vista and later, while I really like to keep Windows XP\n> support in Git for Windows.\n\nNo, the biggest problem with mklink is that you have to have\nadministrative privileges to use it... from wikipedia:\n\nhttp://en.wikipedia.org/wiki/NTFS_symbolic_link\n\n> The default security settings in Windows Vista/Windows 7 disallow\n> non-elevated administrators and all non-administrators from creating\n> symbolic links. This behavior can be changed running \"secpol.msc\" the\n> Local Security Policy management console (under: Security Settings\n> \\Local Policies\\User Rights Assignment\\Create symbolic links). It can\n> be worked around by starting cmd.exe with Run as administrator option\n> or the runas command.\n\nExcept even that is not so simple, as various StackOverflow questions\nand answers will show (I have to run so I can't look them up now).  I\ndid try to get this to work a year or so ago, and although I'm in no way\na Windows person (so maybe someone else would have better luck) I\ncouldn't get it to work.\n"},{"id":"262120","messageId":"1fb8315dfaffb91ec4925bcc458e12a2@www.dscho.org","threadId":"39424","inReplyTo":"1432642835.17513.22.camel@mad-scientist.net","subject":"Re: [PATCH] git-new-workdir: add windows compatibility","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2015-05-26T12:35:30Z","receivedAt":"2015-05-26T12:35:30Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Paul,\n\nOn 2015-05-26 14:20, Paul Smith wrote:\n> On Tue, 2015-05-26 at 11:53 +0200, Johannes Schindelin wrote:\n>> The biggest problem with `mklink` is that it is only supported on\n>> Windows Vista and later, while I really like to keep Windows XP\n>> support in Git for Windows.\n> \n> No, the biggest problem with mklink is that you have to have\n> administrative privileges to use it... from wikipedia:\n> \n> http://en.wikipedia.org/wiki/NTFS_symbolic_link\n\nIt is even worse than that, as you pointed out below: administrators *can* permit non-administrators to create and use of symbolic links.\n\nHowever, from a maintainer's perspective (which is my role in this thread), the compatibility problem is an even worse problem than the permissions.\n\n>> The default security settings in Windows Vista/Windows 7 disallow\n>> non-elevated administrators and all non-administrators from creating\n>> symbolic links. This behavior can be changed running \"secpol.msc\" the\n>> Local Security Policy management console (under: Security Settings\n>> \\Local Policies\\User Rights Assignment\\Create symbolic links). It can\n>> be worked around by starting cmd.exe with Run as administrator option\n>> or the runas command.\n> \n> Except even that is not so simple, as various StackOverflow questions\n> and answers will show (I have to run so I can't look them up now).  I\n> did try to get this to work a year or so ago, and although I'm in no way\n> a Windows person (so maybe someone else would have better luck) I\n> couldn't get it to work.\n\nFor what it is worth, I tried my hand a couple of years ago at the project to move git-new-workdir to use the `.git` *file* and alternates mechanisms, but that does not work because you really need a separate `.git/HEAD`.\n\nCiao,\nJohannes\n"},{"id":"262134","messageId":"5564A3F7.8030305@gmail.com","threadId":"39424","inReplyTo":"xmqqfv6k7zp3.fsf@gitster.dls.corp.google.com","subject":"Re: [PATCH] git-new-workdir: add windows compatibility","fromName":"Karsten Blees","fromEmail":"karsten.blees@gmail.com","sentAt":"2015-05-26T16:48:55Z","receivedAt":"2015-05-26T16:48:55Z","isPatch":true,"sender":{"key":"karsten.blees@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1111200?v=4"},"body":"Am 26.05.2015 um 06:03 schrieb Junio C Hamano:\n> Daniel Smith <dansmith65@gmail.com> writes:\n> \n>> When running on Windows in MinGW, creating symbolic links via ln always\n>> failed.\n>>\n>> Using mklink instead of ln is the recommended method of creating links on\n>> Windows:\n>> http://stackoverflow.com/questions/18641864/git-bash-shell-fails-to-create-symbolic-links\n>>\n> \n> I'll defer to Windows folks if \"mklink\" is a sensible thing to use\n> or not; I have no first-hand experience with Windows, but only heard\n> that links are for admin user only or something like that, so I want\n> to hear from people whose judgement on Windows matters I trust.\n> \n\nmklink:\n - is not available on Windows XP\n - requires special permissions\n - does not work on network shares (unless enabled via 'fsutil behavior')\n - only works on file systems that support reparse points (e.g. NTFS, not FAT)\n\nAFAICT, the MSys2 symlink() implementation is pretty smart to detect these conditions and fall back to deep copy (aka 'cp -a') if symlinks are not supported.\n\nIOW, using 'ln -s' will hopefully \"just work\" in the upcoming Git for Windows 2, thus trying to fix it for MSys1 / Git for Windows 1.9x is probably a lost cause.\n\nKarsten\n"},{"id":"262218","messageId":"4f5a995a4012f7f4bce10c8170b06527@www.dscho.org","threadId":"39424","inReplyTo":"CADBZQ5hR1L7FPM_Ht00-as5eXw+PMJk1T2P3_ZiHedf0bi-H1w@mail.gmail.com","subject":"Re: [PATCH] git-new-workdir: add windows compatibility","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2015-05-27T08:17:05Z","receivedAt":"2015-05-27T08:17:05Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Daniel,\n\nOn 2015-05-26 19:16, Daniel Smith wrote:\n> Thanks to everyone for reviewing my proposed patch an providing valuable\n> feedback. This was my first patch submission to a large open source project\n> like Git and the whole process was a little daunting.\n\nHeh, yeah, it can be quite overwhelming (and this mailing list is very \"male\", too). Sorry!\n\nI hope, though, that it was obvious we all only wanted to be helpful?\n\n> On Tue, May 26, 2015 at 9:48 AM, Karsten Blees <karsten.blees@gmail.com>\n> wrote:\n> \n>> AFAICT, the MSys2 symlink() implementation is pretty smart to detect these\n>> conditions and fall back to deep copy (aka 'cp -a') if symlinks are not\n>> supported.\n>>\n>> IOW, using 'ln -s' will hopefully \"just work\" in the upcoming Git for\n>> Windows 2, thus trying to fix it for MSys1 / Git for Windows 1.9x is\n>> probably a lost cause.\n>>\n> \n> In that case, I'll abandon this patch and wait for Git for Windows 2 to\n> come out.\n\nSpeaking of which: Could you try `git-new-workdir` with Git for Windows 2.x (developers' preview)? https://git-for-windows.github.io/#download\n\nIt *might* be necessary to define the `MSYS` environment variable to `winsymlinks:nativestrict` before starting the Git Bash, to enable symlinking. It would be really good to know if that is the case so that I can do something about this in the Git for Windows installer.\n\nCiao,\nJohannes\n"},{"id":"262399","messageId":"55683700.3010201@drmicha.warpmail.net","threadId":"39424","inReplyTo":"1fb8315dfaffb91ec4925bcc458e12a2@www.dscho.org","subject":"Re: [PATCH] git-new-workdir: add windows compatibility","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2015-05-29T09:53:04Z","receivedAt":"2015-05-29T09:53:04Z","isPatch":true,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Johannes Schindelin venit, vidit, dixit 26.05.2015 14:35:\n> Hi Paul,\n> \n> On 2015-05-26 14:20, Paul Smith wrote:\n>> On Tue, 2015-05-26 at 11:53 +0200, Johannes Schindelin wrote:\n>>> The biggest problem with `mklink` is that it is only supported on\n>>> Windows Vista and later, while I really like to keep Windows XP\n>>> support in Git for Windows.\n>>\n>> No, the biggest problem with mklink is that you have to have\n>> administrative privileges to use it... from wikipedia:\n>>\n>> http://en.wikipedia.org/wiki/NTFS_symbolic_link\n> \n> It is even worse than that, as you pointed out below: administrators *can* permit non-administrators to create and use of symbolic links.\n> \n> However, from a maintainer's perspective (which is my role in this thread), the compatibility problem is an even worse problem than the permissions.\n> \n>>> The default security settings in Windows Vista/Windows 7 disallow\n>>> non-elevated administrators and all non-administrators from creating\n>>> symbolic links. This behavior can be changed running \"secpol.msc\" the\n>>> Local Security Policy management console (under: Security Settings\n>>> \\Local Policies\\User Rights Assignment\\Create symbolic links). It can\n>>> be worked around by starting cmd.exe with Run as administrator option\n>>> or the runas command.\n>>\n>> Except even that is not so simple, as various StackOverflow questions\n>> and answers will show (I have to run so I can't look them up now).  I\n>> did try to get this to work a year or so ago, and although I'm in no way\n>> a Windows person (so maybe someone else would have better luck) I\n>> couldn't get it to work.\n> \n> For what it is worth, I tried my hand a couple of years ago at the project to move git-new-workdir to use the `.git` *file* and alternates mechanisms, but that does not work because you really need a separate `.git/HEAD`.\n> \n> Ciao,\n> Johannes\n> \n\nIsn't that basically the approach that \"git checkout --to\" is taking? Is\nthat one \"Windows proof\"? I've lost track of its status, though.\n\nMichael\n"},{"id":"262404","messageId":"CACsJy8AtoQ=OJbmWN7WMqjxQ3yG7oPTrRszrcqSTSuqVnTkV7g@mail.gmail.com","threadId":"39424","inReplyTo":"55683700.3010201@drmicha.warpmail.net","subject":"Re: [PATCH] git-new-workdir: add windows compatibility","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2015-05-29T10:48:52Z","receivedAt":"2015-05-29T10:48:52Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Fri, May 29, 2015 at 4:53 PM, Michael J Gruber\n<git@drmicha.warpmail.net> wrote:\n> Isn't that basically the approach that \"git checkout --to\" is taking? Is\n> that one \"Windows proof\"?\n\nIt should be.\n\n> I've lost track of its status, though.\n\nIt should be fine to use as long as you don't do checkout --to on a\nsubmodule. Some progress was made on that direction, but I was busy\nwith other series and then didn't have time for git for a while.\n-- \nDuy\n"},{"id":"262405","messageId":"0ff0ae5b80b4bf5a82444343ac99590b@www.dscho.org","threadId":"39424","inReplyTo":"55683700.3010201@drmicha.warpmail.net","subject":"Re: [PATCH] git-new-workdir: add windows compatibility","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2015-05-29T10:52:13Z","receivedAt":"2015-05-29T10:52:13Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Michael,\n\nOn 2015-05-29 11:53, Michael J Gruber wrote:\n> Johannes Schindelin venit, vidit, dixit 26.05.2015 14:35:\n>> For what it is worth, I tried my hand a couple of years ago at the project to move git-new-workdir to use the `.git` *file* and alternates mechanisms, but that does not work because you really need a separate `.git/HEAD`.\n> \n> Isn't that basically the approach that \"git checkout --to\" is taking? Is\n> that one \"Windows proof\"? I've lost track of its status, though.\n\nI haven't tried `git checkout --to` on Windows yet, and sadly I won't be able to do that for another week...\n\nCiao,\nDscho\n"}]}