git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* Re: [PATCH] git-new-workdir: add windows compatibility
       [not found] <CADBZQ5iAKsSrdvBnFcdPcm9psaJo5B-H1zqJj0aRc+xx6cCFMQ@mail.gmail.com>
@ 2015-05-26  4:03 ` Junio C Hamano
  2015-05-26  9:53   ` Johannes Schindelin
  2015-05-26 16:48   ` Karsten Blees
  0 siblings, 2 replies; 9+ messages in thread
From: Junio C Hamano @ 2015-05-26  4:03 UTC (permalink / raw)
  To: Daniel Smith
  Cc: git, Paul Smith, Jeff King, Ralf Wildenhues, Richard Hartmann

Daniel Smith <dansmith65@gmail.com> writes:

> When running on Windows in MinGW, creating symbolic links via ln always
> failed.
>
> Using mklink instead of ln is the recommended method of creating links on
> Windows:
> http://stackoverflow.com/questions/18641864/git-bash-shell-fails-to-create-symbolic-links
>
> Script now branches on Windows to use mklink. This change should not affect
> unix systems.
>
> Signed-off-by: Daniel Smith <dansmith65@gmail.com>
>
> Has been tested on Windows 8.1 and OS X Yosemite.
> ---

Swap the "Has been tested..." and "Signed-off-by:" lines.

I'll defer to Windows folks if "mklink" is a sensible thing to use
or not; I have no first-hand experience with Windows, but only heard
that links are for admin user only or something like that, so I want
to hear from people whose judgement on Windows matters I trust.

>
> +iswindows () {
> + [[ -n "$WINDIR" ]];
> +}

Please don't add unnecessary bash-isms.  We have kept this script
usable without stepping out of POSIX.

	test -n "$WINDIR"

> -git_dir=$(cd "$git_dir" && pwd) || exit 1
> +if iswindows
> +then
> + git_dir=$(cd "$git_dir"; cmd.exe /c cd) || exit 1
> +else
> + git_dir=$(cd "$git_dir" && pwd) || exit 1
> +fi

Indentation of lines inside a new block is done with one more level
of HT in our scripts, not with just one SP.

> - ln -s "$git_dir/$x" "$new_workdir/.git/$x" || failed
> + if iswindows
> + then

Move these into a helper shell function, starting from here...

> + if test -d "$git_dir/$x"
> + then
> + # create directory symbolic link
> + isdir="/d"
> + fi
> + # convert path separator to backslash
> + targetPath=$(sed -e 's#^J:##' -e 's#/#\\#g' <<< "$git_dir/$x")
> + cmd.exe /c "mklink $isdir \"$new_workdir/.git/$x\" \"$targetPath\"" || failed

... up to here.  Also a few points about these new lines:

 * Use indentation when doing nested if/then/if/then/fi/fi block,
   i.e.

	if isWindows
        then
		if test -d "..."
                then
			isdir=/d
                fi
                target=..
                cmd.exe /c ...
	fi

 * "<<<" is a bash-ism, isn't it?

 * Use of "#" as s/// separator, when slash is not involved, looks
   ugly and makes it harder to read.

 * Is "J:" drive something special (unlike C: or D: drives)?

 * Can computation of targetPath fail?  IOW, shouldn't that line end
   with &&?

 * Share || failed between this part and POSIX part, i.e.

	if isWindows
        then
		ln_s_win "$new_workdir" "$x"
	else
		ln -s "$git_dir/$x" "$new_workdir'.git/$x"
	fi || failed

   where ln_s_win would be the "helper shell function" I suggested.

	ln_s_win () {
		if test -d "$git_dir/$2"
		then
                	isdir=/d
		fi
                target=$(printf "%s" "$git_dir/$2" | sed -e "...") &&
		cmd.exe /c "mklink $isdir ..."
	}

> + else
> + ln -s "$git_dir/$x" "$new_workdir/.git/$x" || failed
> + fi
>  done
>
>  # commands below this are run in the context of the new workdir

Thanks.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] git-new-workdir: add windows compatibility
  2015-05-26  4:03 ` [PATCH] git-new-workdir: add windows compatibility Junio C Hamano
