build.zig: metadata dependency on .git/logs/HEAD

This commit is contained in:
Andrew Kelley committed 2026-09-16 13:12:47 -07:00
1 parent 597306838d
commit 4cfd256330
1 file changed
+3 -2
+3 -2
View File
@@ -272,12 +272,13 @@ pub fn build(b: *std.Build) !void {
const io = b.graph.io;
const git_file = b.root.openFile(io, ".git", .{ .allow_directory = false }) catch |err| switch (err) {
error.IsDir => {
b.dependOnFileContents(b.path(".git/logs/HEAD"));
b.dependOnFileMetadata(b.path(".git/logs/HEAD"));
break :git;
},
else => |e| return e,
};
defer git_file.close(io);
b.dependOnFileContents(b.path(".git"));
var line_buffer: ["gitdir: ".len + std.Io.Dir.max_path_bytes + 1]u8 = undefined;
var git_file_reader = git_file.reader(io, &line_buffer);
if (std.mem.cutPrefix(u8, std.mem.trimEnd(u8, try git_file_reader.interface.allocRemaining(
@@ -285,7 +286,7 @@ pub fn build(b: *std.Build) !void {
.limited("gitdir: ".len + std.Io.Dir.max_path_bytes + "\r\n".len),
), "\r\n"), "gitdir: ")) |git_dir| {
const head_file = b.pathJoin(&.{ git_dir, "logs", "HEAD" });
b.dependOnFileContents(if (std.Io.Dir.path.isAbsolute(head_file))
b.dependOnFileMetadata(if (std.Io.Dir.path.isAbsolute(head_file))
b.graph.cwdRelativePath(head_file)
else
b.path(head_file));