╭ changed ───╮ │src/test.zig│ ╰────────────╯ ╭───────────╮ │← all files│ ╰───────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────────╮ │29 } │ │30 } │ │31 │ │32 +test "push creates missing repo under serve" { │ │33 + const io = std.testing.io; │ │34 + const allocator = std.testing.allocator; │ │35 + try testPushCreatesMissingRepo(.xit, .xit, .{ .wire = .http }, 3014, io, allocator); │ │36 + if (.windows != builtin.os.tag) { │ │37 + try testPushCreatesMissingRepo(.xit, .xit, .{ .wire = .ssh }, 3015, io, allocator);│ │38 + } │ │39 +} │ │40 + │ │41 test "clone small" { │ │42 const io = std.testing.io; │ │43 const allocator = std.testing.allocator; │ ╰───────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │1077 │ │1078 // make sure push was successful │ │1079 try std.testing.expect(null == try server_repo.readRef(io, .{ .kind = .tag, .name = "1.0.0" })); │ │1080 +} │ │1081 + │ │1082 +fn testPushCreatesMissingRepo( │ │1083 + comptime repo_kind: rp.RepoKind, │ │1084 + comptime server_repo_kind: rp.RepoKind, │ │1085 + comptime transport_def: net.TransportDefinition, │ │1086 + comptime port: u16, │ │1087 + io: std.Io, │ │1088 + allocator: std.mem.Allocator, │ │1089 +) !void { │ │1090 + const temp_dir_name = "temp-testnet-push-create"; │ │1091 + │ │1092 + const cwd = std.Io.Dir.cwd(); │ │1093 + var temp_dir_or_err = cwd.openDir(io, temp_dir_name, .{}); │ │1094 + if (temp_dir_or_err) |*temp_dir| { │ │1095 + temp_dir.close(io); │ │1096 + try cwd.deleteTree(io, temp_dir_name); │ │1097 + } else |_| {} │ │1098 + var temp_dir = try cwd.createDirPathOpen(io, temp_dir_name, .{}); │ │1099 + defer cwd.deleteTree(io, temp_dir_name) catch {}; │ │1100 + defer temp_dir.close(io); │ │1101 + │ │1102 + var server = try Server(server_repo_kind, transport_def, temp_dir_name, port, true).init(io, allocator); │ │1103 + try server.start(); │ │1104 + defer server.stop(); │ │1105 + │ │1106 + const cwd_path = try std.process.currentPathAlloc(io, allocator); │ │1107 + defer allocator.free(cwd_path); │ │1108 + │ │1109 + const server_path = try std.fs.path.join(allocator, &.{ cwd_path, temp_dir_name, "server" }); │ │1110 + defer allocator.free(server_path); │ │1111 + │ │1112 + const client_path = try std.fs.path.join(allocator, &.{ cwd_path, temp_dir_name, "client" }); │ │1113 + defer allocator.free(client_path); │ │1114 + │ │1115 + var client_repo = try rp.Repo(repo_kind, .{ .is_test = true }).init(io, allocator, .{ .path = client_path }); │ │1116 + defer client_repo.deinit(io, allocator); │ │1117 + │ │1118 + const commit1 = blk: { │ │1119 + const hello_txt = try client_repo.core.work_dir.createFile(io, "hello.txt", .{ .truncate = true }); │ │1120 + defer hello_txt.close(io); │ │1121 + try hello_txt.writeStreamingAll(io, "hello, world!"); │ │1122 + try client_repo.add(io, allocator, &.{"hello.txt"}); │ │1123 + break :blk try client_repo.commit(io, allocator, .{ .message = "let there be light" }); │ │1124 + }; │ │1125 + │ │1126 + _ = try client_repo.addTag(io, allocator, .{ .name = "1.0.0", .message = "hi" }); │ │1127 + │ │1128 + { │ │1129 + if (.windows == builtin.os.tag) { │ │1130 + std.mem.replaceScalar(u8, server_path, '\\', '/'); │ │1131 + } │ │1132 + const separator = if (server_path[0] == '/') "" else "/"; │ │1133 + │ │1134 + const remote_url = switch (transport_def) { │ │1135 + .file => unreachable, │ │1136 + .wire => |wire_kind| switch (wire_kind) { │ │1137 + .http => try std.fmt.allocPrint(allocator, "http://localhost:{}/server", .{port}), │ │1138 + .raw => unreachable, │ │1139 + .ssh => try std.fmt.allocPrint(allocator, "ssh://localhost:{}{s}{s}", .{ port, separator, server_path }), │ │1140 + }, │ │1141 + }; │ │1142 + defer allocator.free(remote_url); │ │1143 + │ │1144 + try client_repo.addRemote(io, allocator, .{ .name = "origin", .value = remote_url }); │ │1145 + try client_repo.addConfig(io, allocator, .{ .name = "branch.master.remote", .value = "origin" }); │ │1146 + } │ │1147 + │ │1148 + const is_ssh = switch (transport_def) { │ │1149 + .file => false, │ │1150 + .wire => |wire_kind| .ssh == wire_kind, │ │1151 + }; │ │1152 + const ssh_cmd_maybe: ?[]const u8 = if (is_ssh) blk: { │ │1153 + const known_hosts_path = try std.fs.path.join(allocator, &.{ cwd_path, temp_dir_name, "known_hosts" }); │ │1154 + defer allocator.free(known_hosts_path); │ │1155 + │ │1156 + const priv_key_path = try std.fs.path.join(allocator, &.{ cwd_path, temp_dir_name, "key" }); │ │1157 + defer allocator.free(priv_key_path); │ │1158 + │ │1159 + break :blk try std.fmt.allocPrint(allocator, "ssh -o UserKnownHostsFile=\"{s}\" -o IdentityFile=\"{s}\"", .{ known_hosts_path, priv_key_path });│ │1160 + } else null; │ │1161 + defer if (ssh_cmd_maybe) |ssh_cmd| allocator.free(ssh_cmd); │ │1162 + │ │1163 + const receive_pack_command = try receivePackCommand(server_repo_kind, is_ssh, true, allocator, cwd_path, port); │ │1164 + defer allocator.free(receive_pack_command); │ │1165 + │ │1166 + try client_repo.push( │ │1167 + io, │ │1168 + allocator, │ │1169 + "origin", │ │1170 + "master", │ │1171 + false, │ │1172 + .{ .refspecs = &.{ "refs/tags/1.0.0:refs/tags/1.0.0" }, .wire = .{ .ssh = .{ │ │1173 + .command = ssh_cmd_maybe, │ │1174 + .receive_pack_command = receive_pack_command, │ │1175 + } } }, │ │1176 + ); │ │1177 + │ │1178 + var server_repo = try rp.Repo(server_repo_kind, .{ .is_test = true }).open(io, allocator, .{ .path = server_path }); │ │1179 + defer server_repo.deinit(io, allocator); │ │1180 + │ │1181 + try std.testing.expect(null != try server_repo.readRef(io, .{ .kind = .tag, .name = "1.0.0" })); │ │1182 + │ │1183 + const oid_master = (try server_repo.readRef(io, .{ .kind = .head, .name = "master" })).?; │ │1184 + try std.testing.expectEqualStrings(&commit1, &oid_master); │ │1185 } │ │1186 │ │1187 fn testClone( │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