diff --git a/git.zig b/git.zig index a3eab63d0d27c31c241cffbcfd4f8c1ad584b2bf..a9f4cc76e1219f5b54e5ab02d1fd1a913c3e8b97 100644 --- a/git.zig +++ b/git.zig @@ -26,7 +26,7 @@ pub fn version(alloc: std.mem.Allocator) !string { /// Returns the result of running `git rev-parse HEAD` /// dir must already be pointing at the .git folder // TODO this doesnt handle when there are 0 commits -pub fn getHEAD(alloc: std.mem.Allocator, dir: std.fs.Dir) !CommitId { +pub fn getHEAD(alloc: std.mem.Allocator, dir: std.fs.Dir) !?CommitId { const h = std.mem.trimRight(u8, try dir.readFileAlloc(alloc, "HEAD", 1024), "\n"); if (std.mem.startsWith(u8, h, "ref:")) { @@ -54,7 +54,7 @@ pub fn getHEAD(alloc: std.mem.Allocator, dir: std.fs.Dir) !CommitId { if (std.mem.eql(u8, h[5..], ref)) return ensureObjId(CommitId, objid); } } - unreachable; + return null; } return ensureObjId(CommitId, h);