╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ ui.zig ───────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
325 326 const local_path = try std.fs.path.join(allocator, &.{ temp_path, "local" }); 327 defer allocator.free(local_path); 328 const remote_path = try std.fs.path.join(allocator, &.{ temp_path, "remote" }); 329 defer allocator.free(remote_path); 330 331 const Repo = xit.repo.Repo(.git, .{}); 332 const RemoteRepo = xit.repo.Repo(.git, .{}); 333 { 334 var remote = try RemoteRepo.init(io, allocator, .{ .path = remote_path }); 335 remote.deinit(io, allocator); 336 } 337 { 338 var local = try Repo.init(io, allocator, .{ .path = local_path }); 339 defer local.deinit(io, allocator); 340 try local.addConfig(io, allocator, .{ .name = "user.name", .value = "user" }); 341 try local.addConfig(io, allocator, .{ .name = "user.email", .value = "user@haxy" }); 342 { 343 const file = try local.core.work_dir.createFile(io, "keep.txt", .{}); 344 defer file.close(io); 345 try file.writeStreamingAll(io, "keep"); 346 } 347 try local.add(io, allocator, &.{"keep.txt"}); 348 _ = try local.commit(io, allocator, .{ .message = "master" }); 349 try local.addRemote(io, allocator, .{ .name = "origin", .value = remote_path }); 350 351 const id = [_]u8{1} ** evt.event_id_size; 352 try evt.consume(.local, .repo, .git, .{}, io, allocator, &local, evt.events_ref, &.{.{ 353 .id = std.fmt.bytesToHex(id, .lower), 354 .author = .{ .name = "haxy", .email = "user@haxy" }, 355 .event = .{ .issue = .{ .title = "sync", .description = "", .tags = "" } }, 356 }}); 357 } 358 359 try std.testing.expectEqual(null, try Events.sync(io, allocator, .{ .path = local_path, .repo_kind = .git })); 360 { 361 var local = try Repo.open(io, allocator, .{ .path = local_path }); 362 defer local.deinit(io, allocator); 363 const id = [_]u8{2} ** evt.event_id_size; 364 try evt.consume(.local, .repo, .git, .{}, io, allocator, &local, evt.events_ref, &.{.{ 365 .id = std.fmt.bytesToHex(id, .lower), 366 .author = .{ .name = "haxy", .email = "user@haxy" }, 367 .event = .{ .issue = .{ .title = "local", .description = "", .tags = "" } }, 368 }}); 369 } 370 { 371 var remote = try RemoteRepo.open(io, allocator, .{ .path = remote_path }); 372 defer remote.deinit(io, allocator); 373 const id = [_]u8{3} ** evt.event_id_size; 374 try evt.consume(.local, .repo, .git, .{}, io, allocator, &remote, evt.events_ref, &.{.{ 375 .id = std.fmt.bytesToHex(id, .lower), 376 .author = .{ .name = "haxy", .email = "user@haxy" }, 377 .event = .{ .issue = .{ .title = "remote", .description = "", .tags = "" } }, 378 }}); 379 } 380 try std.testing.expectEqual(null, try Events.sync(io, allocator, .{ .path = local_path, .repo_kind = .git })); 381 { 382 var local = try Repo.open(io, allocator, .{ .path = local_path }); 383 defer local.deinit(io, allocator); 384 try local.removeBranch(io, .{ .name = evt.events_ref.name }); 385 try evt.consume(.local, .repo, .git, .{}, io, allocator, &local, evt.events_ref, &.{}); 386 } 387 try std.testing.expectEqual(null, try Events.sync(io, allocator, .{ .path = local_path, .repo_kind = .git })); 388 389 var local = try Repo.open(io, allocator, .{ .path = local_path }); 390 defer local.deinit(io, allocator); 391 var head_buffer: [xit.ref.MAX_REF_CONTENT_SIZE]u8 = undefined; 392 const head = try local.head(io, &head_buffer); 393 switch (head) { 394 .ref => |ref| try std.testing.expectEqualStrings("master", ref.name), 395 .oid => return error.TestExpectedEqual, 396 } 397 const kept = try local.core.work_dir.openFile(io, "keep.txt", .{}); 398 kept.close(io); 399 const local_tip = (try local.readRef(io, evt.events_ref)) orelse return error.TestExpectedEqual; 400 401 var remote = try RemoteRepo.open(io, allocator, .{ .path = remote_path }); 402 defer remote.deinit(io, allocator); 403 const remote_tip = (try remote.readRef(io, evt.events_ref)) orelse return error.TestExpectedEqual; 404 try std.testing.expectEqualStrings(&local_tip, &remote_tip); 405 406 var start_oids = [_][local_tip.len]u8{local_tip}; 407 var commit_iter = try local.log(io, allocator, .{ .start_oids = &start_oids }); 408 defer commit_iter.deinit(); 409 var merge_commit = (try commit_iter.next(allocator)) orelse return error.TestExpectedEqual; 410 defer merge_commit.deinit(); 411 const parent_oids = merge_commit.content.commit.metadata.parent_oids orelse return error.TestExpectedEqual; 412 try std.testing.expectEqual(2, parent_oids.len); 413 414 var arena = std.heap.ArenaAllocator.init(allocator); 415 defer arena.deinit(); 416 const status = try Events.Header.local(.git, .{}, arena.allocator(), &local, io, null); 417 try std.testing.expectEqualStrings("nothing to sync", status.sync_status orelse return error.TestExpectedEqual); 418 } 419