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