1use std::path::Path;
29use std::time::Duration;
30
31use anyhow::{Context as _, Result};
32use jiff::Timestamp;
33
34use crate::agent::{self, Invocation};
35use crate::git;
36use crate::land::seat_of;
37use crate::prompt;
38use crate::run::{QuotaLoss, RebaseFixRecord, RunState};
39
40#[derive(Debug, Clone, PartialEq, Eq)]
42pub enum Rebased {
43 Applied,
46 Stopped(String),
50}
51
52const HUNK_PER_FILE: usize = 4_000;
54const HUNK_TOTAL: usize = 16_000;
55const SUBJECTS: usize = 20;
57const PATHS_IN_REASON: usize = 8;
59
60pub async fn rebase_with_fixer(
66 state: &mut RunState,
67 scratch: &Path,
68 branch: &str,
69 onto: &str,
70) -> Result<Rebased> {
71 let repo = state.repo.clone();
72 let cap = state.config.graph.review_rounds;
73 let orig = git::rev_parse(&repo, &format!("refs/heads/{branch}")).await?;
74
75 let mut said = String::new();
76 if !git::rebase_in_progress(scratch).await {
77 match git::rebase_start(&repo, scratch, branch, onto).await? {
78 git::RebaseStart::Applied => return Ok(Rebased::Applied),
79 git::RebaseStart::Failed(why) => return Ok(Rebased::Stopped(why)),
80 git::RebaseStart::Conflicted(why) => said = why,
81 }
82 }
83 let onto_sha = git::rev_parse(&repo, onto).await?;
84 let mut touched: Vec<String> = Vec::new();
87
88 loop {
89 if !git::rebase_in_progress(scratch).await {
90 return finish(state, scratch, branch, &orig, &onto_sha, &touched, &said).await;
91 }
92 let paths = git::unmerged_paths(scratch).await.unwrap_or_default();
93 for p in &paths {
94 if !touched.contains(p) {
95 touched.push(p.clone());
96 }
97 }
98 let spent = state.rebase_fixes.len();
99 if spent >= cap {
100 let why = reason(spent, cap, &paths, &said, "the rounds are spent");
101 abandon(&repo, scratch, branch, &orig).await;
102 return Ok(Rebased::Stopped(why));
103 }
104
105 let winner = state
106 .winner()
107 .cloned()
108 .context("resolving a rebase conflict needs a winning candidate")?;
109 let roles = state
110 .config
111 .resolve_roles()
112 .context("resolve the roster for the rebase fix")?;
113 let attempts = crate::fixer::attempts(state, &roles, &winner);
115 let ids: Vec<String> = attempts.iter().map(|(s, _)| s.id.clone()).collect();
116
117 let round = spent + 1;
118 let branch_subjects = subjects(scratch, &format!("{onto}..{branch}")).await;
119 let onto_subjects = subjects(scratch, &format!("{branch}..{onto}")).await;
120 let hunks = hunks(scratch, &paths);
121 let prompt_text = prompt::rebase_conflict(&prompt::RebaseConflict {
122 instruction: &state.instruction,
123 worktree: scratch,
124 branch,
125 onto,
126 paths: &paths,
127 branch_subjects: &branch_subjects,
128 onto_subjects: &onto_subjects,
129 hunks: &hunks,
130 round,
131 cap,
132 language: &state.config.graph.language,
133 });
134 let prompt_text = if state.config.cache_dir().is_some() {
135 format!("{prompt_text}\n\n{}", prompt::build_cache_note("fix", true))
136 } else {
137 prompt_text
138 };
139
140 state.rebase_fixes.push(RebaseFixRecord {
143 agent: ids[0].clone(),
144 paths: paths.clone(),
145 from: Some(orig.clone()),
146 finished: false,
147 error: None,
148 });
149 state.event(
150 "rebase",
151 format!(
152 "{branch} conflicts with {onto} ({} path(s)); fixer round {round} of {cap}",
153 paths.len()
154 ),
155 );
156 state.save()?;
157
158 let artifacts = agent::artifacts_dir(&state.dir());
163 let mut last = None;
164 for (i, (spec, seat_key)) in attempts.into_iter().enumerate() {
165 if i > 0 {
166 if let Some(r) = state.rebase_fixes.last_mut() {
167 r.agent = spec.id.clone();
168 }
169 state.save()?;
170 }
171 let mut seat = seat_of(state, &seat_key, &spec.id);
172 let stem = if i == 0 {
173 format!("rebase-fix-{round}")
174 } else {
175 format!("rebase-fix-{round}-{}", spec.id)
176 };
177 let out = agent::invoke(
178 &spec,
179 &mut seat,
180 &Invocation {
181 cwd: scratch,
182 prompt: &prompt_text,
183 timeout: Duration::from_secs(state.config.graph.timeout_fix),
184 allow_write: true,
185 unsandboxed: false,
186 sessions: state.config.graph.sessions,
187 artifacts: &artifacts,
188 stem: &stem,
189 run: &state.id,
190 node: "rebase",
191 cache_dir: state.config.cache_dir().as_deref(),
192 attachments: &[],
193 writable: &[],
194 },
195 )
196 .await;
197 let seat_name = seat.key.clone();
198 state.seats.insert(seat.key.clone(), seat);
199 if let Some(next) = ids.get(i + 1)
200 && agent::chain_advances(&out)
201 {
202 let (class, why) = crate::fixer::failure_of(&out);
203 crate::graph::record_handover(
204 state, "rebase", &seat_name, &spec.id, next, &class, &why,
205 );
206 continue;
207 }
208 last = Some((out, seat_name));
209 break;
210 }
211 let (out, seat_name) = last.expect("the fixer chain always has an entry");
212
213 let mut error = None;
214 let mut quota = false;
215 match out {
216 Ok(o) if o.quota_exhausted() => {
217 state.quota.push(QuotaLoss {
218 seat: seat_name,
219 node: "rebase".to_owned(),
220 at: Timestamp::now(),
221 reset: o.quota.as_ref().and_then(|q| q.reset.clone()),
222 });
223 error = Some("rate limited (quota); the fixer could not run".to_owned());
224 quota = true;
225 }
226 Ok(o) if !o.usable() => {
227 error = Some(format!(
228 "the fixer produced nothing usable (exit {:?}, timed out: {})",
229 o.exit_code, o.timed_out
230 ));
231 }
232 Ok(_) => {}
233 Err(e) => error = Some(format!("{e:#}")),
234 }
235
236 let finished = !git::rebase_in_progress(scratch).await;
237 if let Some(r) = state.rebase_fixes.last_mut() {
238 r.finished = finished;
239 r.error = error.clone();
240 }
241 state.save()?;
242
243 if quota {
244 let paths = git::unmerged_paths(scratch).await.unwrap_or_default();
246 let why = reason(
247 state.rebase_fixes.len(),
248 cap,
249 &paths,
250 &said,
251 "the fixer hit its rate limit",
252 );
253 abandon(&repo, scratch, branch, &orig).await;
254 return Ok(Rebased::Stopped(why));
255 }
256 }
257}
258
259async fn finish(
261 state: &mut RunState,
262 scratch: &Path,
263 branch: &str,
264 orig: &str,
265 onto_sha: &str,
266 touched: &[String],
267 said: &str,
268) -> Result<Rebased> {
269 let repo = state.repo.clone();
270 let spent = state.rebase_fixes.len();
271 let cap = state.config.graph.review_rounds;
272 let unmerged = git::unmerged_paths(scratch).await.unwrap_or_default();
273 let head = git::rev_parse(scratch, "HEAD").await.unwrap_or_default();
274 let mut candidates: Vec<String> = touched.to_vec();
279 if let Ok(changed) = git::git(scratch, &["diff", "--name-only", onto_sha, "HEAD"]).await {
280 for p in changed.lines().map(str::trim).filter(|l| !l.is_empty()) {
281 if !candidates.iter().any(|c| c == p) {
282 candidates.push(p.to_owned());
283 }
284 }
285 }
286 let marked: Vec<String> = candidates
287 .into_iter()
288 .filter(|p| has_markers(scratch, p))
289 .collect();
290
291 let emptied = head == onto_sha
296 && git::cherry(&repo, onto_sha, orig)
297 .await
298 .map_or(true, |(unmatched, _)| !unmatched.is_empty());
299
300 let dropped = if unmerged.is_empty() && marked.is_empty() && !emptied && !head.is_empty() {
305 dropped_commits(&repo, onto_sha, orig, &head).await
306 } else {
307 Vec::new()
308 };
309
310 let problem = if !unmerged.is_empty() {
311 Some(("paths are still unmerged", unmerged))
312 } else if !marked.is_empty() {
313 Some(("conflict markers were left in the tree", marked))
314 } else if emptied {
315 Some((
316 "the rebase ended with none of the branch's commits applied (all skipped)",
317 touched.to_vec(),
318 ))
319 } else if !dropped.is_empty() {
320 Some((
321 "the rebase dropped some of the branch's commits (skipped?)",
322 dropped,
323 ))
324 } else if head.is_empty() || !git::is_ancestor(&repo, onto_sha, &head).await {
325 Some((
326 "the rebase ended without the base in the result (abandoned or skipped)",
327 touched.to_vec(),
328 ))
329 } else {
330 None
331 };
332 match problem {
333 None => {
334 git::worktree_remove(&repo, scratch).await.ok();
335 state.event(
336 "rebase",
337 format!("{branch} rebased after {spent} fixer round(s)"),
338 );
339 state.save()?;
340 Ok(Rebased::Applied)
341 }
342 Some((what, paths)) => {
343 let why = reason(spent, cap, &paths, said, what);
344 abandon(&repo, scratch, branch, orig).await;
345 Ok(Rebased::Stopped(why))
346 }
347 }
348}
349
350async fn dropped_commits(repo: &Path, onto_sha: &str, orig: &str, head: &str) -> Vec<String> {
359 let Ok((unmatched, _)) = git::cherry(repo, onto_sha, orig).await else {
360 return Vec::new();
361 };
362 if unmatched.is_empty() {
363 return Vec::new();
364 }
365 let (Ok(origin), Ok(result)) = (
366 git::commit_keys(repo, &format!("{onto_sha}..{orig}")).await,
367 git::commit_keys(repo, &format!("{onto_sha}..{head}")).await,
368 ) else {
369 return Vec::new();
370 };
371 let expected: Vec<git::CommitKey> = origin
372 .into_iter()
373 .filter(|c| unmatched.contains(&c.sha))
374 .collect();
375 let have: Vec<String> = result.iter().map(|c| c.key.clone()).collect();
376 let mut taken = vec![false; result.len()];
377 let mut lost = Vec::new();
378 let mut unverified = Vec::new();
379 for c in missing_commits(&expected, &have) {
384 if !already_in_result(repo, &c.sha, orig, head).await {
389 unverified.push(c);
390 continue;
391 }
392 let mine = change_lines(repo, &c.sha).await;
393 for (i, r) in result.iter().enumerate() {
394 if !taken[i] && r.key == c.key && change_lines(repo, &r.sha).await == mine {
395 taken[i] = true;
396 break;
397 }
398 }
399 }
400 for c in unverified {
404 let mine = commit_paths(repo, &c.sha).await;
405 let mut found = false;
406 for (i, r) in result.iter().enumerate() {
407 if taken[i] || r.key != c.key {
408 continue;
409 }
410 let theirs = commit_paths(repo, &r.sha).await;
411 if theirs.iter().any(|p| mine.contains(p)) {
412 taken[i] = true;
413 found = true;
414 break;
415 }
416 }
417 if !found {
418 lost.push(c.key.rsplit('\u{1f}').next().unwrap_or(&c.key).to_owned());
419 }
420 }
421 lost
422}
423
424async fn change_lines(repo: &Path, sha: &str) -> Vec<String> {
428 git::git(
429 repo,
430 &["diff-tree", "-p", "-U0", "--no-commit-id", "--root", sha],
431 )
432 .await
433 .map(|o| {
434 o.lines()
435 .filter(|l| {
436 !(l.starts_with("diff ")
437 || l.starts_with("index ")
438 || l.starts_with("@@")
439 || l.starts_with("--- ")
440 || l.starts_with("+++ "))
441 })
442 .map(str::to_owned)
443 .collect()
444 })
445 .unwrap_or_default()
446}
447
448async fn commit_paths(repo: &Path, sha: &str) -> Vec<String> {
451 git::git(
452 repo,
453 &[
454 "diff-tree",
455 "--no-commit-id",
456 "--name-only",
457 "-r",
458 "--root",
459 "-z",
460 sha,
461 ],
462 )
463 .await
464 .map(|o| {
465 o.split('\0')
466 .filter(|l| !l.is_empty())
467 .map(str::to_owned)
468 .collect()
469 })
470 .unwrap_or_default()
471}
472
473async fn entry(repo: &Path, rev: &str, path: &str) -> Option<String> {
476 let out = git::git(repo, &["ls-tree", rev, "--", path]).await.ok()?;
477 out.split('\t')
478 .next()
479 .filter(|e| !e.is_empty())
480 .map(str::to_owned)
481}
482
483async fn already_in_result(repo: &Path, sha: &str, orig: &str, head: &str) -> bool {
492 if replay_is_noop(repo, sha, head).await {
493 return true;
494 }
495 for p in &commit_paths(repo, sha).await {
496 let got = entry(repo, head, p).await;
497 if got != entry(repo, sha, p).await && got != entry(repo, orig, p).await {
498 return false;
499 }
500 }
501 true
502}
503
504async fn replay_is_noop(repo: &Path, sha: &str, head: &str) -> bool {
507 let base = format!("{sha}^");
508 let Ok(out) = git::git_raw(
509 repo,
510 &[
511 "merge-tree",
512 "--write-tree",
513 &format!("--merge-base={base}"),
514 head,
515 sha,
516 ],
517 )
518 .await
519 else {
520 return false;
521 };
522 if !out.ok() {
523 return false;
524 }
525 let merged = out.stdout.lines().next().unwrap_or("").trim();
526 match git::tree_of(repo, head).await {
527 Ok(t) => !merged.is_empty() && merged == t,
528 Err(_) => false,
529 }
530}
531
532fn missing_commits(expected: &[git::CommitKey], have: &[String]) -> Vec<git::CommitKey> {
540 expected
541 .iter()
542 .filter(|c| {
543 let want = expected.iter().filter(|e| e.key == c.key).count();
544 let got = have.iter().filter(|k| **k == c.key).count();
545 got < want
546 })
547 .cloned()
548 .collect()
549}
550
551async fn abandon(repo: &Path, scratch: &Path, branch: &str, orig: &str) {
554 git::rebase_abort(repo, scratch).await;
555 let full = format!("refs/heads/{branch}");
556 if git::rev_parse(repo, &full).await.ok().as_deref() != Some(orig) {
557 git::git_raw(repo, &["update-ref", &full, orig]).await.ok();
558 }
559}
560
561fn reason(spent: usize, cap: usize, paths: &[String], said: &str, what: &str) -> String {
564 let shown: Vec<&str> = paths
565 .iter()
566 .take(PATHS_IN_REASON)
567 .map(String::as_str)
568 .collect();
569 let mut list = shown.join(", ");
570 if paths.len() > shown.len() {
571 list.push_str(&format!(" and {} more", paths.len() - shown.len()));
572 }
573 if list.is_empty() {
574 list.push_str("none recorded");
575 }
576 let mut s = format!(
577 "conflict not resolved after {spent} of {cap} fixer round(s) ({what}); remaining \
578 conflicted path(s): {list}"
579 );
580 let said = said.trim();
581 if !said.is_empty() {
582 s.push_str("; git said: ");
583 s.extend(said.chars().take(250));
584 }
585 s
586}
587
588async fn subjects(worktree: &Path, range: &str) -> Vec<String> {
590 let n = format!("-n{SUBJECTS}");
591 git::git(worktree, &["log", "--format=%s", &n, range])
592 .await
593 .map(|o| o.lines().map(str::to_owned).collect())
594 .unwrap_or_default()
595}
596
597fn has_markers(worktree: &Path, path: &str) -> bool {
598 std::fs::read_to_string(worktree.join(path)).is_ok_and(|t| {
599 t.lines().any(|l| l.starts_with("<<<<<<< ")) && t.lines().any(|l| l.starts_with(">>>>>>> "))
600 })
601}
602
603fn hunks(worktree: &Path, paths: &[String]) -> String {
606 let mut out = String::new();
607 for p in paths {
608 if out.len() >= HUNK_TOTAL {
609 out.push_str("\n(more conflicted files omitted)\n");
610 break;
611 }
612 out.push_str(&format!("=== {p} ===\n"));
613 let Ok(text) = std::fs::read_to_string(worktree.join(p)) else {
614 out.push_str("(not readable as text; use git to inspect it)\n");
615 continue;
616 };
617 let mut file = String::new();
618 let mut inside = false;
619 for line in text.lines() {
620 if line.starts_with("<<<<<<< ") {
621 inside = true;
622 }
623 if inside {
624 file.push_str(line);
625 file.push('\n');
626 }
627 if line.starts_with(">>>>>>> ") {
628 inside = false;
629 }
630 }
631 if file.len() > HUNK_PER_FILE {
632 file = file.chars().take(HUNK_PER_FILE).collect();
633 file.push_str("\n(truncated)\n");
634 }
635 out.push_str(&file);
636 }
637 out
638}
639
640#[cfg(test)]
641mod tests {
642 use super::*;
643 use crate::proc::Quiet as _;
644
645 fn ck(sha: &str, subject: &str) -> git::CommitKey {
646 git::CommitKey {
647 sha: sha.to_owned(),
648 key: format!("n\u{1f}e\u{1f}1 +0000\u{1f}{subject}"),
649 }
650 }
651
652 #[test]
653 fn nothing_is_missing_when_every_key_is_present() {
654 let exp = [ck("a", "one"), ck("b", "two")];
655 let have = vec![exp[1].key.clone(), exp[0].key.clone()];
656 assert!(missing_commits(&exp, &have).is_empty());
657 }
658
659 #[test]
660 fn a_dropped_commit_is_named_by_subject() {
661 let exp = [ck("a", "one"), ck("b", "two")];
662 let have = vec![exp[1].key.clone()];
663 assert_eq!(missing_commits(&exp, &have), vec![exp[0].clone()]);
664 }
665
666 #[test]
667 fn duplicate_keys_are_counted_not_collapsed() {
668 let exp = [ck("a", "same"), ck("b", "same")];
669 let have = vec![exp[0].key.clone()];
670 assert_eq!(missing_commits(&exp, &have), exp.to_vec());
671 }
672
673 #[test]
674 fn a_commit_without_a_key_match_is_a_candidate_even_if_a_twin_exists() {
675 let exp = [ck("a", "same"), ck("b", "same")];
676 let have = vec![exp[1].key.clone()];
677 assert_eq!(missing_commits(&exp, &have).len(), 2);
678 }
679
680 fn sh(dir: &Path, args: &[&str]) {
681 let o = std::process::Command::new("git")
682 .quiet()
683 .args(args)
684 .current_dir(dir)
685 .output()
686 .unwrap();
687 assert!(
688 o.status.success(),
689 "{args:?}: {}",
690 String::from_utf8_lossy(&o.stderr)
691 );
692 }
693
694 #[tokio::test]
695 async fn a_lost_mode_change_is_not_already_in_the_result() {
696 let t = tempfile::tempdir().unwrap();
697 let d = t.path();
698 sh(d, &["init", "-q", "-b", "main"]);
699 sh(d, &["config", "user.name", "t"]);
700 sh(d, &["config", "user.email", "t@example.com"]);
701 sh(d, &["config", "core.fileMode", "true"]);
702 std::fs::write(d.join("script.sh"), "echo\n").unwrap();
703 sh(d, &["add", "-A"]);
704 sh(d, &["commit", "-q", "-m", "base"]);
705 sh(d, &["update-index", "--chmod=+x", "script.sh"]);
706 sh(d, &["commit", "-q", "-m", "chmod"]);
707 let sha = git::git(d, &["rev-parse", "HEAD"]).await.unwrap();
708 let base = git::git(d, &["rev-parse", "HEAD~1"]).await.unwrap();
709 assert!(!already_in_result(d, &sha, &sha, &base).await);
711 assert!(already_in_result(d, &sha, &sha, &sha).await);
712 }
713
714 async fn commit(d: &Path, msg: &str) -> String {
715 sh(d, &["add", "-A"]);
716 sh(d, &["commit", "-q", "-m", msg]);
717 git::git(d, &["rev-parse", "HEAD"]).await.unwrap()
718 }
719
720 #[tokio::test]
721 async fn a_change_inside_a_larger_upstream_edit_is_in_the_result() {
722 let t = tempfile::tempdir().unwrap();
723 let d = t.path();
724 sh(d, &["init", "-q", "-b", "main"]);
725 sh(d, &["config", "user.name", "t"]);
726 sh(d, &["config", "user.email", "t@example.com"]);
727 let body = "old\n1\n2\n3\n4\n5\n6\n7\n8\n9\nend\n";
728 std::fs::write(d.join("f.txt"), body).unwrap();
729 commit(d, "base").await;
730 std::fs::write(d.join("f.txt"), body.replacen("old", "new", 1)).unwrap();
731 let c = commit(d, "c1").await;
732 sh(d, &["checkout", "-q", "-b", "up", "HEAD~1"]);
733 let up = body.replacen("old", "new", 1).replace("end", "end plus");
734 std::fs::write(d.join("f.txt"), up).unwrap();
735 let head = commit(d, "upstream").await;
736 assert!(already_in_result(d, &c, &c, &head).await);
737 }
738
739 #[tokio::test]
740 async fn a_dropped_commit_on_a_non_ascii_path_is_still_noticed() {
741 let t = tempfile::tempdir().unwrap();
742 let d = t.path();
743 sh(d, &["init", "-q", "-b", "main"]);
744 sh(d, &["config", "user.name", "t"]);
745 sh(d, &["config", "user.email", "t@example.com"]);
746 std::fs::write(d.join("a.txt"), "a\n").unwrap();
747 let base = commit(d, "base").await;
748 std::fs::write(d.join("日本語.txt"), "x\n").unwrap();
749 let c = commit(d, "c").await;
750 assert!(!already_in_result(d, &c, &c, &base).await);
751 }
752
753 async fn commit_dated(d: &Path, msg: &str) -> String {
754 sh(d, &["add", "-A"]);
755 let st = std::process::Command::new("git")
756 .quiet()
757 .current_dir(d)
758 .env("GIT_AUTHOR_DATE", "2020-01-01T00:00:00+0000")
759 .env("GIT_COMMITTER_DATE", "2020-01-01T00:00:00+0000")
760 .args(["commit", "-q", "-m", msg])
761 .status()
762 .unwrap();
763 assert!(st.success());
764 git::git(d, &["rev-parse", "HEAD"]).await.unwrap()
765 }
766
767 #[tokio::test]
768 async fn a_surviving_resolved_commit_sharing_a_key_with_an_absorbed_one_is_not_lost() {
769 let t = tempfile::tempdir().unwrap();
770 let d = t.path();
771 sh(d, &["init", "-q", "-b", "main"]);
772 sh(d, &["config", "user.name", "t"]);
773 sh(d, &["config", "user.email", "t@example.com"]);
774 std::fs::write(d.join("z.txt"), "z\n").unwrap();
775 let base = commit(d, "base").await;
776 std::fs::write(d.join("a.txt"), "a\n").unwrap();
777 commit_dated(d, "same").await;
778 std::fs::write(d.join("b.txt"), "b\n").unwrap();
779 let orig = commit_dated(d, "same").await;
780 sh(d, &["checkout", "-q", "-b", "up", &base]);
783 std::fs::write(d.join("a.txt"), "a\n").unwrap();
784 std::fs::write(d.join("y.txt"), "y\n").unwrap();
785 std::fs::write(d.join("b.txt"), "other\n").unwrap();
786 let onto = commit(d, "upstream").await;
787 std::fs::write(d.join("b.txt"), "other\nb\n").unwrap();
789 let head = commit_dated(d, "same").await;
790 assert!(dropped_commits(d, &onto, &orig, &head).await.is_empty());
791 }
792
793 #[tokio::test]
794 async fn a_skipped_commit_is_not_masked_by_a_surviving_one_in_the_same_file() {
795 let t = tempfile::tempdir().unwrap();
796 let d = t.path();
797 sh(d, &["init", "-q", "-b", "main"]);
798 sh(d, &["config", "user.name", "t"]);
799 sh(d, &["config", "user.email", "t@example.com"]);
800 let body = "first\n1\n2\n3\n4\n5\n6\n7\n8\n9\nlast\n";
801 std::fs::write(d.join("f.txt"), body).unwrap();
802 let base = commit(d, "base").await;
803 std::fs::write(d.join("f.txt"), body.replacen("first", "mine", 1)).unwrap();
804 commit_dated(d, "same").await;
805 let two = body
806 .replacen("first", "mine", 1)
807 .replacen("last", "tail", 1);
808 std::fs::write(d.join("f.txt"), &two).unwrap();
809 let orig = commit_dated(d, "same").await;
810 sh(d, &["checkout", "-q", "-b", "up", &base]);
811 std::fs::write(d.join("f.txt"), body.replacen("first", "theirs", 1)).unwrap();
812 let onto = commit(d, "upstream").await;
813 std::fs::write(
815 d.join("f.txt"),
816 body.replacen("first", "theirs", 1)
817 .replacen("last", "tail", 1),
818 )
819 .unwrap();
820 let head = commit_dated(d, "same").await;
821 assert_eq!(dropped_commits(d, &onto, &orig, &head).await, vec!["same"]);
822 }
823}