@@ -126,11 +126,19 @@ const trunkSha = (runner: CommandRunner, root: string): string => {
126126 : "unknown" ;
127127} ;
128128
129- /** How a conflict row resolved: hook re-apply, an accepted net-zero delete, regeneration, or a manual resolution. */
130- export const ConflictVia = Schema . Literals ( [ "hook" , "manual" , "net-zero-delete" , "regenerate" ] ) ;
129+ /** How a conflict row resolved: hook re-apply, an accepted net-zero delete, a carried retirement, regeneration, or a manual resolution. */
130+ export const ConflictVia = Schema . Literals ( [
131+ "hook" ,
132+ "manual" ,
133+ "net-zero-delete" ,
134+ "retired" ,
135+ "regenerate" ,
136+ ] ) ;
131137
132138/** The recorded reason when an upstream deletion meets a net-zero fork edit. */
133139export const NET_ZERO_REASON = "upstream deleted; fork edit is net-zero" ;
140+ /** The recorded reason when an upstream deletion meets a path a resolver retired. */
141+ export const RETIRED_REASON = "upstream deleted; retired by sync/resolution" ;
134142
135143export const ConflictRow = Schema . Struct ( {
136144 /** Repo-relative path of the conflicted file. */
@@ -147,7 +155,7 @@ export const ConflictRow = Schema.Struct({
147155 hooksReapplied : Schema . Array ( Schema . String ) ,
148156 /** Why hook re-apply refused the path; set on `manual` rows that carried hooks. */
149157 refuseReason : Schema . optionalKey ( Schema . String ) ,
150- /** Why an automatic rule resolved the path; set on `net-zero-delete` and `regenerate` rows. */
158+ /** Why an automatic rule resolved the path; set on `net-zero-delete`, `retired`, and `regenerate` rows. */
151159 reason : Schema . optionalKey ( Schema . String ) ,
152160} ) ;
153161export interface ConflictRow extends Schema . Schema . Type < typeof ConflictRow > { }
@@ -358,6 +366,8 @@ const WorktreeState = Schema.Struct({
358366 rebased : Schema . optionalKey ( Schema . String ) ,
359367 /** The rerere ids to export: every stop's, plus every imported one, since a replay records none. */
360368 rerere : Schema . optionalKey ( Schema . Array ( Schema . String ) ) ,
369+ /** The paths a resolver retired, plus every imported one: rerere records no delete/modify stop. */
370+ retired : Schema . optionalKey ( Schema . Array ( Schema . String ) ) ,
361371 /** The `sync/resolution` commit this worktree imported; a moved branch refuses adoption. */
362372 resolution : Schema . optionalKey ( Schema . String ) ,
363373} ) ;
@@ -929,8 +939,12 @@ export const refuseDroppedLinks = (
929939 * block again and resolved ones continue; a finished HEAD is taken as the
930940 * rebased tip as long as it contains the target.
931941 *
932- * `conflicts` collects this run's rows and `rerere` each stop's rerere ids as
933- * they happen; `rebaseOnto` owns both.
942+ * A delete/modify a resolver settled by keeping upstream's deletion leaves
943+ * the path out of the index, where rerere never looks: each stop records such
944+ * paths in `retired`, and a later replay accepts the same deletion again.
945+ *
946+ * `conflicts` collects this run's rows, `rerere` each stop's rerere ids, and
947+ * `retired` each stop's retired paths as they happen; `rebaseOnto` owns all three.
934948 */
935949const replayOnto = (
936950 runner : CommandRunner ,
@@ -940,6 +954,7 @@ const replayOnto = (
940954 adopted : boolean ,
941955 conflicts : ConflictRow [ ] ,
942956 rerere : string [ ] ,
957+ retired : string [ ] ,
943958) : RebaseOutcome => {
944959 const worktree = worktreePath ( root ) ;
945960 // The fork stack above `target` sits on this upstream commit — for a normal
@@ -1003,6 +1018,26 @@ const replayOnto = (
10031018 `git rebase failed without a stop: ${ status . stderr . trim ( ) || status . stdout . trim ( ) || "no output" } ` ,
10041019 ) ;
10051020 rerere . push ( ...stopRerereIds ( runner , worktree ) ) ;
1021+ const modified = lines (
1022+ git ( runner , worktree , [
1023+ "diff-tree" ,
1024+ "--no-commit-id" ,
1025+ "--name-only" ,
1026+ "-r" ,
1027+ "--diff-filter=MT" ,
1028+ "REBASE_HEAD" ,
1029+ ] ) ,
1030+ ) ;
1031+ if ( modified . length > 0 ) {
1032+ const tracked = new Set ( lines ( git ( runner , worktree , [ "ls-files" , "--" , ...modified ] ) ) ) ;
1033+ retired . push (
1034+ ...modified . filter (
1035+ ( path ) =>
1036+ ! tracked . has ( path ) &&
1037+ gitResult ( runner , root , [ "cat-file" , "-e" , `${ target . sha } :${ path } ` ] ) . status !== 0 ,
1038+ ) ,
1039+ ) ;
1040+ }
10061041 const forkCommit = git ( runner , worktree , [ "rev-parse" , "REBASE_HEAD" ] ) ;
10071042 const forkSubject = git ( runner , worktree , [ "log" , "-1" , "--format=%s" , "REBASE_HEAD" ] ) ;
10081043 const unmerged = lines ( git ( runner , worktree , [ "diff" , "--name-only" , "--diff-filter=U" ] ) ) ;
@@ -1018,24 +1053,27 @@ const replayOnto = (
10181053 }
10191054 // Delete/modify with the deletion on the upstream (rebase base) side:
10201055 // when the fork trunk's final blob for the path equals the base blob,
1021- // the fork edit is net-zero and the deletion is accepted outright. Any
1022- // other delete/modify shape falls through to hook re-apply, which
1023- // refuses it, and then to a manual row.
1024- if (
1056+ // the fork edit is net-zero and the deletion is accepted outright, as
1057+ // it is for a path a resolver already retired. Any other delete/modify
1058+ // shape falls through to hook re-apply, which refuses it, and then to
1059+ // a manual row.
1060+ const upstreamDeleted =
10251061 stageContent ( runner , worktree , 2 , path ) === null &&
1026- stageContent ( runner , worktree , 3 , path ) !== null &&
1027- gitResult ( runner , root , [ "diff" , "--quiet" , baseSha , oldSha , "--" , path ] ) . status === 0
1028- ) {
1062+ stageContent ( runner , worktree , 3 , path ) !== null ;
1063+ const netZero =
1064+ upstreamDeleted &&
1065+ gitResult ( runner , root , [ "diff" , "--quiet" , baseSha , oldSha , "--" , path ] ) . status === 0 ;
1066+ if ( netZero || ( upstreamDeleted && retired . includes ( path ) ) ) {
10291067 git ( runner , worktree , [ "rm" , "--quiet" , "--" , path ] ) ;
10301068 conflicts . push ( {
10311069 path,
10321070 forkCommit,
10331071 forkSubject,
10341072 upstreamCommit : touch . sha ,
10351073 upstreamSubject : touch . subject ,
1036- via : "net-zero-delete" ,
1074+ via : netZero ? "net-zero-delete" : "retired ",
10371075 hooksReapplied : [ ] ,
1038- reason : NET_ZERO_REASON ,
1076+ reason : netZero ? NET_ZERO_REASON : RETIRED_REASON ,
10391077 } ) ;
10401078 continue ;
10411079 }
@@ -1119,7 +1157,8 @@ export type SyncRebase = RebaseOutcome & {
11191157 * A new worktree runs the repo's setup step before the rebase starts, so a
11201158 * stop has dependencies. Each stop's rows persist beside the worktree as they
11211159 * are recorded, so the run that finishes the rebase still reports them.
1122- * `imported` (from `sync/resolution`) joins the exported rerere ids, and its
1160+ * `imported` (from `sync/resolution`) joins the exported rerere ids and
1161+ * retired paths, and its
11231162 * fixups apply above a rebase this run finishes; every outcome exports the
11241163 * resolution data for the next run.
11251164 */
@@ -1159,14 +1198,16 @@ export const rebaseOnto = (
11591198 const carried = state . conflicts ?? [ ] ;
11601199 const conflicts : ConflictRow [ ] = [ ] ;
11611200 const rerere : string [ ] = [ ...( imported ?. rerere ?? [ ] ) ] ;
1201+ const retired : string [ ] = [ ...( state . retired ?? [ ] ) , ...( imported ?. retired ?? [ ] ) ] ;
11621202 let outcome : RebaseOutcome ;
11631203 try {
1164- outcome = replayOnto ( runner , root , target , oldSha , adopted , conflicts , rerere ) ;
1204+ outcome = replayOnto ( runner , root , target , oldSha , adopted , conflicts , rerere , retired ) ;
11651205 } finally {
11661206 state = {
11671207 ...state ,
11681208 conflicts : mergeStops ( carried , conflicts ) ,
11691209 rerere : [ ...new Set ( [ ...( state . rerere ?? [ ] ) , ...rerere ] ) ] ,
1210+ retired : [ ...new Set ( retired ) ] ,
11701211 } ;
11711212 writeWorktreeState ( root , state ) ;
11721213 }
0 commit comments