From: Junio C Hamano <gitster@pobox.com>
To: Daniel Smith <dansmith65@gmail.com>
Cc: git@vger.kernel.org, Paul Smith <paul@mad-scientist.net>,
Jeff King <peff@peff.net>,
Ralf Wildenhues <Ralf.Wildenhues@gmx.de>,
Richard Hartmann <richih@net.in.tum.de>
Subject: Re: [PATCH] git-new-workdir: add windows compatibility
Date: Mon, 25 May 2015 21:03:20 -0700 [thread overview]
Message-ID: <xmqqfv6k7zp3.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <CADBZQ5iAKsSrdvBnFcdPcm9psaJo5B-H1zqJj0aRc+xx6cCFMQ@mail.gmail.com> (Daniel Smith's message of "Mon, 25 May 2015 16:44:28 -0700")
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.
next parent reply other threads:[~2015-05-26 4:03 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CADBZQ5iAKsSrdvBnFcdPcm9psaJo5B-H1zqJj0aRc+xx6cCFMQ@mail.gmail.com>
2015-05-26 4:03 ` Junio C Hamano [this message]
2015-05-26 9:53 ` [PATCH] git-new-workdir: add windows compatibility 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqfv6k7zp3.fsf@gitster.dls.corp.google.com \
--to=gitster@pobox.com \
--cc=Ralf.Wildenhues@gmx.de \
--cc=dansmith65@gmail.com \
--cc=git@vger.kernel.org \
--cc=paul@mad-scientist.net \
--cc=peff@peff.net \
--cc=richih@net.in.tum.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.