@ 2015-05-26  9:53   ` Johannes Schindelin
  2015-05-26 12:20     ` Paul Smith
  2015-05-26 16:48   ` Karsten Blees
  1 sibling, 1 reply; 9+ messages in thread
From: Johannes Schindelin @ 2015-05-26  9:53 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Daniel Smith, git, Paul Smith, Jeff King, Ralf Wildenhues,
	Richard Hartmann

Hi,

On 2015-05-26 06:03, Junio C Hamano wrote:
> Daniel Smith <dansmith65@gmail.com> writes:
> 
>> When running on Windows in MinGW, creating symbolic links via ln always
>> failed.
>>
>> Using mklink instead of ln is the recommended method of creating links on
>> Windows:
>> http://stackoverflow.com/questions/18641864/git-bash-shell-fails-to-create-symbolic-links
>>
>> Script now branches on Windows to use mklink. This change should not affect
>> unix systems.
>>
>> Signed-off-by: Daniel Smith <dansmith65@gmail.com>
>>
>> Has been tested on Windows 8.1 and OS X Yosemite.
>> ---
> 
> Swap the "Has been tested..." and "Signed-off-by:" lines.
> 
> I'll defer to Windows folks if "mklink" is a sensible thing to use
> or not; I have no first-hand experience with Windows, but only heard
> that links are for admin user only or something like that, so I want
> to hear from people whose judgement on Windows matters I trust.

The 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.

That 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.

But 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.

So I am fine with it!

Ciao,
Dscho

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] git-new-workdir: add windows compatibility
  2015-05-26  9:53   ` Johannes Schindelin
@ 2015-05-26 12:20     ` Paul Smith
  2015-05-26 12:35       ` Johannes Schindelin
  0 siblings, 1 reply; 9+ messages in thread
From: Paul Smith @ 2015-05-26 12:20 UTC (permalink / raw)
  To: Johannes Schindelin
  Cc: Junio C Hamano, Daniel Smith, git, Jeff King, Ralf Wildenhues,
	Richard Hartmann

On Tue, 2015-05-26 at 11:53 +0200, Johannes Schindelin wrote:
> The 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.

No, the biggest problem with mklink is that you have to have
administrative privileges to use it... from wikipedia:

http://en.wikipedia.org/wiki/NTFS_symbolic_link

> The default security settings in Windows Vista/Windows 7 disallow
> non-elevated administrators and all non-administrators from creating
> symbolic links. This behavior can be changed running "secpol.msc" the
> Local Security Policy management console (under: Security Settings
> \Local Policies\User Rights Assignment\Create symbolic links). It can
> be worked around by starting cmd.exe with Run as administrator option
> or the runas command.

Except even that is not so simple, as various StackOverflow questions
and answers will show (I have to run so I can't look them up now).  I
did try to get this to work a year or so ago, and although I'm in no way
a Windows person (so maybe someone else would have better luck) I
couldn't get it to work.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] git-new-workdir: add windows compatibility
  2015-05-26 12:20     ` Paul Smith
@ 2015-05-26 12:35       ` Johannes Schindelin
  2015-05-29  9:53         ` Michael J Gruber
  0 siblings, 1 reply; 9+ messages in thread
From: Johannes Schindelin @ 2015-05-26 12:35 UTC (permalink / raw)
  To: paul
  Cc: Junio C Hamano, Daniel Smith, git, Jeff King, Ralf Wildenhues,
	Richard Hartmann

Hi Paul,

On 2015-05-26 14:20, Paul Smith wrote:
> On Tue, 2015-05-26 at 11:53 +0200, Johannes Schindelin wrote:
>> The 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.
> 
> No, the biggest problem with mklink is that you have to have
> administrative privileges to use it... from wikipedia:
> 
> http://en.wikipedia.org/wiki/NTFS_symbolic_link

It is even worse than that, as you pointed out below: administrators *can* permit non-administrators to create and use of symbolic links.

However, from a maintainer's perspective (which is my role in this thread), the compatibility problem is an even worse problem than the permissions.

>> The default security settings in Windows Vista/Windows 7 disallow
>> non-elevated administrators and all non-administrators from creating
>> symbolic links. This behavior can be changed running "secpol.msc" the
>> Local Security Policy management console (under: Security Settings
>> \Local Policies\User Rights Assignment\Create symbolic links). It can
>> be worked around by starting cmd.exe with Run as administrator option
>> or the runas command.
> 
> Except even that is not so simple, as various StackOverflow questions
> and answers will show (I have to run so I can't look them up now).  I
> did try to get this to work a year or so ago, and although I'm in no way
> a Windows person (so maybe someone else would have better luck) I
> couldn't get it to work.

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`.

Ciao,
Johannes

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] git-new-workdir: add windows compatibility
  2015-05-26  4:03 ` [PATCH] git-new-workdir: add windows compatibility Junio C Hamano
  2015-05-26  9:53   ` Johannes Schindelin
