authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-07-05 17:54:31 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-07-05 17:54:31 -07:00
log75962d6240a3c8580c8a04262436a3caea793774
tree80e879f49da44b22503cb2fc9f07f84619f01459
parente5ed412abe39e3244f7c44c797c2acd6addcfd6a

getHEAD: return null when repo has no commits


1 files changed, 2 insertions(+), 2 deletions(-)

git.zig+2-2
......@@ -26,7 +26,7 @@ pub fn version(alloc: std.mem.Allocator) !string {
2626/// Returns the result of running `git rev-parse HEAD`
2727/// dir must already be pointing at the .git folder
2828// TODO this doesnt handle when there are 0 commits
29pub fn getHEAD(alloc: std.mem.Allocator, dir: std.fs.Dir) !CommitId {
29pub fn getHEAD(alloc: std.mem.Allocator, dir: std.fs.Dir) !?CommitId {
3030 const h = std.mem.trimRight(u8, try dir.readFileAlloc(alloc, "HEAD", 1024), "\n");
3131
3232 if (std.mem.startsWith(u8, h, "ref:")) {
......@@ -54,7 +54,7 @@ pub fn getHEAD(alloc: std.mem.Allocator, dir: std.fs.Dir) !CommitId {
5454 if (std.mem.eql(u8, h[5..], ref)) return ensureObjId(CommitId, objid);
5555 }
5656 }
57 unreachable;
57 return null;
5858 }
5959
6060 return ensureObjId(CommitId, h);