Elffuss BraidHub

utopia-ia/elffuss-braid public

Land: a first changeset without a parent lands without an update

Workspaces created before their branch existed make parentless first
changesets. Once another workspace had created the branch, land refused
them and asked for `braid update`. Such a changeset is based on the
empty tree, where every branch starts, so land now rebases it from
there, exactly as update does. A path the branch also added is a
conflict, never an overwrite.

Found by a stress run of many workspaces landing while processes were
killed at random.
Changeset1f36d778ef35c2ec35ce14861f1ccef1126d867b4926f516fa113d85d6c64760
AuthorKikoCis <KikoCis@users.noreply.github.com> · 2026-10-16 00:15 +02:00
CommitterKikoCis <KikoCis@users.noreply.github.com> · 2026-10-16 00:15 +02:00
Parents7c2ce6e49a3f

Browse the files at this changeset

2 files changed

modified crates/cli/tests/workspaces.rs +29 −0
@@ -1129,3 +1129,32 @@
11291129 }
11301130 assert!(repo.fsck_is_clean());
11311131 }
1132+
1133+#[test]
1134+fn workspaces_made_before_main_existed_land_without_an_update() {
1135+ // Both workspaces start on an empty branch, so their first changesets
1136+ // have no parent. The second to land is rebased from the empty tree.
1137+ let repo = Repo::new();
1138+ let a = repo.workspace("first-a");
1139+ let b = repo.workspace("first-b");
1140+ write(&a, "a.txt", "from a\n");
1141+ write(&b, "b.txt", "from b\n");
1142+ json(&a, &["commit", "-m", "a"]);
1143+ json(&b, &["commit", "-m", "b"]);
1144+ assert_eq!(json(&a, &["land"])["outcome"], "fast-forward");
1145+ let landed = json(&b, &["land"]);
1146+ assert_eq!(landed["outcome"], "rebased");
1147+ assert_eq!(read(&b, "a.txt"), "from a\n");
1148+
1149+ // The same path added on both sides is a conflict, never an overwrite.
1150+ let c = repo.workspace("first-c");
1151+ let d = repo.workspace("first-d");
1152+ write(&c, "same.txt", "from c\n");
1153+ write(&d, "same.txt", "from d\n");
1154+ json(&c, &["commit", "-m", "c"]);
1155+ json(&d, &["commit", "-m", "d"]);
1156+ json(&c, &["land"]);
1157+ let conflict = json_status(&d, &["land"], 2);
1158+ assert_eq!(conflict["conflicts"][0]["path"], "same.txt");
1159+ assert!(repo.fsck_is_clean());
1160+}
modified crates/wc/src/rebase.rs +9 −0
@@ -92,6 +92,15 @@
9292 _ => match land(objects, tip, change, committer.clone()) {
9393 Err(braid_engine::Error::BaseNotOnBranch { .. }) => match (first, tip) {
9494 (First::Anywhere, Some(onto)) => replay_one(objects, onto, change, committer)?,
95+ // A first changeset without a parent is based on the
96+ // empty tree, where every branch starts: rebase it from
97+ // there rather than asking for an update. A path the
98+ // branch added too is a conflict, never overwritten.
99+ (First::MustBeOnBranch, Some(onto))
100+ if read_changeset(objects, change)?.parents.is_empty() =>
101+ {
102+ replay_one(objects, onto, change, committer)?
103+ }
95104 _ => {
96105 return Err(Error::NotOnBranch {
97106 branch: branch.to_owned(),