@ 2015-05-26 16:48   ` Karsten Blees
       [not found]     ` <CADBZQ5hR1L7FPM_Ht00-as5eXw+PMJk1T2P3_ZiHedf0bi-H1w@mail.gmail.com>
  1 sibling, 1 reply; 9+ messages in thread
From: Karsten Blees @ 2015-05-26 16:48 UTC (permalink / raw)
  To: Junio C Hamano, Daniel Smith
  Cc: git, Paul Smith, Jeff King, Ralf Wildenhues, Richard Hartmann,
	Johannes Schindelin

Am 26.05.2015 um 06:03 schrieb Junio C Hamano:
> Daniel Smith <dansmith65@gmail.com> writes:
> 
>> When running on Windows in MinGW, creating symbolic links via ln always
>> failed.
>>
>> Using mklink instead of ln is the recommended method of creating links on
>> Windows:
>> http://stackoverflow.com/questions/18641864/git-bash-shell-fails-to-create-symbolic-links
>>
> 
> I'll defer to Windows folks if "mklink" is a sensible thing to use
> or not; I have no first-hand experience with Windows, but only heard
> that links are for admin user only or something like that, so I want
> to hear from people whose judgement on Windows matters I trust.
> 

mklink:
 - is not available on Windows XP
 - requires special permissions
 - does not work on network shares (unless enabled via 'fsutil behavior')
 - only works on file systems that support reparse points (e.g. NTFS, not FAT)

AFAICT, 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.

IOW, 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.

Karsten

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] git-new-workdir: add windows compatibility
       [not found]     ` <CADBZQ5hR1L7FPM_Ht00-as5eXw+PMJk1T2P3_ZiHedf0bi-H1w@mail.gmail.com>
@ 2015-05-27  8:17       ` Johannes Schindelin
  0 siblings, 0 replies; 9+ messages in thread
From: Johannes Schindelin @ 2015-05-27  8:17 UTC (permalink / raw)
  To: Daniel Smith
  Cc: Karsten Blees, Junio C Hamano, git, Paul Smith, Jeff King,
	Ralf Wildenhues, Richard Hartmann

Hi Daniel,

On 2015-05-26 19:16, Daniel Smith wrote:
> Thanks to everyone for reviewing my proposed patch an providing valuable
> feedback. This was my first patch submission to a large open source project
> like Git and the whole process was a little daunting.

Heh, yeah, it can be quite overwhelming (and this mailing list is very "male", too). Sorry!

I hope, though, that it was obvious we all only wanted to be helpful?

> On Tue, May 26, 2015 at 9:48 AM, Karsten Blees <karsten.blees@gmail.com>
> wrote:
> 
>> AFAICT, 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.
>>
>> IOW, 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.
>>
> 
> In that case, I'll abandon this patch and wait for Git for Windows 2 to
> come out.

Speaking of which: Could you try `git-new-workdir` with Git for Windows 2.x (developers' preview)? https://git-for-windows.github.io/#download

It *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.

Ciao,
Johannes

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] git-new-workdir: add windows compatibility
  2015-05-26 12:35       ` Johannes Schindelin
@ 2015-05-29  9:53         ` Michael J Gruber
  2015-05-29 10:48           ` Duy Nguyen
  2015-05-29 10:52           ` Johannes Schindelin
  0 siblings, 2 replies; 9+ messages in thread
From: Michael J Gruber @ 2015-05-29  9:53 UTC (permalink / raw)
  To: Johannes Schindelin, paul, Git Mailing List, Nguyen Thai Ngoc Duy
  Cc: Junio C Hamano, Daniel Smith, git, Jeff King, Ralf Wildenhues,
	Richard Hartmann

