authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-10-11 11:59:32 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-10-11 11:59:32 -07:00
log4af6aa9409cc8e61c11d270008e9238d137b067b
treea78795ab7a0f572788835ec3752246ec1f4096f4
parentcf8686516941180d02cab74eb1fc4412c8a377d5

cmd/verison- catch git_rev_HEAD and fallback, fixes #35


1 files changed, 6 insertions(+), 7 deletions(-)

src/cmd/version.zig+6-7
......@@ -1,4 +1,5 @@
11const std = @import("std");
2const string = []const u8;
23const gpa = std.heap.c_allocator;
34const builtin = @import("builtin");
45
......@@ -14,19 +15,17 @@ pub fn execute(args: [][]u8) !void {
1415 const build_options = if (@hasDecl(root, "build_options")) root.build_options else struct {};
1516 const version = if (@hasDecl(build_options, "version")) build_options.version else "unknown";
1617
18 var gitversion = u.git_rev_HEAD(gpa, std.fs.cwd()) catch "";
19 gitversion = if (gitversion.len > 0) gitversion[0..7] else gitversion;
20
1721 const stdout = std.io.getStdOut();
1822 const w = stdout.writer();
1923
2024 try w.writeAll("zigmod");
2125
2226 try w.print(" {s}", .{version});
23 if (std.mem.eql(u8, version, "dev")) {
24 try w.print(
25 "-{s}",
26 .{
27 (try u.git_rev_HEAD(gpa, std.fs.cwd()))[0..7],
28 },
29 );
27 if (std.mem.eql(u8, version, "dev") and gitversion.len > 0) {
28 try w.print("-{s}", .{gitversion});
3029 }
3130
3231 try w.print(" {s}", .{@tagName(builtin.os.tag)});