╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ net.zig ──────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1276 1277 // shell out to git so it will send delta objects 1278 var process = try std.process.spawn(io, .{ 1279 .argv = if (is_ssh) 1280 &.{ "git", "-c", ssh_config_arg, "push", "origin", "master" } 1281 else 1282 &.{ "git", "push", "origin", "master" }, 1283 .cwd = .{ .path = client_path }, 1284 .stdin = .ignore, 1285 .stdout = .ignore, 1286 .stderr = .ignore, 1287 }); 1288 const term = try process.wait(io); 1289 if (term != .exited or term.exited != 0) { 1290 return error.GitCommandFailed; 1291 } 1292 } else { 1293 const ssh_cmd_maybe: ?[]const u8 = if (is_ssh) blk: { 1294 const known_hosts_path = try std.fs.path.join(allocator, &.{ cwd_path, temp_dir_name, "known_hosts" }); 1295 defer allocator.free(known_hosts_path); 1296 1297 const priv_key_path = try std.fs.path.join(allocator, &.{ cwd_path, temp_dir_name, "key" }); 1298 defer allocator.free(priv_key_path); 1299 1300 break :blk try std.fmt.allocPrint(allocator, "ssh -o UserKnownHostsFile=\"{s}\" -o IdentityFile=\"{s}\"", .{ known_hosts_path, priv_key_path }); 1301 } else null; 1302 defer if (ssh_cmd_maybe) |ssh_cmd| allocator.free(ssh_cmd); 1303 1304 try client_repo.push( 1305 io, 1306 allocator, 1307 "origin", 1308 "master", 1309 false, 1310 .{ .wire = .{ .ssh = .{ 1311 .command = ssh_cmd_maybe, 1312 } } }, 1313 ); 1314 1315 if (transport_def == .file) { 1316 // update the working dir 1317 try server_repo.restore(io, allocator, "."); 1318 } 1319 } 1320 1321 // make sure push was successful 1322 { 1323 const oid_master = (try server_repo.readRef(io, .{ .kind = .head, .name = "master" })).?; 1324 try std.testing.expectEqualStrings(&commit2, &oid_master); 1325 1326 const hello_txt = try temp_dir.openFile(io, "repos/server/hello.txt", .{}); 1327 defer hello_txt.close(io); 1328 } 1329 } 1330 1331 fn copyDir(io: std.Io, src_dir: std.Io.Dir, dest_dir: std.Io.Dir) !void { 1332 var iter = src_dir.iterate(); 1333 while (try iter.next(io)) |entry| { 1334 switch (entry.kind) { 1335 .file => try src_dir.copyFile(entry.name, dest_dir, entry.name, io, .{}), 1336 .directory => { 1337 try dest_dir.createDirPath(io, entry.name); 1338 var dest_entry_dir = try dest_dir.openDir(io, entry.name, .{ .access_sub_paths = true, .iterate = true, .follow_symlinks = false }); 1339 defer dest_entry_dir.close(io); 1340 var src_entry_dir = try src_dir.openDir(io, entry.name, .{ .access_sub_paths = true, .iterate = true, .follow_symlinks = false }); 1341 defer src_entry_dir.close(io); 1342 try copyDir(io, src_entry_dir, dest_entry_dir); 1343 }, 1344 else => {}, 1345 } 1346 } 1347 } 1348