| ... | @@ -10,6 +10,16 @@ pub const TreeId = struct { id: Id }; | ... | @@ -10,6 +10,16 @@ pub const TreeId = struct { id: Id }; |
| 10 | pub const CommitId = struct { id: Id }; | 10 | pub const CommitId = struct { id: Id }; |
| 11 | pub const BlobId = struct { id: Id }; | 11 | pub const BlobId = struct { id: Id }; |
| 12 | | 12 | |
| | 13 | pub 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 folder | 24 | /// dir must already be pointing at the .git folder |
| 15 | // TODO this doesnt handle when there are 0 commits | 25 | // TODO this doesnt handle when there are 0 commits |