From 77c15ef110976fb3da134b8187877d8ab7fcd975 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Thu, 27 Apr 2023 19:09:53 -0700 Subject: [PATCH] getHEAD: use empty file if packed-refs isnt there --- git.zig | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/git.zig b/git.zig index b245dafaafb2af306fac932993622a5fb8c0f88c..aff4e73c553c50bf931a78e6c775f9be9e085c59 100644 --- a/git.zig +++ b/git.zig @@ -14,7 +14,10 @@ pub fn getHEAD(alloc: std.mem.Allocator, dir: std.fs.Dir) !Id { if (std.mem.startsWith(u8, h, "ref:")) { const r = blk: { - const pckedrfs = try dir.readFileAlloc(alloc, "packed-refs", 1024 * 1024); + const pckedrfs = dir.readFileAlloc(alloc, "packed-refs", 1024 * 1024) catch |err| switch (err) { + error.FileNotFound => try std.fs.cwd().readFileAlloc(alloc, "/dev/null", 1024), + else => |e| return e, + }; var iter = std.mem.split(u8, pckedrfs, "\n"); while (iter.next()) |line| { if (std.mem.startsWith(u8, line, "#")) continue; -- 2.54.0