@@ -5257,6 +5257,128 @@ test("checkpoint plumbing commits raw modified, added, and deleted worktree cont
52575257 assert . equal ( result . tree , git ( cwd , "rev-parse" , "HEAD^{tree}" ) ) ;
52585258} ) ;
52595259
5260+ test ( "checkpoint plumbing preserves a review fix restoring a legacy CRLF blob" , ( ) => {
5261+ const cwd = gitPackageFixture ( { check : 'node -e ""' } ) ;
5262+ const wrapper = "apps/android/gradlew.bat" ;
5263+ const wrapperPath = path . join ( cwd , wrapper ) ;
5264+ fs . mkdirSync ( path . dirname ( wrapperPath ) , { recursive : true } ) ;
5265+ fs . writeFileSync ( path . join ( cwd , ".gitattributes" ) , "*.bat text=auto eol=lf\n" ) ;
5266+ fs . writeFileSync ( wrapperPath , "@echo off\r\nexit /b 0\r\n" ) ;
5267+ git ( cwd , "add" , "." ) ;
5268+ const legacyBlob = git ( cwd , "hash-object" , "-w" , "--no-filters" , wrapper ) ;
5269+ git ( cwd , "update-index" , "--cacheinfo" , `100644,${ legacyBlob } ,${ wrapper } ` ) ;
5270+ git ( cwd , "commit" , "-m" , "legacy CRLF base" ) ;
5271+ const base = git ( cwd , "rev-parse" , "HEAD" ) ;
5272+ const identity = {
5273+ name : "clawsweeper" ,
5274+ email : "274271284+clawsweeper[bot]@users.noreply.github.com" ,
5275+ } ;
5276+
5277+ fs . writeFileSync ( path . join ( cwd , "repair.txt" ) , "validated repair\n" ) ;
5278+ const initial = createTargetCheckpointWithPlumbing ( {
5279+ cwd,
5280+ messages : [ "initial validated repair" ] ,
5281+ identity,
5282+ } ) ;
5283+ assert . equal ( initial . status , "committed" ) ;
5284+ assert . equal ( git ( cwd , "rev-parse" , `HEAD:${ wrapper } ` ) , legacyBlob ) ;
5285+ git ( cwd , "add" , "--renormalize" , "--" , wrapper ) ;
5286+ git ( cwd , "commit" , "-m" , "simulate previously normalized wrapper" ) ;
5287+ assert . notEqual ( git ( cwd , "rev-parse" , `HEAD:${ wrapper } ` ) , legacyBlob ) ;
5288+
5289+ git ( cwd , "restore" , `--source=${ base } ` , "--staged" , "--worktree" , "--" , wrapper ) ;
5290+ assert . equal ( git ( cwd , "status" , "--porcelain" ) , `M ${ wrapper } ` ) ;
5291+
5292+ const corrected = createTargetCheckpointWithPlumbing ( {
5293+ cwd,
5294+ messages : [ "restore unrelated legacy wrapper" ] ,
5295+ identity,
5296+ } ) ;
5297+
5298+ assert . equal ( corrected . status , "committed" ) ;
5299+ assert . equal ( git ( cwd , "rev-parse" , `HEAD:${ wrapper } ` ) , legacyBlob ) ;
5300+ assert . equal ( git ( cwd , "show" , "HEAD:repair.txt" ) , "validated repair" ) ;
5301+ assert . equal ( git ( cwd , "status" , "--porcelain" ) , "" ) ;
5302+
5303+ const accepted = captureTargetCheckoutBinding ( cwd ) ;
5304+ assert . equal ( captureFinalTargetCheckoutBinding ( cwd , accepted , corrected . commit ) . status , "" ) ;
5305+ const compacted = compactTargetHistoryWithPlumbing ( {
5306+ cwd,
5307+ baseRef : base ,
5308+ messages : [ "compact validated repair" ] ,
5309+ identity,
5310+ } ) ;
5311+ assert . equal ( git ( cwd , "rev-parse" , `HEAD:${ wrapper } ` ) , legacyBlob ) ;
5312+ assert . equal ( captureFinalTargetCheckoutBinding ( cwd , accepted , compacted . commit ) . status , "" ) ;
5313+ } ) ;
5314+
5315+ test ( "checkpoint plumbing preserves staged CRLF restorations alongside review edits" , ( ) => {
5316+ const cwd = gitPackageFixture ( { check : 'node -e ""' } ) ;
5317+ const wrapper = "apps/android/gradlew.bat" ;
5318+ const wrapperPath = path . join ( cwd , wrapper ) ;
5319+ fs . mkdirSync ( path . dirname ( wrapperPath ) , { recursive : true } ) ;
5320+ fs . writeFileSync ( path . join ( cwd , ".gitattributes" ) , "*.bat text=auto eol=lf\n" ) ;
5321+ fs . writeFileSync ( wrapperPath , "@echo off\r\nexit /b 0\r\n" ) ;
5322+ git ( cwd , "add" , "." ) ;
5323+ const legacyBlob = git ( cwd , "hash-object" , "-w" , "--no-filters" , wrapper ) ;
5324+ git ( cwd , "update-index" , "--cacheinfo" , `100644,${ legacyBlob } ,${ wrapper } ` ) ;
5325+ git ( cwd , "commit" , "-m" , "legacy CRLF base" ) ;
5326+ const base = git ( cwd , "rev-parse" , "HEAD" ) ;
5327+ const identity = {
5328+ name : "clawsweeper" ,
5329+ email : "274271284+clawsweeper[bot]@users.noreply.github.com" ,
5330+ } ;
5331+ fs . writeFileSync ( path . join ( cwd , "repair.txt" ) , "initial repair\n" ) ;
5332+ createTargetCheckpointWithPlumbing ( { cwd, messages : [ "initial repair" ] , identity } ) ;
5333+ git ( cwd , "add" , "--renormalize" , "--" , wrapper ) ;
5334+ git ( cwd , "commit" , "-m" , "simulate previously normalized wrapper" ) ;
5335+
5336+ git ( cwd , "restore" , `--source=${ base } ` , "--staged" , "--worktree" , "--" , wrapper ) ;
5337+ fs . writeFileSync ( path . join ( cwd , "repair.txt" ) , "review-corrected repair\n" ) ;
5338+
5339+ const corrected = createTargetCheckpointWithPlumbing ( {
5340+ cwd,
5341+ messages : [ "review repair and restore unrelated wrapper" ] ,
5342+ identity,
5343+ } ) ;
5344+
5345+ assert . equal ( corrected . status , "committed" ) ;
5346+ assert . equal ( git ( cwd , "rev-parse" , `HEAD:${ wrapper } ` ) , legacyBlob ) ;
5347+ assert . equal ( git ( cwd , "show" , "HEAD:repair.txt" ) , "review-corrected repair" ) ;
5348+ assert . equal ( git ( cwd , "status" , "--porcelain" ) , "" ) ;
5349+ } ) ;
5350+
5351+ test ( "checkpoint plumbing rejects a staged blob that disagrees with unchanged worktree" , ( ) => {
5352+ const sources = process . platform === "win32" ? [ "source.txt" ] : [ "source.txt" , ":(exclude)*" ] ;
5353+ for ( const source of sources ) {
5354+ const cwd = gitPackageFixture ( { check : 'node -e ""' } ) ;
5355+ fs . writeFileSync ( path . join ( cwd , source ) , "validated content\n" ) ;
5356+ git ( cwd , "add" , "." ) ;
5357+ git ( cwd , "commit" , "-m" , "validated base" ) ;
5358+ const previousHead = git ( cwd , "rev-parse" , "HEAD" ) ;
5359+ const poisonedBlob = execFileSync ( "git" , [ "hash-object" , "-w" , "--stdin" ] , {
5360+ cwd,
5361+ input : "poisoned staged content\n" ,
5362+ encoding : "utf8" ,
5363+ } ) . trim ( ) ;
5364+ git ( cwd , "update-index" , "--cacheinfo" , `100644,${ poisonedBlob } ,${ source } ` ) ;
5365+
5366+ assert . throws (
5367+ ( ) =>
5368+ createTargetCheckpointWithPlumbing ( {
5369+ cwd,
5370+ messages : [ "reject poisoned index" ] ,
5371+ identity : {
5372+ name : "clawsweeper" ,
5373+ email : "274271284+clawsweeper[bot]@users.noreply.github.com" ,
5374+ } ,
5375+ } ) ,
5376+ / t a r g e t i n d e x d i f f e r s f r o m u n c h a n g e d w o r k t r e e c o n t e n t / ,
5377+ ) ;
5378+ assert . equal ( git ( cwd , "rev-parse" , "HEAD" ) , previousHead ) ;
5379+ }
5380+ } ) ;
5381+
52605382test ( "checkpoint plumbing supports replacing a tracked file with a directory" , ( ) => {
52615383 const cwd = gitPackageFixture ( { check : 'node -e ""' } ) ;
52625384 fs . writeFileSync ( path . join ( cwd , "shape" ) , "file\n" ) ;
0 commit comments