@@ -249,6 +249,16 @@ fn move_to_commit(
249249 " {} Reposition to the desired location (use the new commit ID from step 1)" ,
250250 "↳" . cyan( )
251251 ) ?;
252+ } else if let Some ( out) = out. for_json ( ) {
253+ out. write_value ( serde_json:: json!( {
254+ "ok" : false ,
255+ "error" : "cross_stack_position" ,
256+ "hint" : format!(
257+ "Move to branch first with 'but move {} {}', then reposition" ,
258+ & source_oid. to_string( ) [ ..7 ] ,
259+ target_stack_head_branch
260+ ) ,
261+ } ) ) ?;
252262 }
253263
254264 bail ! ( "Cannot move commit to specific position in another stack" ) ;
@@ -311,14 +321,16 @@ fn move_to_branch(
311321 let cmd = format ! ( "but move {} <target-commit> [--after]" , & source_str[ ..7 ] ) ;
312322 writeln ! ( out, " {}" , cmd. green( ) ) ?;
313323 }
324+ } else if let Some ( out) = out. for_json ( ) {
325+ out. write_value ( serde_json:: json!( { "ok" : true } ) ) ?;
314326 }
315327 } else {
316328 // Different stack - use move_commit API
317329 if let Some ( illegal_move) =
318330 gitbutler_branch_actions:: move_commit ( ctx, target_stack_id, source_oid. to_git2 ( ) , source_stack_id) ?
319331 {
320332 if let Some ( out) = out. for_human ( ) {
321- match illegal_move {
333+ match & illegal_move {
322334 gitbutler_branch_actions:: MoveCommitIllegalAction :: DependsOnCommits ( deps) => {
323335 writeln ! (
324336 out,
@@ -343,6 +355,24 @@ fn move_to_branch(
343355 ) ?;
344356 }
345357 }
358+ } else if let Some ( out) = out. for_json ( ) {
359+ let ( reason, deps) = match & illegal_move {
360+ gitbutler_branch_actions:: MoveCommitIllegalAction :: DependsOnCommits ( deps) => {
361+ ( "depends_on_commits" , Some ( deps. clone ( ) ) )
362+ }
363+ gitbutler_branch_actions:: MoveCommitIllegalAction :: HasDependentChanges ( deps) => {
364+ ( "has_dependent_changes" , Some ( deps. clone ( ) ) )
365+ }
366+ gitbutler_branch_actions:: MoveCommitIllegalAction :: HasDependentUncommittedChanges => {
367+ ( "has_dependent_uncommitted_changes" , None )
368+ }
369+ } ;
370+ out. write_value ( serde_json:: json!( {
371+ "ok" : false ,
372+ "error" : "illegal_move" ,
373+ "reason" : reason,
374+ "dependencies" : deps,
375+ } ) ) ?;
346376 }
347377 bail ! ( "Illegal move" ) ;
348378 }
@@ -371,6 +401,8 @@ fn move_to_branch(
371401 let cmd = format ! ( "but move {} <target-commit> [--after]" , & source_str[ ..7 ] ) ;
372402 writeln ! ( out, " {}" , cmd. green( ) ) ?;
373403 }
404+ } else if let Some ( out) = out. for_json ( ) {
405+ out. write_value ( serde_json:: json!( { "ok" : true } ) ) ?;
374406 }
375407 }
376408
@@ -415,6 +447,8 @@ fn move_within_stack(
415447 if git2_source_oid == git2_target_oid {
416448 if let Some ( out) = out. for_human ( ) {
417449 writeln ! ( out, "Source and target are the same commit. Nothing to do." ) ?;
450+ } else if let Some ( out) = out. for_json ( ) {
451+ out. write_value ( serde_json:: json!( { "ok" : true } ) ) ?;
418452 }
419453 return Ok ( ( ) ) ;
420454 }
@@ -457,6 +491,8 @@ fn move_within_stack(
457491 position_desc,
458492 target_oid. to_string( ) [ ..7 ] . blue( )
459493 ) ?;
494+ } else if let Some ( out) = out. for_json ( ) {
495+ out. write_value ( serde_json:: json!( { "ok" : true } ) ) ?;
460496 }
461497
462498 Ok ( ( ) )
0 commit comments