4

I want to curl a git tag through the command line:

curl -O http://someurl

But when I try to untar the file it is broken? Do anyone know what is the problem?

einstein
  • 13,389
  • 27
  • 80
  • 110

3 Answers3

4

You can curl a git tag from a git repos hosting service like GitHub, because it has a dedicated tarball service (like Nodeload) which provides tar (or zip). But not any other git repo out there has that same service.

See "Having trouble downloading Git archive tarballs from Private Repo" for a concrete example with GitHub (or this curl GitHub tutorial):

curl -sL --user "${username}:${password}" https://github.com/$account/$repo/tarball/$tag_name > tarball.tar

On a public repo:

curl -L https://github.com/pinard/Pymacs/tarball/v0.24-beta2 | tar zx
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Do you know how to change the name of the extract folder. Now it is username-repo-commithash. Is there a way to rename it? I have tried several solution nad it didn't work for me – einstein Jan 04 '13 at 06:48
  • I have tried `curl -L https://github.com/tinganho/yeoman/tarball/v.p1.0.9.0 > yeoman.tar.gz && tar -xvf yeoman.tar.gz -C node_modules` – einstein Jan 04 '13 at 06:49
  • @Woho87 no, because that root directory is part of the elements included in this tar (in your case, I suspect you would get `node_modules/username-repo-commithash/...`). You need to add an extra step which will detect the most recent directory created (starting with `${username}`), and rename it. – VonC Jan 04 '13 at 06:51
  • @Woho87 sure: `ls -1t "${username}*"|head -n1` – VonC Jan 04 '13 at 06:56
  • Do you happen to know how to pipe the output of `ls -rt | tail -1` toa `mv command`? I cannot change the name of the folder now – einstein Jan 04 '13 at 07:07
  • @Woho87 pipe? No. I simply store the result in a variable and use that variable. See an example of that technique in https://github.com/VonC/compileEverything/blob/master/.cpl/params/aliensvn#L2 – VonC Jan 04 '13 at 07:12
  • Never mind I found out http://stackoverflow.com/questions/937716/how-do-you-send-the-output-of-ls-to-mv – einstein Jan 04 '13 at 07:12
  • 1
    @Woho87 that will work too :) I prefer the intermediate steps from my script. – VonC Jan 04 '13 at 07:15
3

git itself doesn't provide a http-interface. A solution is to use git archive instead

git clone http://example.com/myrepo.git
git archive mytag > myrepo-mytag.tar.gz
KingCrunch
  • 128,817
  • 21
  • 151
  • 173
  • +1. This is a more git-native solution than my answer. (Although it does involve a *local* clone) – VonC Dec 31 '12 at 13:32
  • @VonC I don't think a local clone is a real problem, because your can remove it anytime with `rm -Rf myrepo.git`. But I my experience something like this occurs more often, so you can keep the clone and use it as the local platform for packaging :) Sooner or later one wants to run tests or something like that, before packaging, and in this case the sources are already available. – KingCrunch Jan 01 '13 at 01:31
2

If you need to fetch only the minimum necessary,

git init temp
cd temp
git remote add x http://example.com/repo.git
git fetch x sometag --depth=1
git archive FETCH_HEAD > ../repo.sometag.tgz
cd ..
rm -rf temp

will do ya

jthill
  • 55,082
  • 5
  • 77
  • 137
  • So, what is the benefit compared to a real clone? And please don't say "saving space" – KingCrunch Jan 01 '13 at 01:31
  • He wants a tarball, not a repo. For a large project like linux or blender-full or whatnot, this saves well over a gigabyte of network traffic. (edit: <-- I didn't say "space", see? :-) – jthill Jan 01 '13 at 01:37
  • For such a large (foreign!!!) project I hope there is already a tarball (or zip or whatever) to download somewhere... I guess it's about an own, or at least an affiliated project and therefore a little effort wont hurt. Yes, network _may be_ a point, but it depends on the country you live in :X Here in Germany I would absolutely never pull a repo via mobile access. Oh, and not to forget: Once you cloned the repo later pulls will only fetch the changes :) – KingCrunch Jan 01 '13 at 02:04
  • No question, clone gives you _major_ long-term benefits. But this does what OP specifically asked for and I don't think the difference between seconds and minutes is to be ignored, even if it's unlikely to happen. – jthill Jan 01 '13 at 02:17
  • You are going to confuse me ... What are you talking about? My last argument was only about whether, or not you want to pack this "thing" once, or often. But my _main_ question is: Whats the benefit of your solution compared to a straight forward and simple `git clone`? (except that one save bandwith and space ;)) – KingCrunch Jan 01 '13 at 02:26
  • It seemed to me I answered that. Still does. A full clone on a large project will take minutes. A --depth=1 fetch of a single tag will take seconds. That matters. – jthill Jan 01 '13 at 02:31
  • Finally +1. Maybe I made it too complicated (but look at the calendar). It's a solution that makes sense in particular situations. – KingCrunch Jan 01 '13 at 02:43
  • my last reply was much clearer about what I was trying to avoid than the earlier ones, I could have just said it up front, but, well, look at the calendar ... – jthill Jan 01 '13 at 03:12