How to unzip a (windows.zip) file from Msysgit?

1,927 views
Skip to first unread message

Philip Oakley

unread,
Sep 26, 2011, 6:09:27 PM9/26/11
to Git MsysGit
I'm trying to create a script that will unzip a windows.zip file as part of
a git commit script. The zip contains a full directory of source code.

The step I'm stuck on is, finding the right way to get at an unzip method
from within a git script. (see
http://stackoverflow.com/questions/7535311/is-there-an-opposite-command-to-git-archive-for-importing-zip-files)

I'm trying this on an XP netbook.
I have the full msysgit, with source code, which includes 7-zip, and I have
7-zip and Filzip on the XP side of the platform.

I can't seem to either get a $ cmd dos_script.bat command line to execute
a dos batch file, (I can't locate a manual page for the passing of
parameters from the bash to the cmd command, so I'm not sure it even sees
the batch file name I've given it)

Also I'm not sure how, or if, I can get the C:\msysgit\share\7-Zip code to
be usable from the bash - I'm pretty sure that this directory is the Windows
version used for packaging the MSysGit, rather than being an available
utility for the bash - but I thought I'd better mention it.

Can anyone suggest how I can do the unzip (of a directory) step in the git
script from the available MSysGit installation code, without jumping into
some 'dependency hell' ;-)

Philip

Pat Thoyts

unread,
Sep 27, 2011, 10:18:57 AM9/27/11
to Philip Oakley, Git MsysGit

There is a copy of unzip in the msysgit bin/ directory of the msysGit
build tree. So:
#!/bin/sh
unzip $1
would be a trivial unzip script. The 7za.exe will unzip files too.
Just call it: 7za x zipfile. Both of these will recreate the tree
structure from the archive.

Philip Oakley

unread,
Sep 27, 2011, 4:08:55 PM9/27/11
to Pat Thoyts, Git MsysGit
From: "Pat Thoyts" <patt...@gmail.com>
Subject: Re: [msysGit] How to unzip a (windows.zip) file from Msysgit?

----
I now see my mistake. I had been starting up an old bash (from a right click
menu option) which was for a plain 'git for windows' bash (version
1.7.3.1-preview20101002 !).

I have now started the MsysGit (Welcome to msysGit; git version 1.7.6.GIT)
via my Start>programmes menu. I had added that menu when I installed the
full msysgit.

This now gave me access to the unzip, which the old bash didn't. (learning
point ;-)

A bit of a 'Doh' moment, but we have to go through these occasionally to see
the woods for the trees.

Philip

Philip Oakley

unread,
Sep 27, 2011, 5:38:04 PM9/27/11
to Pat Thoyts, Git MsysGit
From: "Philip Oakley" <philip...@iee.org>
> From: "Pat Thoyts" <patt...@gmail.com>

However, for a 'Git for Windows' basic user, how would they get the script
to run, given that it doesn't appear to have the unzip available to them. Or
is that a limitaion of the Git for Windows basic installation?

Philip

Sebastian Schuberth

unread,
Sep 28, 2011, 6:07:26 AM9/28/11
to Philip Oakley, Pat Thoyts, Git MsysGit
On 27.09.2011 23:38, Philip Oakley wrote:

>> I now see my mistake. I had been starting up an old bash (from a right
>> click menu option) which was for a plain 'git for windows' bash
>> (version 1.7.3.1-preview20101002 !).
>>
>> I have now started the MsysGit (Welcome to msysGit; git version
>> 1.7.6.GIT) via my Start>programmes menu. I had added that menu when I
>> installed the full msysgit.
>>
>> This now gave me access to the unzip, which the old bash didn't.
>> (learning point ;-)
>>
>> A bit of a 'Doh' moment, but we have to go through these occasionally
>> to see the woods for the trees.
>>
>> Philip
>
> However, for a 'Git for Windows' basic user, how would they get the
> script to run, given that it doesn't appear to have the unzip available
> to them. Or is that a limitaion of the Git for Windows basic installation?

I'm not sure what you call "basic installation" installation here. No
matter what features you (de-)select in the installer, you always get
all the files in your installation directory. Only some configuration
stuff changes.

So here's what I think happened to you: At some point you installed
version 1.7.3.1 and chose to install the Windows Explorer "Git Bash"
context menu entries.

Later, you installed version 1.7.6 in parallel (not updating the
existing version 1.7.3.1) but chose *not* to install the context menu
entries. This means these entries still launch version 1.7.3.1, while
the Start Menu entries were updated and launch version 1.7.6.

My guess is that version 1.7.3.1 did not come with the unzip script yet,
but version 1.7.6 does. So the easiest way to fix this would be to
uninstall version 1.7.3.1 and reinstall 1.7.6 with the option to install
the Windows Explorer context menus checked.

