isaacs/npm — pull request #2482 by guybrush (2012-05-30 11:35:25+00:00)
Title: Cache git remotes

right now `npm install git+ssh://foo.com/bar.git#v0.0.1` will (see https://github.com/isaacs/npm/blob/master/lib/cache.js#L280-326 ):

* clone the git-repo into `/tmp/random`
* then it will checkout the gitref `v0.0.1`
* then it will run `addLocalDirectory(/tmp/random)`

this patch will make it do (u is the git-remote):

1. path.exists(cache+'/.gitRemotes/'+sha1(u)) ? 3. : 2.
2. git clone --bare u cache/.gitRemotes/sha1(u)
3. cd cache/.gitRemotes/sha1(u) && git fetch
4. git clone cache/.gitRemotes/sha1(u) /tmp/random
5. cd /tmp/random && git checkout
6. addLocalDirectory(/tmp/random)

that way npm only needs to clone repositories (per git-remote) 1 time and will use `git fetch` after that