authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-05-16 19:46:28 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-05-16 19:46:28 -07:00
loga9d3588173ab80ce564b8aeba4113384d18c2411
treebdc9e07c4cf00b28a3818dff1d71e73a6e2c8002
parentaa32b286047d782c4aea3def44d8e20e328296d2

add version() function


1 files changed, 10 insertions(+), 0 deletions(-)

git.zig+10
...@@ -10,6 +10,16 @@ pub const TreeId = struct { id: Id };...@@ -10,6 +10,16 @@ pub const TreeId = struct { id: Id };
10pub const CommitId = struct { id: Id };10pub const CommitId = struct { id: Id };
11pub const BlobId = struct { id: Id };11pub const BlobId = struct { id: Id };
1212
13pub fn version(alloc: std.mem.Allocator) !string {
14 const result = try std.ChildProcess.exec(.{
15 .allocator = alloc,
16 .argv = &.{ "git", "--version" },
17 .max_output_bytes = 1024,
18 });
19 std.debug.assert(result.term == .Exited and result.term.Exited == 0);
20 return extras.trimPrefixEnsure(std.mem.trimRight(u8, result.stdout, "\n"), "git version ").?;
21}
22
13/// Returns the result of running `git rev-parse HEAD`23/// Returns the result of running `git rev-parse HEAD`
14/// dir must already be pointing at the .git folder24/// dir must already be pointing at the .git folder
15// TODO this doesnt handle when there are 0 commits25// TODO this doesnt handle when there are 0 commits