| ... | ... | @@ -15,6 +15,7 @@ pub const CollectOptions = struct { |
| 15 | 15 | pub fn collect_deps(dir: []const u8, mpath: []const u8, comptime options: CollectOptions) anyerror!u.Module { |
| 16 | 16 | const m = try u.ModFile.init(gpa, mpath); |
| 17 | 17 | const moduledeps = &std.ArrayList(u.Module).init(gpa); |
| 18 | const tempdir = try fs.path.join(gpa, &.{dir, "temp"}); |
| 18 | 19 | var moddir: []const u8 = undefined; |
| 19 | 20 | for (m.deps) |d| { |
| 20 | 21 | const p = try fs.path.join(gpa, &.{dir, try d.clean_path()}); |
| ... | ... | @@ -26,12 +27,6 @@ pub fn collect_deps(dir: []const u8, mpath: []const u8, comptime options: Collec |
| 26 | 27 | // no op |
| 27 | 28 | }, |
| 28 | 29 | .git => blk: { |
| 29 | | if (!try u.does_folder_exist(p)) { |
| 30 | | try d.type.pull(d.path, p); |
| 31 | | } |
| 32 | | else { |
| 33 | | if (options.update) { try d.type.update(p, d.path); } |
| 34 | | } |
| 35 | 30 | if (d.version.len > 0) { |
| 36 | 31 | const vers = u.parse_split(u.GitVersionType, "-").do(d.version) catch |e| switch (e) { |
| 37 | 32 | error.IterEmpty => unreachable, |
| ... | ... | @@ -43,23 +38,30 @@ pub fn collect_deps(dir: []const u8, mpath: []const u8, comptime options: Collec |
| 43 | 38 | }; |
| 44 | 39 | if (try u.does_folder_exist(pv)) { |
| 45 | 40 | if (vers.id == .branch) { |
| 46 | | if (options.update) { try d.type.update(p, d.path); } |
| 41 | if (options.update) { try d.type.update(pv, d.path); } |
| 47 | 42 | } |
| 48 | 43 | moddir = pv; |
| 49 | 44 | break :blk; |
| 50 | 45 | } |
| 51 | | if ((try u.run_cmd(p, &.{"git", "checkout", vers.string})) > 0) { |
| 46 | try d.type.pull(d.path, tempdir); |
| 47 | if ((try u.run_cmd(tempdir, &.{"git", "checkout", vers.string})) > 0) { |
| 52 | 48 | u.assert(false, "fetch: git: {s}: {s} {s} does not exist", .{d.path, @tagName(vers.id), vers.string}); |
| 53 | | } else { |
| 54 | | _ = try u.run_cmd(p, &.{"git", "checkout", "-"}); |
| 55 | 49 | } |
| 56 | | try d.type.pull(d.path, pv); |
| 57 | | _ = try u.run_cmd(pv, &.{"git", "checkout", vers.string}); |
| 50 | const td_fd = try fs.cwd().openDir(dir, .{}); |
| 51 | try u.mkdir_all(pv); |
| 52 | try td_fd.rename("temp", try d.clean_path_v()); |
| 58 | 53 | if (vers.id != .branch) { |
| 59 | 54 | const pvd = try std.fs.cwd().openDir(pv, .{}); |
| 60 | 55 | try pvd.deleteTree(".git"); |
| 61 | 56 | } |
| 62 | 57 | moddir = pv; |
| 58 | break :blk; |
| 59 | } |
| 60 | if (!try u.does_folder_exist(p)) { |
| 61 | try d.type.pull(d.path, p); |
| 62 | } |
| 63 | else { |
| 64 | if (options.update) { try d.type.update(p, d.path); } |
| 63 | 65 | } |
| 64 | 66 | }, |
| 65 | 67 | .hg => { |