1

Recently I saw both this question and this question where the answers say you can use git archive to retrieve a single file from a remote git repository. This is great, and I would like to be able to emulate that functionality using LibGit2Sharp.

I have looked at the source code, but I can't find anything that really does archiving. There's an ArchiverBase class, but this seems like it's just meant to be derived from, and I can't see anything that derives from it. ObjectDatabase has an Archive() method that uses an ArchiverBase parameter, but none of the ArchiverBase methods are really implemented. Do I need to derive ArchiverBase and overwrite its methods myself? How would I go about that? Has it already been done in some other class?

In short, How can I emulate git archive using LibGit2Sharp to retrieve a single file as described in the linked questions?

Community
  • 1
  • 1
wlyles
  • 2,236
  • 1
  • 20
  • 38
  • 1
    There's a concrete implementation for tar in `TarArchiver`, but you cannot point it to a remote repository, only the local repository. – Edward Thomson Jun 20 '14 at 16:45
  • @EdwardThomson Could you please promote that comment into an answer so that I can upvote it? ;p – nulltoken Jun 20 '14 at 17:51
  • @wlyles Ed's right. At this moment, you can't do this through LibGit2Sharp through the archiving feature. You'll have to Clone() the repository. – nulltoken Jun 20 '14 at 17:58

1 Answers1

1

There does happen to be a concrete archiver implementation in LibGit2Sharp, TarArchiver, which will create a tar archive of your local Git repository. However, it will only work against a repository, it will not work against a remote endpoint, so it will not be suitable to retrieve a single file like git archive can.

LibGit2Sharp does not include a way to do what you are asking. Your options are to:

  1. Clone the repository, checking out a single file
  2. Use an API offered by your Git hosting provider (OctoKit for GitHub or the REST API for Team Foundation Server) to retrieve a single file.
  3. Execute git-archive yourself.
Edward Thomson
  • 74,857
  • 14
  • 158
  • 187