From a9d3588173ab80ce564b8aeba4113384d18c2411 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Tue, 16 May 2023 19:46:28 -0700 Subject: [PATCH] add version() function --- git.zig | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/git.zig b/git.zig index 17134f1f79ea3ba8c6133a8e8b74df3495f56aa9..1f9f05dcf6b6bbd259d52c8cb80284baa06eb86e 100644 --- a/git.zig +++ b/git.zig @@ -10,6 +10,16 @@ pub const TreeId = struct { id: Id }; pub const CommitId = struct { id: Id }; pub const BlobId = struct { id: Id }; +pub fn version(alloc: std.mem.Allocator) !string { + const result = try std.ChildProcess.exec(.{ + .allocator = alloc, + .argv = &.{ "git", "--version" }, + .max_output_bytes = 1024, + }); + std.debug.assert(result.term == .Exited and result.term.Exited == 0); + return extras.trimPrefixEnsure(std.mem.trimRight(u8, result.stdout, "\n"), "git version ").?; +} + /// Returns the result of running `git rev-parse HEAD` /// dir must already be pointing at the .git folder // TODO this doesnt handle when there are 0 commits -- 2.54.0