File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2222 branch_exists ,
2323 ensure_git_repo ,
2424 get_current_branch ,
25+ is_clean_working_tree ,
2526 run_git ,
2627)
2728from gx .utils .stack import get_parent , get_parent_head , record_relationship
@@ -102,6 +103,10 @@ def retarget(
102103 ])
103104 return
104105
106+ if not is_clean_working_tree ():
107+ print_warning ("You have uncommitted changes. Stash or commit them before retargeting." )
108+ raise typer .Exit (1 )
109+
105110 if not confirm_action (f"Retarget { branch } onto { new_target } ?" ):
106111 print_info ("Cancelled." )
107112 raise typer .Exit (0 )
Original file line number Diff line number Diff line change 2121 GitError ,
2222 ensure_git_repo ,
2323 get_current_branch ,
24+ is_clean_working_tree ,
2425 run_git ,
2526 supports_update_refs ,
2627)
@@ -230,6 +231,11 @@ def sync(
230231 print_dry_run (actions )
231232 return
232233
234+ # Check for uncommitted changes
235+ if not is_clean_working_tree ():
236+ print_warning ("You have uncommitted changes. Stash or commit them before syncing." )
237+ raise typer .Exit (1 )
238+
233239 # Confirm for long chains
234240 if len (sync_branches ) >= SYNC_CONFIRM_THRESHOLD :
235241 if not confirm_action (f"Sync { len (sync_branches )} branches?" ):
Original file line number Diff line number Diff line change 1919 print_info ,
2020 print_success ,
2121 print_table ,
22+ print_warning ,
2223)
2324from gx .utils .git import (
2425 GitError ,
2526 ensure_git_repo ,
2627 get_last_commit ,
2728 get_reflog_entries ,
2829 get_repo_root ,
30+ is_clean_working_tree ,
2931 run_git ,
3032 time_ago ,
3133)
@@ -161,7 +163,7 @@ def _detect_state() -> dict | None:
161163 "action_msg" : "Soft reset to previous commit. Your changes will be preserved in staging." ,
162164 }
163165
164- break # Only inspect the most recent meaningful action
166+ continue # Skip non-matching entries and check subsequent ones
165167
166168 return None
167169
@@ -294,6 +296,13 @@ def redo() -> None:
294296 print_info ("Cancelled." )
295297 raise typer .Exit (0 )
296298
299+ # Check for uncommitted changes before hard reset
300+ if not is_clean_working_tree ():
301+ print_warning ("You have uncommitted changes that would be lost by redo." )
302+ if not confirm_action ("Proceed anyway?" ):
303+ print_info ("Cancelled." )
304+ raise typer .Exit (0 )
305+
297306 # Redo by resetting to pre-state
298307 pre_ref = last_undo .get ("pre_state_ref" , "" )
299308 if not pre_ref :
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments