Skip to content

Should prevent ENOENT on absence of .git/packed-refs #6

Merged
merged 1 commit into from Aug 10, 2012
+27 −13
View
40 lib/git-fs.js
@@ -123,22 +123,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() {
Something went wrong with that request. Please try again.