Artifactspublic-v0

ply

main
ply4 git calls309 ms41 KiB2 cachedprotocol v2
97 lines7.2 KiBRaw
1// The rename guard's one-sided removal trigger, decided by git. ply does not detect renames; when both sides changed a
2// directory identically, the merge takes it unread, and a rename both sides made inside it stays hidden. That is safe
3// only while neither side added or removed a path of its own: a file one side alone deleted is a second rename source
4// on that side, so git may pair the shared add with it there and with the shared delete on the other side, and report
5// CONFLICT (rename/delete). The guard therefore enters the shared subtrees when a side removed a path, not only when a
6// side added one. These shapes have no add outside the shared subtree and no conflict in the walk: the removal is the
7// only thing that makes ply look.
8//
9// The oracle is `git merge-tree --write-tree` (exit status, tree id and messages, git's defaults) on three trees built
10// with git plumbing, run here for every case; `git diff-tree -M` says the stand-down shape hides a rename. Nothing is
11// expected from ply that git did not say first:
12//
13// git conflict ⇒ ply merge_conflict
14// ply ok ⇒ git clean, and the same tree id
15import { test, beforeAll as before, afterAll as after } from 'vitest';
16import assert from 'node:assert/strict';
17import { join } from 'node:path';
18import { spawnSync } from 'node:child_process';
19import { tmpRoot, makeBareRepo, startGitServer } from './server.js';
20import { oracleRediff } from './gitversion.js';
21import { mergeBranch } from '../src/merge.js';
22import { Tracer, arrayExporter } from '../src/otel.js';
24const rediff = oracleRediff();
25const ENV = { ...process.env, GIT_AUTHOR_NAME: 'w', GIT_AUTHOR_EMAIL: 'w@x', GIT_COMMITTER_NAME: 'w', GIT_COMMITTER_EMAIL: 'w@x', GIT_AUTHOR_DATE: '1700000000 +0000', GIT_COMMITTER_DATE: '1700000000 +0000', GIT_CONFIG_COUNT: '1', GIT_CONFIG_KEY_0: 'commit.gpgsign', GIT_CONFIG_VALUE_0: 'false' };
26const EMPTY_TREE = '4b825dc642cb6eb9a060e54bf8d69288fbee4904';
27const author = { name: 'm', email: 'm@x', time: 1700000001 };
28const opts = () => ({ tracer: new Tracer({ exporter: arrayExporter() }), rediff });
30let root, cleanup, srv, bare, url, seq = 0;
31const blobs = new Map();
32const sh = (args, input, env = {}) => spawnSync('git', ['-C', bare, ...args], { encoding: 'utf8', env: { ...ENV, ...env }, input, maxBuffer: 1 << 26 });
33const must = (args, input, env) => { const r = sh(args, input, env); assert.equal(r.status, 0, `git ${args.join(' ')}: ${r.stderr}`); return r.stdout.trim(); };
34before(async () => { ({ root, cleanup } = tmpRoot()); srv = await startGitServer(root); bare = makeBareRepo(root, 'rnrm'); url = `${srv.url}/rnrm.git`; });
35after(async () => { await srv?.close(); cleanup?.(); });
37// a tree from { path: content }, with git: hash-object per distinct content, one update-index, write-tree
38const blob = data => { let oid = blobs.get(data); if (oid === undefined) { oid = must(['hash-object', '-w', '--stdin'], data); blobs.set(data, oid); } return oid; };
39const tree = files => {
40 const env = { GIT_INDEX_FILE: join(root, `idx${seq++}`) };
41 must(['update-index', '--add', '--index-info'], Object.keys(files).map(p => `100644 ${blob(files[p])}\t${p}\n`).join(''), env);
42 return must(['write-tree'], undefined, env);
43};
44const commit = (t, parents, msg) => must(['commit-tree', t, ...parents.flatMap(p => ['-p', p]), '-m', msg]);
46// One three-way case: git's verdict and ply's, side by side. Each case has its own pair of refs.
47async function both(base, ours, theirs) {
48 const cb = commit(tree(base), [], 'base'); const co = commit(tree(ours), [cb], 'ours'); const ct = commit(tree(theirs), [cb], 'theirs');
49 const id = seq++;
50 must(['update-ref', `refs/heads/o${id}`, co]); must(['update-ref', `refs/heads/t${id}`, ct]);
51 const gm = sh(['-c', `attr.tree=${EMPTY_TREE}`, 'merge-tree', '--write-tree', '--name-only', co, ct]);
52 assert.ok(gm.status === 0 || gm.status === 1, gm.stderr);
53 const git = { clean: gm.status === 0, tree: gm.stdout.split('\n')[0].trim(), info: gm.stdout.split('\n\n').slice(1).join(' ').replace(/\s+/g, ' ').trim() };
54 const r = await mergeBranch(url, { ref: `refs/heads/o${id}`, from: `refs/heads/t${id}`, author }, opts());
55 return { git, r, commits: { base: cb, ours: co, theirs: ct } };
58const lines = (n, f = i => `line ${i}`) => `${Array.from({ length: n }, (_, i) => f(i)).join('\n')}\n`;
59const C = lines(30);
60// C with every third line changed: similar enough for git to pair it with C (over 50%), not identical
61const P = lines(30, i => (i % 3 === 0 ? `changed ${i}` : `line ${i}`));
62const K = { keep: 'keep\n' };
64// In each shape both sides replace x/f (C) with x/g (P), so x is one tree on ours and theirs, and one side alone
65// deletes a file whose bytes are exactly x/g's. On that side git pairs x/g with the exact twin and x/f is a plain
66// delete; on the other side x/g pairs with x/f. git: rename/delete.
67const REMOVALS = [
68 ['V0 ours alone deletes the root file y', { ...K, 'x/f': C, 'x/h': 'h\n', y: P }, { ...K, 'x/g': P, 'x/h': 'h\n' }, { ...K, 'x/g': P, 'x/h': 'h\n', y: P }],
69 ['V1 theirs alone deletes the root file y', { ...K, 'x/f': C, 'x/h': 'h\n', y: P }, { ...K, 'x/g': P, 'x/h': 'h\n', y: P }, { ...K, 'x/g': P, 'x/h': 'h\n' }],
70 ['V2 the deleted file sits in a directory only ours changed (y/t)', { ...K, 'x/f': C, 'x/h': 'h\n', 'y/t': P, 'y/k': 'k\n' }, { ...K, 'x/g': P, 'x/h': 'h\n', 'y/k': 'k\n' }, { ...K, 'x/g': P, 'x/h': 'h\n', 'y/t': P, 'y/k': 'k\n' }],
71];
72for (const [name, base, ours, theirs] of REMOVALS) {
73 test(`one-sided removal beside a rename hidden in a shared subtree == git merge-tree: ${name}`, async () => {
74 const { git, r } = await both(base, ours, theirs);
75 // the shape is what its name says, by git
76 assert.equal(git.clean, false, `git merges this clean (tree ${git.tree})`);
77 assert.match(git.info, /CONFLICT \(rename\/delete\): x\/f renamed to x\/g/, git.info);
78 // so ply must refuse
79 assert.equal(r.ok, false, `${name}: ply merged clean (tree ${r.ok ? r.value.tree : ''}) where git conflicts: ${git.info}`);
80 assert.equal(r.error.code, 'merge_conflict', `${name}: ${r.error.code} ${r.error.message}`);
81 });
84test('the guard stands down over a rename hidden in a shared subtree when the sides differ only by edits elsewhere: the same tree as git merge-tree', async () => {
85 // V0 with y kept on both sides: the same hidden rename, and nothing added or removed by one side alone. Both sides
86 // give rename detection the same sources and targets, so git pairs x/f with x/g on both and merges clean.
87 const { git, r, commits } = await both(
88 { ...K, 'x/f': C, 'x/h': 'h\n', y: P, a: 'a\n', b: 'b\n' },
89 { ...K, 'x/g': P, 'x/h': 'h\n', y: P, a: 'a2\n', b: 'b\n' },
90 { ...K, 'x/g': P, 'x/h': 'h\n', y: P, a: 'a\n', b: 'b2\n' });
91 // the rename is there, by git, on each side
92 for (const side of [commits.ours, commits.theirs]) assert.match(must(['diff-tree', '-r', '-M', '--name-status', commits.base, side]), /^R\d+\tx\/f\tx\/g$/m);
93 assert.equal(git.clean, true, `git: ${git.info}`);
94 assert.equal(r.ok, true, `git is clean and no side added or removed a path of its own, so must ply be (${r.ok ? '' : `${r.error.code} ${JSON.stringify(r.error.reasons)}`})`);
95 assert.equal(r.value.outcome, 'merge');
96 assert.equal(r.value.tree, git.tree, 'ply\'s clean tree differs from git\'s');
97});
Diagnostics4 git calls · 309 ms
CallStatusSizeTime0309 ms
discover200152 B3 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
git.response.bytes=152
git.server.agent=gitty/1.0
git.server.object_format=sha1
git.server.caps=agent ls-refs fetch object-format
git.server.fetch=shallow filter sideband-all
git.protocol.version=2
git.pkt.frames=8
git.pkt.data=6
git.pkt.flush=2
git.pkt.delim=0
git.pkt.bytes=152
git.pkt.payload.max=34
ls-refs200145 B · hit3 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=3
git.response.bytes=145
git.response.cache=HIT
git.response.duration_ms=3
git.protocol.version=2
git.pkt.frames=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=145
git.pkt.payload.max=76
git.ls_refs.count=2
git.ls_refs.head=refs/heads/main
fetchblob:none · deepen 1020038 KiB · hit7 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=299
git.response.bytes=38434
git.response.cache=HIT
git.response.duration_ms=7
git.fetch.filter=blob:none
git.fetch.filter.requested=tree:0
git.fetch.filter.fallback=blob:none
git.fetch.filter.learned=false
git.fetch.wants=19912563f540228593df0c489082e5e2508e21e4
git.fetch.haves.count=0
git.fetch.deepen=10
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=6
git.pkt.data=4
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=38434
git.pkt.payload.max=38339
git.sideband.band1.bytes=38338
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=63
git.pack.bytes=38338
git.pack.ofs_delta=0
git.pack.ref_delta=8
git.pack.chain.max=8
git.pack.trailer=0bc36ab7adf82d3109177f11f1ea93f1ce071f77
git.pack.full=55
Open pack map
fetch2003.0 KiB299 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=3093
git.response.cache=MISS
git.response.duration_ms=299
git.fetch.wants=3c20fe68bc8dd77eb2954c8078f345021b602c16
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=3093
git.pkt.payload.max=3072
git.sideband.band1.bytes=3071
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0

Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.

Remote
https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/ply.git
Ref
refs/heads/main
Commit
19912563f540228593df0c489082e5e2508e21e4
cf-ray
a5e371f0690422ce
Request
015f4c08…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format