╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ ui.zig ───────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
89 const RemoteRepo = xit.repo.Repo(.git, .{}); 90 { 91 var remote = try RemoteRepo.init(io, allocator, .{ .path = remote_path }); 92 remote.deinit(io, allocator); 93 } 94 { 95 var local = try Repo.init(io, allocator, .{ .path = local_path }); 96 defer local.deinit(io, allocator); 97 try local.addConfig(io, allocator, .{ .name = "user.name", .value = "user" }); 98 try local.addConfig(io, allocator, .{ .name = "user.email", .value = "user@haxy" }); 99 { 100 const file = try local.core.work_dir.createFile(io, "keep.txt", .{}); 101 defer file.close(io); 102 try file.writeStreamingAll(io, "keep"); 103 } 104 try local.add(io, allocator, &.{"keep.txt"}); 105 _ = try local.commit(io, allocator, .{ .message = "master" }); 106 try local.addRemote(io, allocator, .{ .name = "origin", .value = remote_path }); 107 108 const id = [_]u8{1} ** evt.event_id_size; 109 try evt.consume(.repo, .git, .{}, io, allocator, &local, evt.events_ref, &.{.{ 110 .id = std.fmt.bytesToHex(id, .lower), 111 .author = .{ .name = "haxy", .email = "user@haxy" }, 112 .event = .{ .issue = .{ .title = "sync", .description = "", .tags = "" } }, 113 }}); 114 } 115 116 try std.testing.expectEqual(null, try Events.sync(io, allocator, .{ .path = local_path, .repo_kind = .git })); 117 { 118 var local = try Repo.open(io, allocator, .{ .path = local_path }); 119 defer local.deinit(io, allocator); 120 const id = [_]u8{2} ** evt.event_id_size; 121 try evt.consume(.repo, .git, .{}, io, allocator, &local, evt.events_ref, &.{.{ 122 .id = std.fmt.bytesToHex(id, .lower), 123 .author = .{ .name = "haxy", .email = "user@haxy" }, 124 .event = .{ .issue = .{ .title = "local", .description = "", .tags = "" } }, 125 }}); 126 } 127 { 128 var remote = try RemoteRepo.open(io, allocator, .{ .path = remote_path }); 129 defer remote.deinit(io, allocator); 130 const id = [_]u8{3} ** evt.event_id_size; 131 try evt.consume(.repo, .git, .{}, io, allocator, &remote, evt.events_ref, &.{.{ 132 .id = std.fmt.bytesToHex(id, .lower), 133 .author = .{ .name = "haxy", .email = "user@haxy" }, 134 .event = .{ .issue = .{ .title = "remote", .description = "", .tags = "" } }, 135 }}); 136 } 137 try std.testing.expectEqual(null, try Events.sync(io, allocator, .{ .path = local_path, .repo_kind = .git })); 138 { 139 var local = try Repo.open(io, allocator, .{ .path = local_path }); 140 defer local.deinit(io, allocator); 141 try local.removeBranch(io, .{ .name = evt.events_ref.name }); 142 try evt.consume(.repo, .git, .{}, io, allocator, &local, evt.events_ref, &.{}); 143 } 144 try std.testing.expectEqual(null, try Events.sync(io, allocator, .{ .path = local_path, .repo_kind = .git })); 145 146 var local = try Repo.open(io, allocator, .{ .path = local_path }); 147 defer local.deinit(io, allocator); 148 var head_buffer: [xit.ref.MAX_REF_CONTENT_SIZE]u8 = undefined; 149 const head = try local.head(io, &head_buffer); 150 switch (head) { 151 .ref => |ref| try std.testing.expectEqualStrings("master", ref.name), 152 .oid => return error.TestExpectedEqual, 153 } 154 const kept = try local.core.work_dir.openFile(io, "keep.txt", .{}); 155 kept.close(io); 156 const local_tip = (try local.readRef(io, evt.events_ref)) orelse return error.TestExpectedEqual; 157 158 var remote = try RemoteRepo.open(io, allocator, .{ .path = remote_path }); 159 defer remote.deinit(io, allocator); 160 const remote_tip = (try remote.readRef(io, evt.events_ref)) orelse return error.TestExpectedEqual; 161 try std.testing.expectEqualStrings(&local_tip, &remote_tip); 162 163 var start_oids = [_][local_tip.len]u8{local_tip}; 164 var commit_iter = try local.log(io, allocator, .{ .start_oids = &start_oids }); 165 defer commit_iter.deinit(); 166 var merge_commit = (try commit_iter.next(allocator)) orelse return error.TestExpectedEqual; 167 defer merge_commit.deinit(); 168 const parent_oids = merge_commit.content.commit.metadata.parent_oids orelse return error.TestExpectedEqual; 169 try std.testing.expectEqual(2, parent_oids.len); 170 171 var arena = std.heap.ArenaAllocator.init(allocator); 172 defer arena.deinit(); 173 const status = try Events.Header.local(.git, .{}, arena.allocator(), &local, io, null); 174 try std.testing.expectEqualStrings("nothing to sync", status.sync_status orelse return error.TestExpectedEqual); 175 } 176