3

I' using windows, git bash prompt

I'm trying to use the git archive command with bitbucket

and I receive the error remote: "git upload-archive: archiver died with error"

Any ideas ?

git archive --remote=ssh://git@bitbucket.org/username/reponame.git --format=tar --output="file.tar"

I have created all SSH keys and public keys etc and even tested ssh -v hg@bitbucket.org and it works fine

Shanthi
  • 637
  • 2
  • 7
  • 17
  • 1
    Did you try with a specific tree-ish, like a tag or a branch name? `git archive --remote=ssh://git@bitbucket.org/username/reponame.git --format=tar --output="file.tar" master`? – VonC Aug 22 '12 at 10:51
  • Yes that was it and now it works. Can I also know how to retrieve a particular revision if I know the commit id ? Also is it possible to retrieve ONLY those files changed or added in a particular commit. I do a git archive --remote=ssh://git@bitbucket.org/username/reponame.git --format=tar --output="file.tar" 1f74388a6faa and I receive an error "no such ref" – Shanthi Aug 22 '12 at 12:37
  • A SHA1 wouldn't work, see my answer below. And git-archive retrieves a tree, not a delta. To get only the files that have changed, you would have to get 2 trees and compare them. But to get two tree, you can only specify branch names or tags, not SHA1. – VonC Aug 22 '12 at 12:57

1 Answers1

10

You cannot get just an archive without precising the tree-is you want to get, when you are using --remote

git archive --remote=ssh://git@bitbucket.org/username/reponame.git --format=tar --output="file.tar" master

Would work, mentioning a name of a branch.
That would work too with the name of a tag.

However, according to this thread, a commit ID would not work:

Is there a reason git-archive requires a named ref rather than just a commit (or tree) ID?

Yes; generally git repositories do not allow clients to access arbitrary sha1s. Instead, they require that the requested objects be accessible by a ref.

git-archive was not properly enforcing this, and was changed recently to allow only refs by name, as well as sub-trees of refs (e.g., HEAD:subdir/).
That means we do disallow an arbitrary commit or tree sha1, even if it is reachable from the advertised refs.

would it be difficult to patch git-upload-archive to use the IDs?
I could use tags for the ref, but in my case would result in almost every commit being a tag which seems wasteful.

Doing it right is a bit expensive, because in the general case (somebody requested a tree sha1), we would need to traverse every tree of every commit to see if it is reachable.

We could potentially implement a more restricted set of rules, allowing "<commit>:<subdir>" and checking that <commit> is reachable.
That would disallow an arbitrary tree sha1, but I suspect it would cover the common use case (i.e., you want to get the tree, or even a subtree, of a particular revision).

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250