API for pushing/fetching objects to/from git repositories
Provides simple API for interacting with git repositories remotely. For now only a subset of the packfile protocol and file/ssh/git transports are supported.
npm install git-remote
Consider that we are working from the same context as shown in git-core usage
connect = require'git-remote';// first step is to connect to some remote:remote = connect'/local/repo.git';// orremote = connect'git://somehost/remote/repo.git';// orremote = connect'user@host:remote/repo.git'key: fsreadFileSync'/path/to/ssh/private/key';// fetch datafetch = remotefetch;fetchon'discover'console.log'Remote refs': refs;// retrieve all history of master and topic branchrefs'heads/master'want;refs'heads/topic'want;fetchflush;;fetchon'progress'console.logprogressStatus;;fetchon'fetched'console.log'Master branch latest commit:' fetched'heads/master';console.log'Topic branch latest commit:' fetched'heads/topic';;// It is possible to set the maximum history depth. For example, if all you// need is the tree pointed by a tag or branch:fetch = remotefetch;fetchmaxDepth = 1;fetchon'discover'refs'heads/master'want;fetchflush;;fetchon'fetched'console.logfetched'heads/master'tree;// the 'parents' properties of the commit only contains sha1 strings;// modify a remote repopush = remotepush;pushon'discover'// update the master branch with the c3 and parentsrefs'heads/master'updatec3;// delete a tagrefs'tags/v0.0.1'del;// create a new branch referencing 'c2'pushcreate'heads/new-branch' c2;// flush the commandspushflush;;pushon'pushed'console.logstatus;;
For now, both the git-core/git-remote packages work completely on memory, so don't use this package to retrieve a large amount of objects. If you have enough memory, you can see what I mean by opening node REPL and pasting this:
connect = require'git-remote';remote = connect'git://github.com/torvalds/linux.git';fetch = remotefetch;// never forget maxDepth fetching from big repositories!fetchmaxDepth = 1;fetchon'discover'refs'tags/v2.6.11-tree'want;fetchflush;;fetchon'progress'console.logp;;fetchon'fetched'console.log'Fetched the initial linux import into git. Here is the tag message:';console.logfetched'tags/v2.6.11-tree'message;;
Inspect the process using 'top' or some other tool. The memory usage should go past 400mb.