--
Sebastian Schuberth

Erik Faye-Lund

unread,
Sep 28, 2011, 6:20:15 AM9/28/11
to Sebastian Schuberth, Philip Oakley, Pat Thoyts, Git MsysGit

I don't think that's it. I believe the difference is Git for Windows
vs msysGit. msysGit includes unzip, while Git for Windows does not.

Basicly, Git for Windows is a Git (including a minimal runtime
environment), while msysGit is a fully blown msys-based development
environment.

Stuffing all kinds of sometimes-useful-but-not-really-essential tools
into the Git for Windows distribution will end up bloating it, which
is the reason why non-essential tools aren't included.

So the answer to the question would be that you had to download a
unzip tool from somewhere before the script can run. Just the same way
you'd have to for another git-unrelated tool.

Alternatively, you could install msysGit rather than Git for Windows,
but it isn't quite as nicely packaged.

Sebastian Schuberth

unread,
Sep 28, 2011, 6:28:07 AM9/28/11
to kusm...@gmail.com, Philip Oakley, Pat Thoyts, Git MsysGit
On Wed, Sep 28, 2011 at 12:20, Erik Faye-Lund <kusm...@gmail.com> wrote:

> I don't think that's it. I believe the difference is Git for Windows
> vs msysGit. msysGit includes unzip, while Git for Windows does not.

You're right, Erik, this sounds more likely.

--
Sebastian Schuberth

Erik Faye-Lund

unread,
Sep 28, 2011, 6:57:40 AM9/28/11
to Sebastian Schuberth, Philip Oakley, Pat Thoyts, Git MsysGit, Johannes Schindelin
On Wed, Sep 28, 2011 at 12:20 PM, Erik Faye-Lund <kusm...@gmail.com> wrote:
> Stuffing all kinds of sometimes-useful-but-not-really-essential tools
> into the Git for Windows distribution will end up bloating it, which
> is the reason why non-essential tools aren't included.

Looking a bit more at the distribution, I'm not sure I completely
agree with myself on this point: We already distribute gzip, gunzip,
bzip and bunzip. Perhaps it would make sense to also include unzip in
the distribution?

Thoughts?

---
diff --git a/share/WinGit/copy-files.sh b/share/WinGit/copy-files.sh
index 9b7f0fa..3e9f12b 100755
--- a/share/WinGit/copy-files.sh
+++ b/share/WinGit/copy-files.sh
@@ -48,7 +48,8 @@
ls.exe,m4.exe,md5sum.exe,mkdir.exe,msys-1.0.dll,msysltdl-3.dll,mv.exe,patch.exe,
patch.exe.manifest,perl.exe,printf,ps.exe,pwd,rm.exe,rmdir.exe,rxvt.exe,\
scp.exe,sed.exe,sh.exe,sleep.exe,sort.exe,split.exe,\
ssh-agent.exe,ssh.exe,ssh-add.exe,ssh-keygen.exe,ssh-keyscan.exe,\
-tail.exe,tar.exe,tee.exe,touch.exe,tr.exe,true.exe,uname.exe,uniq.exe,vi,\
+tail.exe,tar.exe,tee.exe,touch.exe,tr.exe,true.exe,uname.exe,uniq.exe,\
+unzip.exe,vi,\
msys-perl5_8.dll,lib{apr,aprutil,expat,neon,z,svn}*.dll,pthreadGC2.dll,\
msys-crypto-0.9.8.dll,msys-regex-1.dll,msys-ssl-0.9.8.dll,msys-minires.dll,msys-z.dll,\
openssl.exe,vim,wc.exe,which,xargs.exe,start} lib/engines/ \

Sebastian Schuberth

unread,
Sep 28, 2011, 7:44:59 AM9/28/11
to kusm...@gmail.com, Philip Oakley, Pat Thoyts, Git MsysGit, Johannes Schindelin
On Wed, Sep 28, 2011 at 12:57, Erik Faye-Lund <kusm...@gmail.com> wrote:

> Looking a bit more at the distribution, I'm not sure I completely
> agree with myself on this point: We already distribute gzip, gunzip,
> bzip and bunzip. Perhaps it would make sense to also include unzip in
> the distribution?
>
> Thoughts?

Looks good to me. As we're a Windows distribution of Git, we should
include an (un)zip tool for the zip format that is most common on
Windows.

Please commit to devel.

--
Sebastian Schuberth

Johannes Schindelin

unread,
Sep 28, 2011, 12:41:10 PM9/28/11
to Erik Faye-Lund, Sebastian Schuberth, Philip Oakley, Pat Thoyts, Git MsysGit
Hi,

