diff options
| author | Scott Prager <splinterofchaos@gmail.com> | 2015-06-03 11:39:03 -0400 |
|---|---|---|
| committer | Scott Prager <splinterofchaos@gmail.com> | 2015-06-03 15:01:30 -0400 |
| commit | ca0f11bfa1b8d89e73e40e59c4c1e114c173fc5e (patch) | |
| tree | 2499c71992c4c40c66b2e0b12a805b851208b787 | |
| parent | fc4651256d709259871bd8f28b6e26d884215540 (diff) | |
git-remote: Don't edit .git/refs manually.
Use `$ git update-ref {branch} {sha}` instead.
| -rwxr-xr-x | git-remote-gittorrent | 42 |
1 files changed, 13 insertions, 29 deletions
diff --git a/git-remote-gittorrent b/git-remote-gittorrent index 82c22b4..cd55172 100755 --- a/git-remote-gittorrent +++ b/git-remote-gittorrent @@ -3,7 +3,6 @@ var Chalk = require('chalk') var DHT = require('bittorrent-dht') var exec = require('child_process').exec -var fs = require('fs') var hat = require('hat') var magnet = require('magnet-uri') var prettyjson = require('prettyjson') @@ -142,34 +141,19 @@ dht.on('peer', function (addr, hash, from) { swarms[hash].addPeer(addr) }) -function write_sha (sha, branch) { - // TODO: use `git update-ref` +function update_ref (sha, branch) { var targetdir = process.env['GIT_DIR'] || '.' - - // Make the parent directories; build the path. - var path = targetdir + '/refs' - var target = ['remotes', remotename].concat(branch.split('/')) - target.forEach(function (segment, i) { - path += '/' + segment - // Call mkdir on every entry segment the last - if (i < target.length - 1 && !fs.existsSync(path)) { - fs.mkdirSync(path) - } - }) - - console.warn('writing to: ' + path) - var stream = fs.createWriteStream(path) - stream.once('open', function (fd) { - stream.write(sha + '\n') - stream.end() - todo-- - if (todo <= 0) { - // These writes are actually necessary for git to finish - // checkout. - process.stdout.write('\n\n') - process.exit() - } - }) + branch = remotename + '/' + branch + spawn('git', ['update-ref', branch, sha]) + console.warn('git update-ref ' + chalk.yellow(branch) + ' ' + + chalk.green(sha)) + todo-- + if (todo <= 0) { + // These writes are actually necessary for git to finish + // checkout. + process.stdout.write('\n\n') + process.exit() + } } function get_infohash (sha, branch) { @@ -215,7 +199,7 @@ function get_infohash (sha, branch) { stream.pipe(unpack.stdin) unpack.stderr.pipe(process.stderr) unpack.on('exit', function (code) { - write_sha(sha, branch) + update_ref(sha, branch) }) }) }) |