Johannes Schindelin venit, vidit, dixit 26.05.2015 14:35:
> Hi Paul,
> 
> On 2015-05-26 14:20, Paul Smith wrote:
>> On Tue, 2015-05-26 at 11:53 +0200, Johannes Schindelin wrote:
>>> The 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.
>>
>> No, the biggest problem with mklink is that you have to have
>> administrative privileges to use it... from wikipedia:
>>
>> http://en.wikipedia.org/wiki/NTFS_symbolic_link
> 
> It is even worse than that, as you pointed out below: administrators *can* permit non-administrators to create and use of symbolic links.
> 
> However, from a maintainer's perspective (which is my role in this thread), the compatibility problem is an even worse problem than the permissions.
> 
>>> The default security settings in Windows Vista/Windows 7 disallow
>>> non-elevated administrators and all non-administrators from creating
>>> symbolic links. This behavior can be changed running "secpol.msc" the
>>> Local Security Policy management console (under: Security Settings
>>> \Local Policies\User Rights Assignment\Create symbolic links). It can
>>> be worked around by starting cmd.exe with Run as administrator option
>>> or the runas command.
>>
>> Except even that is not so simple, as various StackOverflow questions
>> and answers will show (I have to run so I can't look them up now).  I
>> did try to get this to work a year or so ago, and although I'm in no way
>> a Windows person (so maybe someone else would have better luck) I
>> couldn't get it to work.
> 
> 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`.
> 
> Ciao,
> Johannes
> 

Isn't that basically the approach that "git checkout --to" is taking? Is
that one "Windows proof"? I've lost track of its status, though.

Michael

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] git-new-workdir: add windows compatibility
  2015-05-29  9:53         ` Michael J Gruber
@ 2015-05-29 10:48           ` Duy Nguyen
  2015-05-29 10:52           ` Johannes Schindelin
  1 sibling, 0 replies; 9+ messages in thread
From: Duy Nguyen @ 2015-05-29 10:48 UTC (permalink / raw)
  To: Michael J Gruber
  Cc: Johannes Schindelin, paul, Git Mailing List, Junio C Hamano,
	Daniel Smith, Jeff King, Ralf Wildenhues, Richard Hartmann

On Fri, May 29, 2015 at 4:53 PM, Michael J Gruber
<git@drmicha.warpmail.net> wrote:
> Isn't that basically the approach that "git checkout --to" is taking? Is
> that one "Windows proof"?

It should be.

> I've lost track of its status, though.

It should be fine to use as long as you don't do checkout --to on a
submodule. Some progress was made on that direction, but I was busy
with other series and then didn't have time for git for a while.
-- 
Duy

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] git-new-workdir: add windows compatibility
  2015-05-29  9:53         ` Michael J Gruber
  2015-05-29 10:48           ` Duy Nguyen
@ 2015-05-29 10:52           ` Johannes Schindelin
  1 sibling, 0 replies; 9+ messages in thread
From: Johannes Schindelin @ 2015-05-29 10:52 UTC (permalink / raw)
  To: Michael J Gruber
  Cc: paul, Git Mailing List, Nguyen Thai Ngoc Duy, Junio C Hamano,
	Daniel Smith, Jeff King, Ralf Wildenhues, Richard Hartmann

Hi Michael,

On 2015-05-29 11:53, Michael J Gruber wrote:
> Johannes Schindelin venit, vidit, dixit 26.05.2015 14:35:
>> 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`.
> 
> Isn't that basically the approach that "git checkout --to" is taking? Is
> that one "Windows proof"? I've lost track of its status, though.

I haven't tried `git checkout --to` on Windows yet, and sadly I won't be able to do that for another week...

Ciao,
Dscho

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2015-05-29 10:52 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CADBZQ5iAKsSrdvBnFcdPcm9psaJo5B-H1zqJj0aRc+xx6cCFMQ@mail.gmail.com>
2015-05-26  4:03 ` [PATCH] git-new-workdir: add windows compatibility Junio C Hamano
2015-05-26  9:53   ` Johannes Schindelin
2015-05-26 12:20     ` Paul Smith
2015-05-26 12:35       ` Johannes Schindelin
2015-05-29  9:53         ` Michael J Gruber
2015-05-29 10:48           ` Duy Nguyen
2015-05-29 10:52           ` Johannes Schindelin
2015-05-26 16:48   ` Karsten Blees
     [not found]     ` <CADBZQ5hR1L7FPM_Ht00-as5eXw+PMJk1T2P3_ZiHedf0bi-H1w@mail.gmail.com>
2015-05-27  8:17       ` Johannes Schindelin

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).