diff --git a/git.zig b/git.zig new file mode 100644 index 0000000000000000000000000000000000000000..c80c13752b24813bdba2ba8e4d7e5dff71fdf8bd --- /dev/null +++ b/git.zig @@ -0,0 +1,11 @@ +const std = @import("std"); +const string = []const u8; + +/// Returns the result of running `git rev-parse HEAD` +pub fn getHEAD(alloc: std.mem.Allocator, dir: std.fs.Dir) !string { + var dirg = try dir.openDir(".git", .{}); + defer dirg.close(); + const h = std.mem.trimRight(u8, try dirg.readFileAlloc(alloc, "HEAD", 1024), "\n"); + const r = std.mem.trimRight(u8, try dirg.readFileAlloc(alloc, h[5..], 1024), "\n"); + return r; +} diff --git a/zig.mod b/zig.mod new file mode 100644 index 0000000000000000000000000000000000000000..17817d0a1fafd881fb533f39bd6a66ae8463d06a --- /dev/null +++ b/zig.mod @@ -0,0 +1,6 @@ +id: 0k64oe2nuzvjgz226ufvimjhialghxdgmlzusonbma31flnd +name: git +main: git.zig +license: MIT +description: Inspect into the depths of your .git folder purely from Zig +dependencies: