╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ patch.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1228 .title = "edit the answer", 1229 .labels = patch.labels, 1230 .description = patch.description, 1231 .target_branch = patch.target_branch, 1232 } }; 1233 try evt.Patch.update(.local, .xit, repo_opts, io, allocator, target, id, edit, author); 1234 try std.testing.expectEqualDeep(pch.Mergeability{}, try readMergeability(target, io, allocator, id, patch)); 1235 _ = try evt.Comment.create(.{ .server = .{ .users_dir = users_dir } }, .xit, repo_opts, io, allocator, target, &input.id, &input.id, "reviewing the answer", author); 1236 try std.testing.expectEqualDeep(pch.Mergeability{}, try readMergeability(target, io, allocator, id, patch)); 1237 1238 // a server patch edit refreshes its mergeability 1239 edit.fields.title = patch.title; 1240 const before_edit = try target.core.db.rootCursor().count(); 1241 try evt.Patch.update(.{ .server = .{ .users_dir = users_dir } }, .xit, repo_opts, io, allocator, target, id, edit, author); 1242 try std.testing.expectEqual(before_edit + 1, try target.core.db.rootCursor().count()); 1243 const events_before = try target.readRef(io, evt.events_ref); 1244 try std.testing.expectEqualDeep(pch.Mergeability{ .source = .conflict, .squash = .conflict }, try readMergeability(target, io, allocator, id, patch)); 1245 try expectMergeabilityShortBytes(try target.core.latestMoment(), id); 1246 try std.testing.expectError(error.MergeConflict, pch.merge(repo_opts, io, allocator, users_dir, target, input)); 1247 try std.testing.expectError(error.MergeConflict, pch.merge(repo_opts, io, allocator, users_dir, target, squash_input)); 1248 try std.testing.expectEqual(events_before, try target.readRef(io, evt.events_ref)); 1249 try std.testing.expectEqual(conflicting_target, (try target.readRef(io, .{ .kind = .head, .name = "master" })).?); 1250 try std.testing.expectEqual(null, try target.readRef(io, .{ .kind = .none, .name = "MERGE_HEAD" })); 1251 1252 // deleting and restoring the target cannot reuse the conflict result 1253 { 1254 var detached = try target.switchDir(io, allocator, .{ .target = .{ .oid = base } }); 1255 defer detached.deinit(); 1256 } 1257 try target.removeBranch(io, .{ .name = "master" }); 1258 pch.refreshOpenMergeability(repo_opts, io, allocator, target, users_dir, null, null); 1259 try std.testing.expectEqualDeep(pch.Mergeability{}, try readMergeability(target, io, allocator, id, patch)); 1260 try expectMergeabilityShortBytes(try target.core.latestMoment(), id); 1261 try target.addBranch(io, .{ .name = "master" }); 1262 { 1263 var restored = try target.switchDir(io, allocator, .{ .target = .{ .ref = .{ .kind = .head, .name = "master" } } }); 1264 defer restored.deinit(); 1265 } 1266 pch.refreshOpenMergeability(repo_opts, io, allocator, target, users_dir, null, null); 1267 try std.testing.expectEqualDeep(clean, try readMergeability(target, io, allocator, id, patch)); 1268 1269 // a missing fork disables merging without changing the accepted events 1270 const draft_path = try fork.forkPath(allocator, users_dir, forker_id, id); 1271 defer allocator.free(draft_path); 1272 const away_path = try std.fmt.allocPrint(allocator, "{s}.away", .{draft_path}); 1273 defer allocator.free(away_path); 1274 { 1275 try std.Io.Dir.renameAbsolute(draft_path, away_path, io); 1276 defer std.Io.Dir.renameAbsolute(away_path, draft_path, io) catch {}; 1277 { 1278 const log_level = std.testing.log_level; 1279 std.testing.log_level = .err; 1280 defer std.testing.log_level = log_level; 1281 try std.testing.expectError(error.PatchDataUnavailable, pch.merge(repo_opts, io, allocator, users_dir, target, input)); 1282 } 1283 try std.testing.expectEqualDeep(pch.Mergeability{}, try readMergeability(target, io, allocator, id, patch)); 1284 try std.testing.expectEqual(events_before, try target.readRef(io, evt.events_ref)); 1285 } 1286 pch.refreshMergeability(repo_opts, io, allocator, target, users_dir, id.*); 1287 try std.testing.expectEqualDeep(clean, try readMergeability(target, io, allocator, id, patch)); 1288 1289 // a changed revision is unknown even if its target has not moved 1290 var changed = patch; 1291 changed.revision.?.id[0] = if (changed.revision.?.id[0] == 'a') 'b' else 'a'; 1292 try std.testing.expectEqualDeep(pch.Mergeability{}, try readMergeability(target, io, allocator, id, changed)); 1293 } 1294