@@ -57,6 +57,7 @@ import {
5757 resolveGlobalManager ,
5858 resolveNodeRunner ,
5959 resolveTargetVersion ,
60+ resolveUpdateGitRepo ,
6061 resolveUpdateRoot ,
6162 runUpdateStep ,
6263 tryWriteCompletionCache ,
@@ -323,6 +324,8 @@ async function runPackageInstallUpdate(params: {
323324async function runGitUpdate ( params : {
324325 root : string ;
325326 switchToGit : boolean ;
327+ gitRepoUrl : string ;
328+ enforceGitRepo : boolean ;
326329 installKind : "git" | "package" | "unknown" ;
327330 timeoutMs : number | undefined ;
328331 startedAt : number ;
@@ -336,21 +339,24 @@ async function runGitUpdate(params: {
336339 const updateRoot = params . switchToGit ? resolveGitInstallDir ( ) : params . root ;
337340 const effectiveTimeout = params . timeoutMs ?? 20 * 60_000 ;
338341
339- const cloneStep = params . switchToGit
340- ? await ensureGitCheckout ( {
341- dir : updateRoot ,
342- timeoutMs : effectiveTimeout ,
343- progress : params . progress ,
344- } )
345- : null ;
346-
347- if ( cloneStep && cloneStep . exitCode !== 0 ) {
342+ const checkoutStep =
343+ params . switchToGit || params . enforceGitRepo
344+ ? await ensureGitCheckout ( {
345+ dir : updateRoot ,
346+ timeoutMs : effectiveTimeout ,
347+ progress : params . progress ,
348+ repoUrl : params . gitRepoUrl ,
349+ enforceRepo : params . enforceGitRepo ,
350+ } )
351+ : null ;
352+
353+ if ( checkoutStep && checkoutStep . exitCode !== 0 ) {
348354 const result : UpdateRunResult = {
349355 status : "error" ,
350356 mode : "git" ,
351357 root : updateRoot ,
352- reason : cloneStep . name ,
353- steps : [ cloneStep ] ,
358+ reason : checkoutStep . name ,
359+ steps : [ checkoutStep ] ,
354360 durationMs : Date . now ( ) - params . startedAt ,
355361 } ;
356362 params . stop ( ) ;
@@ -367,7 +373,7 @@ async function runGitUpdate(params: {
367373 channel : params . channel ,
368374 tag : params . tag ,
369375 } ) ;
370- const steps = [ ...( cloneStep ? [ cloneStep ] : [ ] ) , ...updateResult . steps ] ;
376+ const steps = [ ...( checkoutStep ? [ checkoutStep ] : [ ] ) , ...updateResult . steps ] ;
371377
372378 if ( params . switchToGit && updateResult . status === "ok" ) {
373379 const manager = await resolveGlobalManager ( {
@@ -661,10 +667,18 @@ export async function updateCommand(opts: UpdateCommandOptions): Promise<void> {
661667 return ;
662668 }
663669
670+ const gitRepo = resolveUpdateGitRepo (
671+ configSnapshot . valid ? configSnapshot . config . update ?. gitRepo : undefined ,
672+ ) ;
673+ const preferGitRepo = gitRepo . source !== "default" ;
674+
664675 const installKind = updateStatus . installKind ;
665- const switchToGit = requestedChannel === "dev " && installKind !== "git" ;
676+ const switchToGit = installKind !== "git " && ( requestedChannel === "dev" || preferGitRepo ) ;
666677 const switchToPackage =
667- requestedChannel !== null && requestedChannel !== "dev" && installKind === "git" ;
678+ requestedChannel !== null &&
679+ requestedChannel !== "dev" &&
680+ installKind === "git" &&
681+ ! preferGitRepo ;
668682 const updateInstallKind = switchToGit ? "git" : switchToPackage ? "package" : installKind ;
669683 const defaultChannel =
670684 updateInstallKind === "git" ? DEFAULT_GIT_CHANNEL : DEFAULT_PACKAGE_CHANNEL ;
@@ -711,11 +725,16 @@ export async function updateCommand(opts: UpdateCommandOptions): Promise<void> {
711725 actions . push ( `Persist update.channel=${ requestedChannel } in config` ) ;
712726 }
713727 if ( switchToGit ) {
714- actions . push ( "Switch install mode from package to git checkout (dev channel)" ) ;
728+ actions . push (
729+ `Switch install mode from package to git checkout (channel ${ channel } , repo ${ gitRepo . url } )` ,
730+ ) ;
715731 } else if ( switchToPackage ) {
716732 actions . push ( `Switch install mode from git to package manager (${ mode } )` ) ;
717733 } else if ( updateInstallKind === "git" ) {
718734 actions . push ( `Run git update flow on channel ${ channel } (fetch/rebase/build/doctor)` ) ;
735+ if ( gitRepo . source !== "default" ) {
736+ actions . push ( `Ensure git origin matches configured repo (${ gitRepo . url } )` ) ;
737+ }
719738 } else {
720739 actions . push ( `Run global package manager update with spec openclaw@${ tag } ` ) ;
721740 }
@@ -842,6 +861,8 @@ export async function updateCommand(opts: UpdateCommandOptions): Promise<void> {
842861 : await runGitUpdate ( {
843862 root,
844863 switchToGit,
864+ gitRepoUrl : gitRepo . url ,
865+ enforceGitRepo : gitRepo . source !== "default" ,
845866 installKind,
846867 timeoutMs,
847868 startedAt,
0 commit comments