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