@@ -541,9 +541,9 @@ function satisfiesMinimumCrabboxVersion(version: string, minimum: number[]) {
541541 return ! parsed . suffix || isPostReleaseDescribeSuffix ( parsed . suffix ) ;
542542}
543543
544- function gitOutput ( commandArgs : string [ ] ) {
544+ function gitOutput ( commandArgs : string [ ] , extraEnv : ProcessEnv = { } ) {
545545 const gitBinary = resolvePathBinary ( "git" , process . env , process . platform ) ?? "git" ;
546- const gitEnv = { ...process . env , GIT_CONFIG_GLOBAL : "/dev/null" } ;
546+ const gitEnv = { ...process . env , ... extraEnv , GIT_CONFIG_GLOBAL : "/dev/null" } ;
547547 const invocation = spawnInvocation ( gitBinary , commandArgs , gitEnv , process . platform ) ;
548548 const result = spawnSync ( invocation . command , invocation . args , {
549549 cwd : repoRoot ,
@@ -3410,21 +3410,19 @@ function isWorktreeClean() {
34103410 return status . status === 0 && status . stdout === "" ;
34113411}
34123412
3413- function shouldUseFullCheckoutForCleanRemoteSync ( commandArgs : string [ ] , _providerName : string ) {
3413+ function shouldUseFullCheckoutForRemoteSync ( commandArgs : string [ ] , _providerName : string ) {
34143414 if ( commandArgs [ 0 ] !== "run" ) {
34153415 return false ;
34163416 }
34173417 if ( hasOption ( commandArgs , "--no-sync" ) ) {
34183418 return false ;
34193419 }
3420- if ( ! isWorktreeClean ( ) ) {
3421- return false ;
3422- }
34233420
3424- return (
3425- isSparseCheckout ( ) ||
3426- isChangedGateCommand ( parseRunInvocation ( help . text , commandArgs ) . commandArgs )
3427- ) ;
3421+ const changedGate = isChangedGateCommand ( parseRunInvocation ( help . text , commandArgs ) . commandArgs ) ;
3422+ if ( changedGate && ! isWindowsRemoteTarget ( commandArgs ) ) {
3423+ return true ;
3424+ }
3425+ return isWorktreeClean ( ) && ( isSparseCheckout ( ) || changedGate ) ;
34283426}
34293427
34303428function defaultFullCheckoutSyncRoot ( ) {
@@ -3498,9 +3496,27 @@ function assertFullCheckoutSyncDisk(root: string) {
34983496 ) ;
34993497}
35003498
3499+ function currentWorktreeTree ( syncRoot : string ) {
3500+ const indexDir = mkdtempSync ( resolve ( syncRoot , "openclaw-crabbox-index-" ) ) ;
3501+ const indexPath = resolve ( indexDir , "index" ) ;
3502+ const indexEnv = { GIT_INDEX_FILE : indexPath } ;
3503+ try {
3504+ const read = gitOutput ( [ "read-tree" , "HEAD" ] , indexEnv ) ;
3505+ const add = gitOutput ( [ "add" , "-A" , "--" , "." ] , indexEnv ) ;
3506+ const tree = gitOutput ( [ "write-tree" ] , indexEnv ) ;
3507+ if ( read . status !== 0 || add . status !== 0 || tree . status !== 0 || ! tree . stdout ) {
3508+ throw new Error ( read . text || add . text || tree . text || "git write-tree failed" ) ;
3509+ }
3510+ return tree . stdout ;
3511+ } finally {
3512+ rmSync ( indexDir , { recursive : true , force : true } ) ;
3513+ }
3514+ }
3515+
35013516function prepareFullCheckoutForSync ( options : { changedGateBase ?: string } = { } ) {
35023517 const syncRoot = fullCheckoutSyncRoot ( ) ;
35033518 assertFullCheckoutSyncDisk ( syncRoot ) ;
3519+ const changedGateTree = options . changedGateBase ? currentWorktreeTree ( syncRoot ) : "" ;
35043520 const dir = mkdtempSync ( resolve ( syncRoot , "openclaw-crabbox-sync-" ) ) ;
35053521 let active = false ;
35063522 let resolvedChangedGateBase = options . changedGateBase ?? "" ;
@@ -3526,19 +3542,15 @@ function prepareFullCheckoutForSync(options: { changedGateBase?: string } = {})
35263542 try {
35273543 bundleTempDir = mkdtempSync ( resolve ( syncRoot , "openclaw-crabbox-bundle-" ) ) ;
35283544 const bundleTempPath = resolve ( bundleTempDir , "changed-gate.bundle" ) ;
3529- const head = gitOutput ( [ "-C" , dir , "rev-parse" , "HEAD" ] ) ;
35303545 const base = gitOutput ( [ "-C" , dir , "rev-parse" , options . changedGateBase ] ) ;
3531- if ( head . status !== 0 || base . status !== 0 || ! head . stdout || ! base . stdout ) {
3532- throw new Error ( `git rev-parse failed: ${ head . text || base . text } ` ) ;
3546+ const baseTree = gitOutput ( [ "-C" , dir , "rev-parse" , `${ options . changedGateBase } ^{tree}` ] ) ;
3547+ if ( base . status !== 0 || baseTree . status !== 0 || ! base . stdout || ! baseTree . stdout ) {
3548+ throw new Error ( `git rev-parse failed: ${ base . text || baseTree . text } ` ) ;
35333549 }
35343550 resolvedChangedGateBase = base . stdout ;
3535- if ( head . stdout === base . stdout ) {
3551+ if ( changedGateTree === baseTree . stdout ) {
35363552 writeFileSync ( bundleTempPath , "" , "utf8" ) ;
35373553 } else {
3538- const headTree = gitOutput ( [ "-C" , dir , "rev-parse" , "HEAD^{tree}" ] ) ;
3539- if ( headTree . status !== 0 || ! headTree . stdout ) {
3540- throw new Error ( headTree . text || "git rev-parse HEAD tree failed" ) ;
3541- }
35423554 // A parentless carrier makes the bundle self-contained while sending
35433555 // only the final tree. The remote attaches the fetched base as parent.
35443556 const transportCommit = gitOutput ( [
@@ -3549,7 +3561,7 @@ function prepareFullCheckoutForSync(options: { changedGateBase?: string } = {})
35493561 "-c" ,
3550356235513563 "commit-tree" ,
3552- headTree . stdout ,
3564+ changedGateTree ,
35533565 "-m" ,
35543566 "remote-changed-gate-tree" ,
35553567 ] ) ;
@@ -3938,7 +3950,7 @@ normalizedArgs = scriptBootstrap.args;
39383950const scriptStdinPrepared = scriptBootstrap . prepared ;
39393951let wsl2ScriptBootstrap = { args : normalizedArgs , cleanup : ( ) => { } , prepared : false } ;
39403952try {
3941- if ( shouldUseFullCheckoutForCleanRemoteSync ( normalizedArgs , provider ) ) {
3953+ if ( shouldUseFullCheckoutForRemoteSync ( normalizedArgs , provider ) ) {
39423954 const invocation = parseRunInvocation ( help . text , normalizedArgs ) ;
39433955 const facts = analyzeRemoteCommand ( invocation ) ;
39443956 const changedGate = facts . changedGate ? changedGateBaseForCommand ( facts . commandArgs ) : null ;
@@ -3953,11 +3965,11 @@ try {
39533965 remoteChangedGateBase = checkout . changedGateBase ;
39543966 remoteChangedGateAlias = changedGate ?. remoteAlias ?? "" ;
39553967 console . error (
3956- `[crabbox] sparse clean checkout detected ; syncing from temporary full checkout ${ checkout . dir } ` ,
3968+ `[crabbox] isolated checkout sync ; syncing from temporary full checkout ${ checkout . dir } ` ,
39573969 ) ;
39583970 if ( checkout . changedGateBase ) {
39593971 console . error (
3960- `[crabbox] remote changed gate detected; overlaying local HEAD as worktree changes from ${ checkout . changedGateBase } ` ,
3972+ `[crabbox] remote changed gate detected; overlaying the local worktree as changes from ${ checkout . changedGateBase } ` ,
39613973 ) ;
39623974 }
39633975 }
@@ -4124,7 +4136,7 @@ if (childStderr) {
41244136 } ) ;
41254137}
41264138const childKillGraceMs = resolveChildKillGraceMs ( process . env ) ;
4127- let childForceKillTimer : NodeJS . Timeout | undefined ;
4139+ let childForceKillTimer : ReturnType < typeof setTimeout > | undefined ;
41284140let childTreeShutdownStarted = false ;
41294141if ( fullCheckout ) {
41304142 try {
0 commit comments