On Wed, 28 Sep 2011, Erik Faye-Lund wrote:

> On Wed, Sep 28, 2011 at 12:20 PM, Erik Faye-Lund <kusm...@gmail.com> wrote:
> > Stuffing all kinds of sometimes-useful-but-not-really-essential tools
> > into the Git for Windows distribution will end up bloating it, which
> > is the reason why non-essential tools aren't included.
>
> Looking a bit more at the distribution, I'm not sure I completely
> agree with myself on this point: We already distribute gzip, gunzip,
> bzip and bunzip. Perhaps it would make sense to also include unzip in
> the distribution?
>
> Thoughts?

No objections from my side!

Ciao,
Dscho

Eric Sunshine

unread,
Sep 28, 2011, 2:37:38 PM9/28/11
to kusm...@gmail.com, Sebastian Schuberth, Philip Oakley, Pat Thoyts, Git MsysGit, Johannes Schindelin
On 9/28/2011 6:57 AM, Erik Faye-Lund wrote:
> Looking a bit more at the distribution, I'm not sure I completely
> agree with myself on this point: We already distribute gzip, gunzip,
> bzip and bunzip. Perhaps it would make sense to also include unzip in
> the distribution?

For the other compression mechanisms, both the compressor and
uncompressor are shipped (gzip/gunzip and bzip2/bunzip2), so why ship
only an uncompressor for ZIP? Shipping both zip and unzip, rather than
only unzip, seems like a good idea.

-- ES

Johannes Schindelin

unread,
Sep 28, 2011, 3:42:13 PM9/28/11
to Eric Sunshine, kusm...@gmail.com, Sebastian Schuberth, Philip Oakley, Pat Thoyts, Git MsysGit
Hi Eric,

Sure. Where is the patch?

Ciao,
Dscho

Erik Faye-Lund

unread,
Sep 28, 2011, 5:32:46 PM9/28/11
to Eric Sunshine, Sebastian Schuberth, Philip Oakley, Pat Thoyts, Git MsysGit, Johannes Schindelin

That'd be a brilliant idea if we only had a zip-binary. We don't, so
I'll leave that part to someone else... ;)

Philip Oakley

unread,
Sep 28, 2011, 6:16:58 PM9/28/11
to Eric Sunshine, kusm...@gmail.com, Sebastian Schuberth, Pat Thoyts, Git MsysGit, Johannes Schindelin
To: <kusm...@gmail.com>

For the particular workflow I had in mind, the zip side is done on the
Windows side of the fence, e.g. by compressing a project folder.

This way (being able to unzip such project zip files and commit them into
git) allows the easy 'capture' of such zip storage based workflows that
happen at a low level (It's a method my project uses for day to day
storage).

That's not to say that having the matching pair wouldn't be the expected
capability. Having the zip/unzip capablity directly available on the
'linux/bash' side of the fence makes it a complete solution, and allows
simple scripts.

Philip

Philip Oakley

unread,
Sep 28, 2011, 7:02:58 PM9/28/11
to kusm...@gmail.com, Sebastian Schuberth, Pat Thoyts, Git MsysGit
From: "Erik Faye-Lund" <kusm...@gmail.com>

Correct - That's my situation / misunderstanding

>
> Stuffing all kinds of sometimes-useful-but-not-really-essential tools
> into the Git for Windows distribution will end up bloating it, which
> is the reason why non-essential tools aren't included.
>
> So the answer to the question would be that you had to download a
> unzip tool from somewhere before the script can run. Just the same way
> you'd have to for another git-unrelated tool.

One of my 'lack of understandings' is about whether Msysgit could even run
regular windows programmes, such as WinZip (for example) from the bash
prompt -- that is, I had assumed that Windows programes were separate from
the Linux programmes, on the basis that the two sorts of programmes hooked
into the OS by different routes. Is this the case? or had I misled myself
and I can run say the 7-zip.exe directly from the bash prompt, even though I
have the windows version installed?

Sebastian Schuberth

unread,
Sep 29, 2011, 3:46:01 AM9/29/11
to Philip Oakley, kusm...@gmail.com, Pat Thoyts, Git MsysGit
On Thu, Sep 29, 2011 at 01:02, Philip Oakley <philip...@iee.org> wrote:

>> Basicly, Git for Windows is a Git (including a minimal runtime
>> environment), while msysGit is a fully blown msys-based development
>> environment.
>
> Correct - That's my situation / misunderstanding

I'd like to amend that: msysGit is a fully blown msys-based
development environment primarily targeted at developing "Git for
Windows" itself.

> One of my 'lack of understandings' is about whether Msysgit could even run
> regular windows programmes, such as WinZip (for example) from the bash

