| ... | ... | @@ -71,12 +71,14 @@ pub fn version(alloc: std.mem.Allocator) !string { |
| 71 | 71 | |
| 72 | 72 | /// Returns the result of running `git rev-parse HEAD` |
| 73 | 73 | /// dir must already be pointing at the .git folder |
| 74 | | // TODO this doesnt handle when there are 0 commits |
| 75 | 74 | pub fn getHEAD(alloc: std.mem.Allocator, dir: nfs.Dir) !?CommitId { |
| 76 | 75 | const t = tracer.trace(@src(), "", .{}); |
| 77 | 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 | 82 | defer alloc.free(headfile); |
| 81 | 83 | const h = std.mem.trimEnd(u8, headfile, "\n"); |
| 82 | 84 | |