@@ -12,8 +12,9 @@ use opencode_cloud_core::config::load_config;
1212use opencode_cloud_core:: docker:: update:: tag_current_as_previous;
1313use opencode_cloud_core:: docker:: {
1414 CONTAINER_NAME , DockerClient , IMAGE_TAG_DEFAULT , ImageState , ProgressReporter , build_image,
15- container_exists, container_is_running, exec_command, get_cli_version, has_previous_image,
16- pull_image, rollback_image, save_state, setup_and_start, stop_service,
15+ container_exists, container_is_running, exec_command, exec_command_with_status,
16+ get_cli_version, has_previous_image, pull_image, rollback_image, save_state, setup_and_start,
17+ stop_service,
1718} ;
1819
1920/// Arguments for the update command
@@ -394,10 +395,8 @@ pub(crate) async fn cmd_update_opencode(
394395 style( current_version. unwrap_or_else( || "unknown" . to_string( ) ) ) . dim( ) ,
395396 style( current_commit. unwrap_or_else( || "unknown" . to_string( ) ) ) . dim( )
396397 ) ;
397- eprintln ! (
398- "Next hash: {}" ,
399- style( next_commit. unwrap_or_else( || "unknown" . to_string( ) ) ) . dim( )
400- ) ;
398+ let next_hash = next_commit. as_deref ( ) . unwrap_or ( "unknown" ) ;
399+ eprintln ! ( "Next hash: {}" , style( next_hash) . dim( ) ) ;
401400 eprintln ! ( ) ;
402401 }
403402
@@ -422,9 +421,22 @@ pub(crate) async fn cmd_update_opencode(
422421pkill -f "/opt/opencode/bin/opencode" || true
423422pkill -f "opencode-broker" || true
424423"# ;
425- exec_command ( & client, CONTAINER_NAME , vec ! [ "bash" , "-lc" , stop_cmd] )
426- . await
427- . map_err ( |e| anyhow ! ( "Failed to stop opencode processes: {e}" ) ) ?;
424+ let ( stop_output, stop_status) =
425+ exec_command_with_status ( & client, CONTAINER_NAME , vec ! [ "bash" , "-lc" , stop_cmd] )
426+ . await
427+ . map_err ( |e| anyhow ! ( "Failed to stop opencode processes: {e}" ) ) ?;
428+ if !quiet && !stop_output. trim ( ) . is_empty ( ) {
429+ eprintln ! (
430+ "{} Stop output:\n {}" ,
431+ style( "[info]" ) . cyan( ) ,
432+ stop_output. trim( )
433+ ) ;
434+ }
435+ if stop_status != 0 {
436+ return Err ( anyhow ! (
437+ "Failed to stop opencode processes (exit {stop_status}).\n {stop_output}"
438+ ) ) ;
439+ }
428440
429441 let update_script = format ! (
430442 r#"set -euo pipefail
@@ -455,9 +467,32 @@ rm -rf "$REPO"
455467"#
456468 ) ;
457469
458- exec_command ( & client, CONTAINER_NAME , vec ! [ "bash" , "-lc" , & update_script] )
459- . await
460- . map_err ( |e| anyhow ! ( "Failed to update opencode: {e}" ) ) ?;
470+ let ( update_output, update_status) =
471+ exec_command_with_status ( & client, CONTAINER_NAME , vec ! [ "bash" , "-lc" , & update_script] )
472+ . await
473+ . map_err ( |e| anyhow ! ( "Failed to update opencode: {e}" ) ) ?;
474+ if !quiet && !update_output. trim ( ) . is_empty ( ) {
475+ eprintln ! (
476+ "{} Update output:\n {}" ,
477+ style( "[info]" ) . cyan( ) ,
478+ update_output. trim( )
479+ ) ;
480+ }
481+ if update_status != 0 {
482+ return Err ( anyhow ! (
483+ "Opencode update failed (exit {update_status}).\n {update_output}"
484+ ) ) ;
485+ }
486+
487+ if let Some ( expected) = next_commit. as_deref ( ) {
488+ let updated_commit = get_current_opencode_commit ( & client) . await ;
489+ if updated_commit. as_deref ( ) != Some ( expected) {
490+ let found = updated_commit. unwrap_or_else ( || "unknown" . to_string ( ) ) ;
491+ return Err ( anyhow ! (
492+ "Opencode update did not apply (expected {expected}, found {found}).\n {update_output}"
493+ ) ) ;
494+ }
495+ }
461496
462497 spinner. success ( "Opencode updated, restarting service..." ) ;
463498
0 commit comments