╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ net.zig ──────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1558 1559 try client_repo.addRemote(io, allocator, .{ .name = "origin", .value = remote_url }); 1560 try client_repo.addConfig(io, allocator, .{ .name = "branch.master.remote", .value = "origin" }); 1561 } 1562 1563 const is_ssh = switch (transport_def) { 1564 .file => false, 1565 .wire => |wire_kind| .ssh == wire_kind, 1566 }; 1567 1568 const receive_pack_command = try receivePackCommand(is_ssh, allocator, cwd_path, port); 1569 defer allocator.free(receive_pack_command); 1570 1571 if (shell_out_to_git) { 1572 const priv_key_path = try std.fs.path.join(allocator, &.{ cwd_path, temp_dir_name, "key" }); 1573 defer allocator.free(priv_key_path); 1574 const ssh_config_arg = try std.fmt.allocPrint(allocator, "core.sshCommand=ssh -o StrictHostKeyChecking=no -o IdentityFile={s}", .{priv_key_path}); 1575 defer allocator.free(ssh_config_arg); 1576 1577 // shell out to git so it will send delta objects 1578 var process = try std.process.spawn(io, .{ 1579 .argv = if (is_ssh) 1580 &.{ "git", "-c", ssh_config_arg, "push", "--receive-pack", receive_pack_command, "origin", "master" } 1581 else 1582 &.{ "git", "push", "origin", "master" }, 1583 .cwd = .{ .path = client_path }, 1584 .stdin = .ignore, 1585 .stdout = .ignore, 1586 .stderr = .ignore, 1587 }); 1588 const term = try process.wait(io); 1589 if (term != .exited or term.exited != 0) { 1590 return error.GitCommandFailed; 1591 } 1592 } else { 1593 const ssh_cmd_maybe: ?[]const u8 = if (is_ssh) blk: { 1594 const known_hosts_path = try std.fs.path.join(allocator, &.{ cwd_path, temp_dir_name, "known_hosts" }); 1595 defer allocator.free(known_hosts_path); 1596 1597 const priv_key_path = try std.fs.path.join(allocator, &.{ cwd_path, temp_dir_name, "key" }); 1598 defer allocator.free(priv_key_path); 1599 1600 break :blk try std.fmt.allocPrint(allocator, "ssh -o UserKnownHostsFile=\"{s}\" -o IdentityFile=\"{s}\"", .{ known_hosts_path, priv_key_path }); 1601 } else null; 1602 defer if (ssh_cmd_maybe) |ssh_cmd| allocator.free(ssh_cmd); 1603 1604 try client_repo.push( 1605 io, 1606 allocator, 1607 "origin", 1608 "master", 1609 false, 1610 .{ .wire = .{ .ssh = .{ 1611 .command = ssh_cmd_maybe, 1612 .receive_pack_command = receive_pack_command, 1613 } } }, 1614 ); 1615 1616 if (transport_def == .file) { 1617 // update the working dir 1618 try server_repo.restore(io, allocator, "."); 1619 } 1620 } 1621 1622 // make sure push was successful 1623 { 1624 const oid_master = (try server_repo.readRef(io, .{ .kind = .head, .name = "master" })).?; 1625 try std.testing.expectEqualStrings(&commit2, &oid_master); 1626 1627 const hello_txt = try temp_dir.openFile(io, "repos/server/hello.txt", .{}); 1628 defer hello_txt.close(io); 1629 } 1630 } 1631 1632 fn copyDir(io: std.Io, src_dir: std.Io.Dir, dest_dir: std.Io.Dir) !void { 1633 var iter = src_dir.iterate(); 1634 while (try iter.next(io)) |entry| { 1635 switch (entry.kind) { 1636 .file => try src_dir.copyFile(entry.name, dest_dir, entry.name, io, .{}), 1637 .directory => { 1638 try dest_dir.createDirPath(io, entry.name); 1639 var dest_entry_dir = try dest_dir.openDir(io, entry.name, .{ .access_sub_paths = true, .iterate = true, .follow_symlinks = false }); 1640 defer dest_entry_dir.close(io); 1641 var src_entry_dir = try src_dir.openDir(io, entry.name, .{ .access_sub_paths = true, .iterate = true, .follow_symlinks = false }); 1642 defer src_entry_dir.close(io); 1643 try copyDir(io, src_entry_dir, dest_entry_dir); 1644 }, 1645 else => {}, 1646 } 1647 } 1648 } 1649