| ... | @@ -26,7 +26,7 @@ pub fn version(alloc: std.mem.Allocator) !string { | ... | @@ -26,7 +26,7 @@ pub fn version(alloc: std.mem.Allocator) !string { |
| 26 | /// Returns the result of running `git rev-parse HEAD` | 26 | /// Returns the result of running `git rev-parse HEAD` |
| 27 | /// dir must already be pointing at the .git folder | 27 | /// dir must already be pointing at the .git folder |
| 28 | // TODO this doesnt handle when there are 0 commits | 28 | // TODO this doesnt handle when there are 0 commits |
| 29 | pub fn getHEAD(alloc: std.mem.Allocator, dir: std.fs.Dir) !CommitId { | 29 | pub fn getHEAD(alloc: std.mem.Allocator, dir: std.fs.Dir) !?CommitId { |
| 30 | const h = std.mem.trimRight(u8, try dir.readFileAlloc(alloc, "HEAD", 1024), "\n"); | 30 | const h = std.mem.trimRight(u8, try dir.readFileAlloc(alloc, "HEAD", 1024), "\n"); |
| 31 | | 31 | |
| 32 | if (std.mem.startsWith(u8, h, "ref:")) { | 32 | if (std.mem.startsWith(u8, h, "ref:")) { |
| ... | @@ -54,7 +54,7 @@ pub fn getHEAD(alloc: std.mem.Allocator, dir: std.fs.Dir) !CommitId { | ... | @@ -54,7 +54,7 @@ pub fn getHEAD(alloc: std.mem.Allocator, dir: std.fs.Dir) !CommitId { |
| 54 | if (std.mem.eql(u8, h[5..], ref)) return ensureObjId(CommitId, objid); | 54 | if (std.mem.eql(u8, h[5..], ref)) return ensureObjId(CommitId, objid); |
| 55 | } | 55 | } |
| 56 | } | 56 | } |
| 57 | unreachable; | 57 | return null; |
| 58 | } | 58 | } |
| 59 | | 59 | |
| 60 | return ensureObjId(CommitId, h); | 60 | return ensureObjId(CommitId, h); |