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