Skip to content

Commit

Permalink
gittorrentd: Check cwd for .git/, too.
Browse files Browse the repository at this point in the history
.git/git-daemon-export-ok may exist relative to the current directory,
and the user may not want to supply all repositories from its parent.
  • Loading branch information
Scott Prager committed Jun 2, 2015
1 parent 09f38bb commit 5141cf8
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions gittorrentd
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var EC = require('elliptic').ec
var ed25519 = new EC('ed25519')
var exec = require('child_process').exec
var glob = require('glob')
var path = require('path')
var fs = require('fs')
var hat = require('hat')
var net = require('net')
Expand Down Expand Up @@ -76,12 +77,20 @@ function bpad (n, buf) {

dht.on('ready', function () {
// Spider all */.git dirs and announce all refs.
var repos = glob.sync('*/{,.git/}git-daemon-export-ok', {strict: false})
var repos = glob.sync('{,.git/,*/.git/}git-daemon-export-ok', {strict: false})
var count = repos.length
repos.forEach(function (repo) {
console.log('in repo ' + repo)
repo = repo.replace(/git-daemon-export-ok$/, '')
console.log(repo)
if (repo === '') {
repo = process.cwd() // We're in '.git'.
}
var reponame = path.basename(repo.replace(/\/?.git\/?$/, ''))
if (reponame === '' || reponame === '.') {
// repo = './.git'
reponame = path.basename(process.cwd())
}
console.log('in repo ' + repo)

var upload = spawn('git-upload-pack', ['--strict', repo])
upload.stdout.on('data', function (line) {
var lines = line.toString().split('\n')
Expand All @@ -96,7 +105,6 @@ dht.on('ready', function () {
if (!announcedRefs.master[sha]) {
console.log('Announcing ' + sha + ' for ref ' + ref + ' on repo ' + repo)
announcedRefs.master[sha] = repo
var reponame = repo.replace(/\/.git\/$/, '')
userProfile.repositories[reponame] = {}
userProfile.repositories[reponame].master = sha
// Callback counting for repos
Expand Down

0 comments on commit 5141cf8

Please sign in to comment.