| ... | @@ -71,12 +71,14 @@ pub fn version(alloc: std.mem.Allocator) !string { | ... | @@ -71,12 +71,14 @@ pub fn version(alloc: std.mem.Allocator) !string { |
| 71 | | 71 | |
| 72 | /// Returns the result of running `git rev-parse HEAD` | 72 | /// Returns the result of running `git rev-parse HEAD` |
| 73 | /// dir must already be pointing at the .git folder | 73 | /// dir must already be pointing at the .git folder |
| 74 | // TODO this doesnt handle when there are 0 commits | | |
| 75 | pub fn getHEAD(alloc: std.mem.Allocator, dir: nfs.Dir) !?CommitId { | 74 | pub fn getHEAD(alloc: std.mem.Allocator, dir: nfs.Dir) !?CommitId { |
| 76 | const t = tracer.trace(@src(), "", .{}); | 75 | const t = tracer.trace(@src(), "", .{}); |
| 77 | defer t.end(); | 76 | defer t.end(); |
| 78 | | 77 | |
| 79 | const headfile = try dir.readFileAlloc(alloc, "HEAD", 1024); | 78 | const headfile = dir.readFileAlloc(alloc, "HEAD", 1024) catch |err| switch (err) { |
| | 79 | error.ENOENT => return null, |
| | 80 | else => |e| return e, |
| | 81 | }; |
| 80 | defer alloc.free(headfile); | 82 | defer alloc.free(headfile); |
| 81 | const h = std.mem.trimEnd(u8, headfile, "\n"); | 83 | const h = std.mem.trimEnd(u8, headfile, "\n"); |
| 82 | | 84 | |