creationix / jsgit

A command-line git client powered by js-git and node.js
114 stars 15 forks source link

Ability to get only particular files from repo #6

Open vgrichina opened 11 years ago

vgrichina commented 11 years ago

I understand that it isn't a normal use case for Git – but it would be cool to have ability to download only specific files from specific revision. It can be useful for some niche automation use cases, e.g. I really need it to speed-up automatic project configuration at http://hosted-ci.com

I understand that this isn't something that you'd likely want to spend time on – but I'm willing to do it myself, just not sure where to start.

creationix commented 10 years ago

You can do this with minimal effort today. The git remote protocol doesn't allow grabbing a single file directly, but it does allow shallow commits. I implemented this ability. So if you know the commit you want (and it's in some remote branch or tag), just do a shallow commit of that version to a memory backed git db. Then once you have that one commit, walk the file tree till you get the file you want.

Does this sound like it would help with your use case? I can code up an example if you're still stuck.

creationix commented 10 years ago

Also, if your git repos are always on github, I believe they do have a RESTful API for grabbing a single file from a repo at a specific revision. It's not git protocol and thus not covered by js-git, but it might fit your use case.