Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #6 from AvianFlu/master

Should prevent ENOENT on absence of .git/packed-refs
  • Loading branch information...
commit 093306de6d827f5edfab81f873412b73dd7fcb12 2 parents c30606c + c20afa6
Tim Caswell authored August 10, 2012

Showing 1 changed file with 27 additions and 13 deletions. Show diff stats Hide diff stats

  1. 40  lib/git-fs.js
40  lib/git-fs.js
@@ -130,22 +130,36 @@ function getHeadSha(callback) {
130 130
   }
131 131
 
132 132
   var head, packedRefs, master;
133  
-  fs.readFile(Path.join(gitDir, "packed-refs"), "ascii", function (err, result) {
134  
-    if (err) { groupCallback(err); return; }
135  
-    packedRefs = result;
136  
-    checkDone();
  133
+  
  134
+  Path.exists(Path.join(gitDir, "packed-refs"), function (exists) {
  135
+    if(exists) {
  136
+      getHEAD();
  137
+    }
  138
+    else {
  139
+      gitExec(["gc"],function (err) {
  140
+        getHEAD();
  141
+      });
  142
+    }
137 143
   });
138  
-  fs.readFile(Path.join(gitDir, "HEAD"), "ascii", function (err, result) {
139  
-    if (err) { groupCallback(err); return; }
140  
-    try {
141  
-      head = result.match(/^ref: (.*)\n$/)[1]
142  
-    } catch (err) { groupCallback(err); return; }
143  
-    fs.readFile(Path.join(gitDir, head), "ascii", function (err, result) {
144  
-      master = result || null;
  144
+  
  145
+  function getHEAD() {
  146
+    fs.readFile(Path.join(gitDir, "packed-refs"), "ascii", function (err, result) {
  147
+      if (err) { groupCallback(err); return; }
  148
+      packedRefs = result;
145 149
       checkDone();
146 150
     });
147  
-    checkDone();
148  
-  });
  151
+    fs.readFile(Path.join(gitDir, "HEAD"), "ascii", function (err, result) {
  152
+      if (err) { groupCallback(err); return; }
  153
+      try {
  154
+        head = result.match(/^ref: (.*)\n$/)[1]
  155
+      } catch (err) { groupCallback(err); return; }
  156
+      fs.readFile(Path.join(gitDir, head), "ascii", function (err, result) {
  157
+        master = result || null;
  158
+        checkDone();
  159
+      });
  160
+      checkDone();
  161
+    });
  162
+  }
149 163
 
150 164
   // When they're both done, parse out the sha and return it.
151 165
   function checkDone() {

0 notes on commit 093306d

Please sign in to comment.
Something went wrong with that request. Please try again.