It can. Think of Msysgit as Windows programs that emulate Linux
behavior. Msysgit executables are regular Windows executables, just
like 7-zip.exe. Msysgit is *not* something like colinux, or Wine the
other way around, or even a virtual machine. It's just a Cygwin fork.

> and I can run say the 7-zip.exe directly from the bash prompt, even though I
> have the windows version installed?

You can. In fact, the files in C:\msysgit\share\7-Zip are the regular
Windows versions, not a special Mingw-compiled version of 7-Zip.

But as the Mingw executables emulate Linux, you have to take care with
the path mangling when passing files to Windows executables from the
Mingw Bash. That is, basically use forward instead of backward
slashes.

--
Sebastian Schuberth

Sebastian Schuberth

unread,
Sep 29, 2011, 3:48:04 AM9/29/11
to kusm...@gmail.com, Eric Sunshine, Philip Oakley, Pat Thoyts, Git MsysGit, Johannes Schindelin
On Wed, Sep 28, 2011 at 23:32, Erik Faye-Lund <kusm...@gmail.com> wrote:

>> For the other compression mechanisms, both the compressor and uncompressor
>> are shipped (gzip/gunzip and bzip2/bunzip2), so why ship only an
>> uncompressor for ZIP? Shipping both zip and unzip, rather than only unzip,
>> seems like a good idea.
>
> That'd be a brilliant idea if we only had a zip-binary. We don't, so
> I'll leave that part to someone else... ;)

I was about to answer the exact same thing :-)

--
Sebastian Schuberth

Karsten Blees

unread,
Sep 29, 2011, 7:07:16 AM9/29/11
to msysGit
On Sep 27, 12:09 am, "Philip Oakley" <philipoak...@iee.org> wrote:
> I'm trying to create a script that will unzip a windows.zip file as part of
> a git commit script. The zip contains a full directory of source code.
>

Hi Philip,

Windows Explorer can open .zip files as ActiveX Shell.Folder objects,
so if you don't mind the Explorer progress dialog popping up, you
could do this:

---
#!/bin/sh

cat > CopyFolder.vbs << EOF
Set oShell=CreateObject("Shell.Application")
oShell.NameSpace(WScript.Arguments(1)).CopyHere
oShell.NameSpace(WScript.Arguments(0)).Items
EOF

cscript CopyFolder.vbs $1 $2
---

Karsten

Philip Oakley

unread,
Sep 29, 2011, 8:39:27 AM9/29/11
to msysGit
That's an interesting approach.

I'd never really thought that I could do that. I've done vbs code for
interfacing a different product (MathCAD), so It should give me a good
start.

Obviously such a script wouldn't be that transferable to the Linux
diehard side of git, but would work well in our msysgit environment.

Philip

Philip Oakley

unread,
Sep 29, 2011, 8:47:33 AM9/29/11
to msysGit
On Sep 29, 8:46 am, Sebastian Schuberth <sschube...@gmail.com> wrote:
> On Thu, Sep 29, 2011 at 01:02, Philip Oakley <philipoak...@iee.org> wrote:
.snip.
> > and I can run say the 7-zip.exe directly from the bash prompt, even though I
> > have the windows version installed?
>
> You can. In fact, the files in C:\msysgit\share\7-Zip are the regular
> Windows versions, not a special Mingw-compiled version of 7-Zip.
>
> But as the Mingw executables emulate Linux, you have to take care with
> the path mangling when passing files to Windows executables from the
> Mingw Bash. That is, basically use forward instead of backward
> slashes.
>
> --
Are there standard routines that do the forward and inverse mangling,
and which ones are 'best' for use in git scripts?
I guessing that there will be advice on the kernal.org site when it
comes back up, but in the mean time..

Philip Oakley

unread,
Sep 29, 2011, 4:25:29 PM9/29/11
to Karsten Blees, msysGit
From: "Karsten Blees" <bl...@dcon.de>

---
Karsten,
The script presumes, I think, that we are using a compressed zip file that
Windows Explorer can interogate automatically. I'm thinking that if someone
used WinZip that we'd have to invoke winzip as the executable (googling
"csript" came up with some useful info - I'd not used/seen 'cscript/wscript'
before).
Also on first reading I didn't notice (I wasn't looking very hard) that you
actually create the CopyFolder.vbs file and populate it with the commands
via the cat command, rather than it simply being a pre-prepared file!

I've included this note for other readers of the list.

-----
No virus found in this message.
Checked by AVG - www.avg.com
Version: 10.0.1410 / Virus Database: 1520/3925 - Release Date: 09/28/11


Reply all
Reply to author
Forward
0 new messages