From ff2e993343f689312a51c1bbbf620c05e41a4f62 Mon Sep 17 00:00:00 2001 From: Scott Prager Date: Fri, 5 Jun 2015 13:15:36 -0400 Subject: Use `git ls-remote` to get local refs. `git ls-remote` gives us the same info as `git-upload-pack`, but in an easier to parse format. We can also share the code for interpreting `git ls-remote` between git-remote-gittorrent and gittorrentd. This also fixes the problem of `publish_mutable_key()` being called too soon. --- git.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 git.js (limited to 'git.js') diff --git a/git.js b/git.js new file mode 100644 index 0000000..cd9efe3 --- /dev/null +++ b/git.js @@ -0,0 +1,27 @@ +#!/usr/bin/env node + +var spawn = require('child_process').spawn + +// Returns a process running `git ls-remote ` that calls `with_ref` on +// each parsed reference. The url may point to a local repository. +function ls (url, with_ref) { + var ls = spawn('git', ['ls-remote', url]) + ls.stdout.on('data', function (lines) { + lines.toString().split('\n').forEach(function (line) { + if (!line || line === '') { + return + } + line = line.split('\t') + var sha = line[0] + var branch = line[1] + if (sha.length !== 40) { + console.warn('[git ls-remote] expected a 40-byte sha: ' + sha + '\n') + console.warn('[git ls-remote] on line: ' + line.join('\t')) + } + with_ref(sha, branch) + }) + }) + return ls +} + +module.exports = {ls: ls} -- cgit v1.2.3