[PING] Issue 535: unc path support

294 views
Skip to first unread message

con...@aleksoft.net

unread,
Feb 7, 2011, 2:58:40 PM2/7/11
to msysGit
Sorry to bother you again, but a variant of a better "Git Bash.vbs"
has been posted three month ago, however it has not received any
comments.
Here is another try. Do you have any objections of including it?

http://code.google.com/p/msysgit/issues/detail?id=535

Alex.

diff --git a/share/WinGit/Git Bash.vbs b/share/WinGit/Git Bash.vbs
index 365189b..6e90fe0 100644
--- a/share/WinGit/Git Bash.vbs
+++ b/share/WinGit/Git Bash.vbs
@@ -1,10 +1,6 @@
+Set WshObj = CreateObject("WScript.Shell")
' If there is an argument, use it as the directory to change to.
If WScript.Arguments.Length=1 Then
- Set WshObj = CreateObject("WScript.Shell")
- WshObj.CurrentDirectory = WScript.Arguments(0)
+ path = Replace(wscript.arguments(0),"\","/")
End If
-
-' Launch the shortcut in the current directory which has the same
-' base name as this script.
-Set AppObj = CreateObject("Shell.Application")
-AppObj.ShellExecute(Replace(WScript.ScriptFullName, ".vbs", ".lnk"))
+WshObj.run("bash.exe -c 'cd """ & path & """ && bash -il'")

Erik Faye-Lund

unread,
Feb 7, 2011, 3:09:47 PM2/7/11
to con...@aleksoft.net, msysGit
On Mon, Feb 7, 2011 at 8:58 PM, <con...@aleksoft.net> wrote:
> Sorry to bother you again, but a variant of a better "Git Bash.vbs"
> has been posted three month ago, however it has not received any
> comments.
> Here is another try. Do you have any objections of including it?
>

Thanks for sending this to the mailing list. I don't know VBscript, so
I can't comment on the validity of the patch myself, but I'd like to
point out that you should probably resend it as a proper patch (with a
commit-message describing what the patch does and all).

Then, if no one objects, it will probably be merged.

> http://code.google.com/p/msysgit/issues/detail?id=535
>
> Alex.
>
> diff --git a/share/WinGit/Git Bash.vbs b/share/WinGit/Git Bash.vbs
> index 365189b..6e90fe0 100644
> --- a/share/WinGit/Git Bash.vbs
> +++ b/share/WinGit/Git Bash.vbs
> @@ -1,10 +1,6 @@
> +Set WshObj = CreateObject("WScript.Shell")
>  ' If there is an argument, use it as the directory to change to.
>  If WScript.Arguments.Length=1 Then
> -    Set WshObj = CreateObject("WScript.Shell")
> -    WshObj.CurrentDirectory = WScript.Arguments(0)
> +    path = Replace(wscript.arguments(0),"\","/")
>  End If
> -
> -' Launch the shortcut in the current directory which has the same
> -' base name as this script.
> -Set AppObj = CreateObject("Shell.Application")
> -AppObj.ShellExecute(Replace(WScript.ScriptFullName, ".vbs", ".lnk"))
> +WshObj.run("bash.exe -c 'cd """ & path & """ && bash -il'")
>

You're killing all the comments, probably because they'd become stale
otherwise. But perhaps you should add some new ones to describe what
the code does?

con...@aleksoft.net

unread,
Feb 9, 2011, 1:29:55 PM2/9/11
to msysGit
On Feb 7, 12:09 pm, Erik Faye-Lund <kusmab...@gmail.com> wrote:
> Thanks for sending this to the mailing list. I don't know VBscript, so
> I can't comment on the validity of the patch myself, but I'd like to
> point out that you should probably resend it as a proper patch (with a
> commit-message describing what the patch does and all).
>
> Then, if no one objects, it will probably be merged.
>
>
> >http://code.google.com/p/msysgit/issues/detail?id=535
>

Here is another patch. The first version assumed that the git\bin
folder
was on the PATH. This version removes this assumption and
unconditionally
adds the git\bin to the process level PATH environment variable,
it does not affect other processes and is discarded when the running
script quits.

BTW, I had some problem applying the patches containing CRLF line
endings
in either a file to be patched or the patch files, is this a known
issue?
But that's another topic anyway...

Alex.

From e1a935a46a3729a3ec7399cca67f8e1c5c9cba0c Mon Sep 17 00:00:00 2001
From: Alex <vo...@aleksoft.net>
Date: Wed, 9 Feb 2011 09:42:26 -0800
Subject: [PATCH] New Git Bash.vbs

This version of "Git Bash.vbs" allows "Git Bash Here" shell
extention to be started from a UNC share (\\server\share\etc\etc).
If the script is invoked from a windows shell, the Arguments(0)
contains the path to the directory where it's been invoked from;
we simply replace backslashes with forward slashes needed by bash,
then start bash and ask it to cd either into our directory
or $HOME (if the path is null).

Signed-off-by: Alex Ivanov <vo...@aleksoft.net>
---
share/WinGit/Git Bash.vbs | 24 ++++++++++++++----------
1 files changed, 14 insertions(+), 10 deletions(-)
rewrite share/WinGit/Git Bash.vbs (98%)

diff --git a/share/WinGit/Git Bash.vbs b/share/WinGit/Git Bash.vbs
dissimilarity index 98%
index 365189b..6b78154 100644
--- a/share/WinGit/Git Bash.vbs
+++ b/share/WinGit/Git Bash.vbs
@@ -1,10 +1,14 @@
-' If there is an argument, use it as the directory to change to.
-If WScript.Arguments.Length=1 Then
- Set WshObj = CreateObject("WScript.Shell")
- WshObj.CurrentDirectory = WScript.Arguments(0)
-End If
-
-' Launch the shortcut in the current directory which has the same
-' base name as this script.
-Set AppObj = CreateObject("Shell.Application")
-AppObj.ShellExecute(Replace(WScript.ScriptFullName, ".vbs", ".lnk"))
+' If the script invoked from a windows shell, the Arguments(0)
+' contains the path to the directory where it's been invoked from;
+' we simply replace backslashes with forward slashes needed by bash.
+Set WshObj = CreateObject("WScript.Shell")
+' In case the git\bin is not in the %PATH%
+' add it to the current process' PATH so the WshObj.Run could find it
+dir =
Left(WScript.ScriptFullName,InStrRev(WScript.ScriptFullName,"\")) &
"bin"
+WshObj.Environment("process").Item("PATH") =
WshObj.Environment("process").Item("PATH") & ";" & dir
+If WScript.Arguments.Length = 1 Then
+ path = Replace(wscript.arguments(0),"\","/")
+End If
+' Run the bash and ask it to cd into our directory
+' or $HOME (if the path is null).
+WshObj.run("bash.exe -c 'cd """ & path & """ && bash -il'")
--
1.7.4.msysgit.0



Johannes Schindelin

unread,
Feb 17, 2011, 7:04:04 AM2/17/11
to con...@aleksoft.net, msysGit
Hi,

On Wed, 9 Feb 2011, con...@aleksoft.net wrote:

> On Feb 7, 12:09�pm, Erik Faye-Lund <kusmab...@gmail.com> wrote:
> > Thanks for sending this to the mailing list. I don't know VBscript, so
> > I can't comment on the validity of the patch myself, but I'd like to
> > point out that you should probably resend it as a proper patch (with a
> > commit-message describing what the patch does and all).
> >
> > Then, if no one objects, it will probably be merged.
> >
> >
> > >http://code.google.com/p/msysgit/issues/detail?id=535
>
> Here is another patch. The first version assumed that the git\bin folder
> was on the PATH. This version removes this assumption and
> unconditionally adds the git\bin to the process level PATH environment
> variable, it does not affect other processes and is discarded when the
> running script quits.

I lean towards applying it without review if there is nobody can review
it, since you obviously put in some amount of work, and I do not want to
let this be spent in vain.

Objections, anyone?

Ciao,
Dscho

Pat Thoyts

unread,
Feb 17, 2011, 8:54:24 AM2/17/11
to Johannes Schindelin, con...@aleksoft.net, msysGit
On 17 February 2011 12:04, Johannes Schindelin

Objection.

Quickly trying this out shows some problems. I assume the last
attachment is the right one. On my system I have git installed with
use git from cmd prompt so none of git is actually in my PATH except
the git.cmd script. Doing
wscript "c:\Program Files (x86)\Git\Git Bash.vbs" c:\src\git.git
works with the old version but does not work with the new version. I
get 'The system cannot find the file specified' - it can't find
'bash.exe'

Fixing it to use the actual path to bash.exe on my system results in a
shell window flashing up then disappearing immediately.

Also - if no argument is provided, the 'path' variable will be
undefined by the last line.

Johannes Schindelin

unread,
Feb 17, 2011, 9:23:00 AM2/17/11
to Pat Thoyts, con...@aleksoft.net, msysGit
Hi,

Thanks.

Alex, do you think you can fix it without a flashing cmd window?

Ciao,
Dscho

Pat Thoyts

unread,
Feb 17, 2011, 10:22:47 AM2/17/11
to Johannes Schindelin, con...@aleksoft.net, msysGit
On 17 February 2011 14:23, Johannes Schindelin

The following appears to work for me. I suspect using
%ProgramFiles(x86)% is wrong for non-x64 people and possibly should be
using FileSystemObject.GetTemporaryFolder() or something. In this
version I create a temporary shotcut and launch that. All the various
attempts to execute bash -c 'cd somewhere; bash --login -i' failed to
work in some way or another.

--- begin ---
Option Explicit

Dim shell, path, bash, code, temp
Set shell = CreateObject("WScript.Shell")
bash = shell.ExpandEnvironmentStrings("%ProgramFiles(x86)%") &
"\Git\bin\bash.exe"
temp = shell.ExpandEnvironmentStrings("%TEMP%")

Dim link : Set link = shell.CreateShortCut(temp & "\gitlaunch.lnk")
link.TargetPath = bash
link.Arguments = "--login -i"
link.WindowStyle = 1
If WScript.Arguments.Length > 0 Then link.WorkingDirectory =
WScript.Arguments(0)
link.Save

Dim app : Set app = CreateObject("Shell.Application")
app.ShellExecute(temp & "\gitlaunch.lnk")
--- end ---

Pat Thoyts

unread,
Feb 17, 2011, 10:59:06 AM2/17/11
to Johannes Schindelin, con...@aleksoft.net, msysGit

I just realised that what I tested is the last attachment on the
msysGit issue 535 - but there is also a patch in this thread - which I
didn't see.

Pat Thoyts

unread,
Feb 17, 2011, 11:20:05 AM2/17/11
to Johannes Schindelin, con...@aleksoft.net, msysGit
From ef5e137a010a6b3cc526c081b7daf554240c1abc Mon Sep 17 00:00:00 2001
From: Pat Thoyts <patt...@users.sourceforge.net>
Date: Thu, 17 Feb 2011 16:14:50 +0000
Subject: [PATCH] issue #535: support UNC paths for the "Git Bash Here"
explorer menu item.

As pointed out in issue #535 the explorer integration menu item does not
open UNC paths. This patch creates a temporary shortcut item with the
target path set before it executes the bash program and solves this issue.

Suggested-by: Alex Ivanov <vo...@aleksoft.net>
Signed-off-by: Pat Thoyts <patt...@users.sourceforge.net>
---

Looking again at the patch in this thread - it does work ok. However
we get two bash
shells running now where we might just have one if we go with my
approach of creating
a temporary shortcut. I took the method of identifying the Git
location from the previous
patch and added this to my version to create this one.

I reckon this provides the best of both -- needs checking on 32 bit
Windows by someone.

share/WinGit/Git Bash.vbs | 26 +++++++++++++++++---------
1 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/share/WinGit/Git Bash.vbs b/share/WinGit/Git Bash.vbs

index 365189b..0676d22 100644


--- a/share/WinGit/Git Bash.vbs
+++ b/share/WinGit/Git Bash.vbs

@@ -1,11 +1,18 @@


-' If there is an argument, use it as the directory to change to.
-If WScript.Arguments.Length=1 Then
- Set WshObj = CreateObject("WScript.Shell")
- WshObj.CurrentDirectory = WScript.Arguments(0)
-End If

+Option Explicit

-' Launch the shortcut in the current directory which has the same
-' base name as this script.
-Set AppObj = CreateObject("Shell.Application")
-AppObj.ShellExecute(Replace(WScript.ScriptFullName, ".vbs", ".lnk"))

+Dim shell : Set shell = CreateObject("WScript.Shell")
+Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
+Dim gitdir : gitdir =
Left(WScript.ScriptFullName,InStrRev(WScript.ScriptFullName,"\"))
+Dim bash : bash = fso.BuildPath(gitdir, "bin\sh.exe")
+Dim linkfile : linkfile = fso.GetTempName() & ".lnk"
+
+Dim link : Set link = shell.CreateShortCut(linkfile)
+link.TargetPath = bash
+link.Arguments = "--login -i"
+link.WindowStyle = 1
+If WScript.Arguments.Length > 0 Then link.WorkingDirectory =
WScript.Arguments(0)
+link.Save
+
+Dim app : Set app = CreateObject("Shell.Application")
+app.ShellExecute linkfile
+fso.DeleteFile linkfile
--
1.7.4.msysgit.0

Johannes Schindelin

unread,
Feb 17, 2011, 11:47:07 AM2/17/11
to Pat Thoyts, con...@aleksoft.net, msysGit
Hi,

This is why I don't like attachments in Bug trackers.

Anyway, I think we're good to go; hopefully Alex will give his ACK?

Ciao,
Dscho

alex

unread,
Feb 17, 2011, 8:02:12 PM2/17/11
to Johannes Schindelin, Pat Thoyts, con...@aleksoft.net, msysGit
>>> Dim link : Set link = shell.CreateShortCut(temp& "\gitlaunch.lnk")

>>> link.TargetPath = bash
>>> link.Arguments = "--login -i"
>>> link.WindowStyle = 1
>>> If WScript.Arguments.Length> 0 Then link.WorkingDirectory =
>>> WScript.Arguments(0)
>>> link.Save
>>>
>>> Dim app : Set app = CreateObject("Shell.Application")
>>> app.ShellExecute(temp& "\gitlaunch.lnk")

>>> --- end ---
>>>
>> I just realised that what I tested is the last attachment on the
>> msysGit issue 535 - but there is also a patch in this thread - which I
>> didn't see.
> This is why I don't like attachments in Bug trackers.
>
> Anyway, I think we're good to go; hopefully Alex will give his ACK?
>
> Ciao,
> Dscho
I get access denied on this line 50% of time on the last line
fso.DeleteFile linkfile
Inserting wscript.sleep(500) immediately above it fixed the problem.
Otherwise it works ok.

Alex.
---

diff --git a/share/WinGit/Git Bash.vbs b/share/WinGit/Git Bash.vbs

index ce280f8..a85e6fc 100644


--- a/share/WinGit/Git Bash.vbs
+++ b/share/WinGit/Git Bash.vbs

@@ -1,10 +1,18 @@


-' If there is an argument, use it as the directory to change to.
-If WScript.Arguments.Length=1 Then
- Set WshObj = CreateObject("WScript.Shell")
- WshObj.CurrentDirectory = WScript.Arguments(0)
-End If

+Option Explicit

-' Launch the shortcut in the current directory which has the same
-' base name as this script.
-Set AppObj = CreateObject("Shell.Application")
-AppObj.ShellExecute(Replace(WScript.ScriptFullName, ".vbs", ".lnk"))

+Dim shell : Set shell = CreateObject("WScript.Shell")
+Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
+Dim gitdir : gitdir = Left(WScript.ScriptFullName,InStrRev(WScript.ScriptFullName,"\"))
+Dim bash : bash = fso.BuildPath(gitdir, "bin\sh.exe")
+Dim linkfile : linkfile = fso.GetTempName() & ".lnk"
+
+Dim link : Set link = shell.CreateShortCut(linkfile)
+link.TargetPath = bash
+link.Arguments = "--login -i"
+link.WindowStyle = 1

+If WScript.Arguments.Length > 0 Then link.WorkingDirectory = WScript.Arguments(0)
+link.Save
+Dim app : Set app = CreateObject("Shell.Application")
+app.ShellExecute linkfile
+wscript.sleep(500)
+fso.DeleteFile linkfile


Pat Thoyts

unread,
Feb 18, 2011, 3:47:11 AM2/18/11
to alex, Johannes Schindelin, con...@aleksoft.net, msysGit

OK - I've added that plus GetTempName just makes a file name so I had
to join it to the path to the temporary directory or it tried to
create the shortcut in %windir% when launched from explorer.
With these two additional fixes its pushed to devel now.

Pat Thoyts

Johannes Schindelin

unread,
Feb 18, 2011, 5:32:29 AM2/18/11
to Pat Thoyts, alex, con...@aleksoft.net, msysGit
Hi,

On Fri, 18 Feb 2011, Pat Thoyts wrote:

> On 18 February 2011 01:02, alex <ale...@aleksoft.net> wrote:
> > I get access denied on this line 50% of time on the last line
> > fso.DeleteFile linkfile
> >
> > Inserting wscript.sleep(500) immediately above it fixed the problem.
> > Otherwise it works ok.
>

> OK - I've added that plus GetTempName just makes a file name so I had to
> join it to the path to the temporary directory or it tried to create the
> shortcut in %windir% when launched from explorer. With these two
> additional fixes its pushed to devel now.

Thanks, both!
Dscho

Reply all
Reply to author
Forward
0 new messages