╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ test.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1618 }; 1619 1620 const receive_pack_command = try switch (server_repo_kind) { 1621 .xit => std.fmt.allocPrint(allocator, "{s}/zig-out/bin/haxy receive-pack", .{cwd_path}), 1622 .git => allocator.dupe(u8, "git-receive-pack"), 1623 }; 1624 defer allocator.free(receive_pack_command); 1625 1626 if (shell_out_to_git) { 1627 const priv_key_path = try std.fs.path.join(allocator, &.{ cwd_path, temp_dir_name, "key" }); 1628 defer allocator.free(priv_key_path); 1629 const ssh_config_arg = try std.fmt.allocPrint(allocator, "core.sshCommand=ssh -o StrictHostKeyChecking=no -o IdentityFile={s}", .{priv_key_path}); 1630 defer allocator.free(ssh_config_arg); 1631 1632 // shell out to git so it will send delta objects 1633 var process = try std.process.spawn(io, .{ 1634 .argv = if (is_ssh) 1635 &.{ "git", "-c", ssh_config_arg, "push", "--receive-pack", receive_pack_command, "origin", "master" } 1636 else 1637 &.{ "git", "push", "origin", "master" }, 1638 .cwd = .{ .path = client_path }, 1639 .stdin = .ignore, 1640 .stdout = .ignore, 1641 .stderr = .ignore, 1642 }); 1643 const term = try process.wait(io); 1644 if (term != .exited) { 1645 return error.GitCommandFailed; 1646 } 1647 } else { 1648 const ssh_cmd_maybe: ?[]const u8 = if (is_ssh) blk: { 1649 const known_hosts_path = try std.fs.path.join(allocator, &.{ cwd_path, temp_dir_name, "known_hosts" }); 1650 defer allocator.free(known_hosts_path); 1651 1652 const priv_key_path = try std.fs.path.join(allocator, &.{ cwd_path, temp_dir_name, "key" }); 1653 defer allocator.free(priv_key_path); 1654 1655 break :blk try std.fmt.allocPrint(allocator, "ssh -o UserKnownHostsFile=\"{s}\" -o IdentityFile=\"{s}\"", .{ known_hosts_path, priv_key_path }); 1656 } else null; 1657 defer if (ssh_cmd_maybe) |ssh_cmd| allocator.free(ssh_cmd); 1658 1659 try client_repo.push( 1660 io, 1661 allocator, 1662 "origin", 1663 "master", 1664 false, 1665 .{ .wire = .{ .ssh = .{ 1666 .command = ssh_cmd_maybe, 1667 .receive_pack_command = receive_pack_command, 1668 } } }, 1669 ); 1670 1671 if (transport_def == .file) { 1672 // update the working dir 1673 try server_repo.restore(io, allocator, "."); 1674 } 1675 } 1676 1677 // make sure push was successful 1678 { 1679 const oid_master = (try server_repo.readRef(io, .{ .kind = .head, .name = "master" })).?; 1680 try std.testing.expectEqualStrings(&commit2, &oid_master); 1681 1682 const hello_txt = try temp_dir.openFile(io, "server/hello.txt", .{}); 1683 defer hello_txt.close(io); 1684 } 1685 } 1686 1687 fn copyDir(io: std.Io, src_dir: std.Io.Dir, dest_dir: std.Io.Dir) !void { 1688 var iter = src_dir.iterate(); 1689 while (try iter.next(io)) |entry| { 1690 switch (entry.kind) { 1691 .file => try src_dir.copyFile(entry.name, dest_dir, entry.name, io, .{}), 1692 .directory => { 1693 try dest_dir.createDirPath(io, entry.name); 1694 var dest_entry_dir = try dest_dir.openDir(io, entry.name, .{ .access_sub_paths = true, .iterate = true, .follow_symlinks = false }); 1695 defer dest_entry_dir.close(io); 1696 var src_entry_dir = try src_dir.openDir(io, entry.name, .{ .access_sub_paths = true, .iterate = true, .follow_symlinks = false }); 1697 defer src_entry_dir.close(io); 1698 try copyDir(io, src_entry_dir, dest_entry_dir); 1699 }, 1700 else => {}, 1701 } 1702 } 1703 } 1704