From 1e9aa3d5bd87db2a7a661d75eff32c7c6bcbd37e Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Tue, 1 Feb 2022 03:02:48 -0800 Subject: [PATCH] initial code implementation --- git.zig | 11 +++++++++++ zig.mod | 6 ++++++ 2 files changed, 17 insertions(+) create mode 100644 git.zig create mode 100644 zig.mod 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: -- 2.54.0