Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

failing test for subdirs

  • Loading branch information...
commit bc504544d7238880fb53c437525ab95b75793ff7 1 parent b98bd1d
@substack authored
Showing with 101 additions and 1 deletion.
  1. +5 −0 index.js
  2. +2 −1  package.json
  3. +94 −0 test/subdir.js
View
5 index.js
@@ -1,6 +1,7 @@
var fs = require('fs');
var path = require('path');
var http = require('http');
+var mkdirp = require('mkdirp');
var spawn = require('child_process').spawn;
var EventEmitter = require('events').EventEmitter;
@@ -28,6 +29,10 @@ Git.prototype.exists = function (repo, cb) {
(fs.exists || path.exists)(path.join(this.repoDir, repo), cb);
};
+Git.prototype.mkdir = function (dir, cb) {
+ mkdirp(path.resolve(this.repoDir, dir), cb);
+};
+
Git.prototype.create = function (repo, cb) {
var cwd = process.cwd();
var dir = path.join(this.repoDir, repo);
View
3  package.json
@@ -25,7 +25,8 @@
},
"dependencies" : {
"http-duplex" : "~0.0.2",
- "inherits" : "~1.0.0"
+ "inherits" : "~1.0.0",
+ "mkdirp" : "~0.3.4"
},
"devDependencies" : {
"tap" : "~0.2.5",
View
94 test/subdir.js
@@ -0,0 +1,94 @@
+var test = require('tap').test;
+var pushover = require('../');
+
+var fs = require('fs');
+var path = require('path');
+var exists = fs.exists || path.exists;
+
+var spawn = require('child_process').spawn;
+var exec = require('child_process').exec;
+var http = require('http');
+
+var seq = require('seq');
+
+test('create, push to, and clone a repo', function (t) {
+ t.plan(7);
+
+ var repoDir = '/tmp/' + Math.floor(Math.random() * (1<<30)).toString(16);
+ var srcDir = '/tmp/' + Math.floor(Math.random() * (1<<30)).toString(16);
+ var dstDir = '/tmp/' + Math.floor(Math.random() * (1<<30)).toString(16);
+ var lastCommit;
+
+ fs.mkdirSync(repoDir, 0700);
+ fs.mkdirSync(srcDir, 0700);
+ fs.mkdirSync(dstDir, 0700);
+
+ var repos = pushover(repoDir, { autoCreate : false });
+ var port = Math.floor(Math.random() * ((1<<16) - 1e4)) + 1e4;
+ var server = http.createServer(function (req, res) {
+ repos.handle(req, res);
+ });
+ server.listen(port);
+
+ process.chdir(srcDir);
+ seq()
+ .seq(function () { repos.mkdir('xyz', this) })
+ .seq(function () { repos.create('xyz/doom', this) })
+ .seq(function () {
+ var ps = spawn('git', [ 'init' ]);
+ ps.stderr.pipe(process.stderr, { end : false });
+ ps.on('exit', this.ok);
+ })
+ .seq(function () {
+ fs.writeFile(srcDir + '/a.txt', 'abcd', this);
+ })
+ .seq(function () {
+ spawn('git', [ 'add', 'a.txt' ]).on('exit', this.ok)
+ })
+ .seq_(function (next) {
+ var ps = spawn('git', [ 'commit', '-am', 'a!!' ]);
+ ps.on('exit', function () {
+ exec('git log | head -n1', function (err, stdout) {
+ lastCommit = stdout.split(/\s+/)[1];
+ next();
+ });
+ });
+ ps.stdout.pipe(process.stdout, { end : false });
+ })
+ .seq(function () {
+ var ps = spawn('git', [
+ 'push', 'http://localhost:' + port + '/xyz/doom', 'master'
+ ]);
+ ps.stderr.pipe(process.stderr, { end : false });
+ ps.on('exit', this.ok);
+ })
+ .seq(function () {
+ process.chdir(dstDir);
+ spawn('git', [ 'clone', 'http://localhost:' + port + '/xyz/doom' ])
+ .on('exit', this.ok)
+ })
+ .seq_(function (next) {
+ exists(dstDir + '/doom/a.txt', function (ex) {
+ t.ok(ex, 'a.txt exists');
+ next();
+ })
+ })
+ .seq(function () {
+ server.close();
+ t.end();
+ })
+ .catch(t.fail)
+ ;
+
+ repos.on('push', function (push) {
+ t.equal(push.repo, 'doom', 'repo name');
+ t.equal(push.commit, lastCommit, 'commit ok');
+ t.equal(push.branch, 'master', 'master branch');
+
+ t.equal(push.headers.host, 'localhost:' + port, 'http host');
+ t.equal(push.method, 'POST', 'is a post');
+ t.equal(push.url, '/xyz/doom/git-receive-pack', 'receive pack');
+
+ push.accept();
+ });
+});
Please sign in to comment.
Something went wrong with that request. Please try again.