authorgravatar for hello@nektro.netMeghan <hello@nektro.net> 2020-11-20 13:06:39 -08:00
committergravatar for hello@nektro.netMeghan <hello@nektro.net> 2020-11-20 13:06:39 -08:00
logf2bd0cc217c506dff006d88f0179c4c903d0365f
tree9a7e181161cd92867a58dae474fbe0c3c32f8d90
parent51fde24c3fabeddb5a5de40ffe2b269c1e53383e

fetch/git: if version is set, validate and copy and checkout files to new dir


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

src/cmd_fetch.zig+18
......@@ -64,6 +64,7 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module {
6464 const moduledeps = &std.ArrayList(u.Module).init(gpa);
6565 for (m.deps) |d| {
6666 const p = try u.concat(&[_][]const u8{dir, "/", try d.clean_path()});
67 const pv = try u.concat(&[_][]const u8{dir, "/v/", try d.clean_path(), "/", d.version});
6768 u.print("fetch: {}: {}: {}", .{m.name, @tagName(d.type), d.path});
6869 switch (d.type) {
6970 .git => {
......@@ -74,6 +75,23 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module {
7475 _ = try run_cmd(p, &[_][]const u8{"git", "fetch"});
7576 _ = try run_cmd(p, &[_][]const u8{"git", "pull"});
7677 }
78 if (d.version.len > 0) {
79 const iter = &std.mem.split(d.version, "-");
80 const v_type_s = iter.next().?;
81 if (std.meta.stringToEnum(u.GitVersionType, v_type_s)) |v_type| {
82 const ref = iter.rest();
83 if ((try run_cmd(p, &[_][]const u8{"git", "rev-parse", ref})) > 0) {
84 u.assert(false, "fetch: git: {}: {} {} does not exist", .{d.path, @tagName(v_type), ref});
85 }
86 _ = try run_cmd(null, &[_][]const u8{"git", "clone", d.path, pv});
87 _ = try run_cmd(pv, &[_][]const u8{"git", "checkout", ref});
88 const pvd = try std.fs.openDirAbsolute(pv, .{});
89 try pvd.deleteTree(".git");
90 }
91 else {
92 u.assert(false, "fetch: git: version type: '{}' on {} is invalid.", .{v_type_s, d.path});
93 }
94 }
7795 },
7896 .hg => {
7997 if (!try u.does_file_exist(p)) {