Skip to content

Commit

Permalink
Implement fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
creationix committed Sep 14, 2013
1 parent 26d7265 commit c3648be
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
32 changes: 32 additions & 0 deletions bin/fetch.js
@@ -0,0 +1,32 @@
#!/usr/bin/env node
var git = require('git-node');
var program = require('commander');

program
.usage('[options] [--] <url>')
.option('--git-dir <dir>', 'Use custom git dir instead of cwd')
.option('-q', 'Be quiet; don\t show progress')
.parse(process.argv);

if (program.args.length !== 1) {
program.outputHelp();
process.exit(1);
}

var url = program.args[0];
var remote = git.remote(url);
var target = require('./root.js')(program);

var repo = git.repo(target);
var opts = {};
if (!program.Q) opts.onProgress = onProgress;
if (!program.Q) console.log("Fetching updates from %s to %s..", url, target);
repo.fetch(remote, opts, onDone);

function onProgress(progress) {
process.stderr.write(progress);
}

function onDone() {
if (!program.Q) console.log("Done.");
}
11 changes: 1 addition & 10 deletions bin/log.js
@@ -1,9 +1,6 @@
#!/usr/bin/env node
var git = require('git-node');
var program = require('commander');
var existsSync = require('fs').existsSync;
var readFileSync = require('fs').readFileSync;
var path = require('path');

program
.usage('[options] [--] [<ref>]')
Expand All @@ -19,13 +16,7 @@ if (program.args.length > 1) {
if (program.limit) program.limit = parseInt(program.limit, 10);

var ref = program.args[0] || "HEAD";
var target = path.resolve(process.cwd(), program.gitDir || '.');
var head = path.join(target, "HEAD");
if (!(existsSync(head) && (/^ref: /).test(readFileSync(head, "utf8")))) {
console.error("Can't find bare repo at %s", target);
process.exit(-1);
}

var target = require('./root.js')(program);

var repo = git.repo(target);
repo.logWalk(ref, function (err, log) {
Expand Down

0 comments on commit c3648be

Please sign in to comment.