Permalink
Browse files

Merge pull request #6 from AvianFlu/master

Should prevent ENOENT on absence of .git/packed-refs
  • Loading branch information...
2 parents c30606c + c20afa6 commit 093306de6d827f5edfab81f873412b73dd7fcb12 @creationix committed Aug 10, 2012
Showing with 27 additions and 13 deletions.
  1. +27 −13 lib/git-fs.js
View
@@ -130,22 +130,36 @@ function getHeadSha(callback) {
}
var head, packedRefs, master;
- fs.readFile(Path.join(gitDir, "packed-refs"), "ascii", function (err, result) {
- if (err) { groupCallback(err); return; }
- packedRefs = result;
- checkDone();
+
+ Path.exists(Path.join(gitDir, "packed-refs"), function (exists) {
+ if(exists) {
+ getHEAD();
+ }
+ else {
+ gitExec(["gc"],function (err) {
+ getHEAD();
+ });
+ }
});
- fs.readFile(Path.join(gitDir, "HEAD"), "ascii", function (err, result) {
- if (err) { groupCallback(err); return; }
- try {
- head = result.match(/^ref: (.*)\n$/)[1]
- } catch (err) { groupCallback(err); return; }
- fs.readFile(Path.join(gitDir, head), "ascii", function (err, result) {
- master = result || null;
+
+ function getHEAD() {
+ fs.readFile(Path.join(gitDir, "packed-refs"), "ascii", function (err, result) {
+ if (err) { groupCallback(err); return; }
+ packedRefs = result;
checkDone();
});
- checkDone();
- });
+ fs.readFile(Path.join(gitDir, "HEAD"), "ascii", function (err, result) {
+ if (err) { groupCallback(err); return; }
+ try {
+ head = result.match(/^ref: (.*)\n$/)[1]
+ } catch (err) { groupCallback(err); return; }
+ fs.readFile(Path.join(gitDir, head), "ascii", function (err, result) {
+ master = result || null;
+ checkDone();
+ });
+ checkDone();
+ });
+ }
// When they're both done, parse out the sha and return it.
function checkDone() {

0 comments on commit 093306d

Please sign in to comment.