Skip to content

Commit

Permalink
call 'git update-server-info' after committing via rest api
Browse files Browse the repository at this point in the history
  • Loading branch information
toolness committed Jul 30, 2012
1 parent 2fe62ae commit 9224a50
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
6 changes: 6 additions & 0 deletions git.js
Expand Up @@ -117,6 +117,12 @@ function Git(options) {
git(['ls-files', dirname], function(err, stdout) {
cb(err, stdout.split('\n').slice(0, -1));
});
},
end: function(cb) {
process.nextTick(function() { cb(null); });
},
cmd: function(args, cb) {
git(args, cb);
}
};

Expand Down
11 changes: 8 additions & 3 deletions simple-git-server.js
@@ -1,7 +1,7 @@
var _ = require('underscore'),
express = require('express');

function makeCommitHandler(git) {
function makeCommitHandler(git, postCommit) {
return function(req, res) {
if (!req.user)
return res.send(403);
Expand Down Expand Up @@ -33,7 +33,10 @@ function makeCommitHandler(git) {
git.commit({
author: author,
message: message
}, function(err) {
});
if (postCommit)
postCommit(git);
git.end(function(err) {
if (err) {
if (!err.stderr)
return res.send('an unknown error occurred', 500);
Expand Down Expand Up @@ -61,8 +64,10 @@ module.exports = function SimpleGitServer(config) {
var self = express.createServer();

self.browserIDCORS = bic;
self.handleCommit = makeCommitHandler(git);
self.handleList = makeListHandler(git);
self.handleCommit = makeCommitHandler(git, function postCommit(git) {
if (git.cmd) git.cmd(['update-server-info']);
});

self.use(express.bodyParser());
self.use(bic.accessToken);
Expand Down
1 change: 1 addition & 0 deletions test/test-git.js
Expand Up @@ -204,6 +204,7 @@ describe('Git', function() {
function onRemoveFooTxt(err) {
if (err) return done(err);
expect(fs.existsSync(git.abspath('foo.txt'))).to.be(false);
expect(fs.existsSync(git.abspath('.git/info/refs'))).to.be(true);
done();
}
});
Expand Down
13 changes: 9 additions & 4 deletions test/test-simple-git-server.js
Expand Up @@ -18,9 +18,12 @@ describe("SimpleGitServer", function() {
lastCommitOptions: null,
addFile: function(f, c) { this.log.push(['add', f, c]); },
rm: function(f) { this.log.push(['rm', f]); },
commit: function(options, cb) {
commit: function(options) {
this.lastCommitOptions = options;
this.log.push(['commit']); cb(null);
this.log.push(['commit']);
},
end: function(cb) {
cb(null);
}
};
}
Expand Down Expand Up @@ -148,7 +151,8 @@ describe("SimpleGitServer", function() {
request(cfg(SimpleGitServer({
git: {
rm: function() {},
commit: function(options, cb) { cb("uhoh"); }
commit: function() {},
end: function(cb) { cb("uhoh"); }
}
})))
.post('/commit')
Expand All @@ -161,7 +165,8 @@ describe("SimpleGitServer", function() {
request(cfg(SimpleGitServer({
git: {
rm: function() {},
commit: function(options, cb) { cb({stderr: "meh does not exist"}); }
commit: function() {},
end: function(cb) { cb({stderr: "meh does not exist"}); }
}
})))
.post('/commit')
Expand Down

0 comments on commit 9224a50

Please sign in to comment.