Skip to content

Commit b9549bc

Browse files
committed
Fix remaining Python parity gaps with Go
Safety: - sync.py: dirty-tree guard before rebase - retarget.py: dirty-tree guard before rebase - undo.py redo: dirty-tree guard with confirmation before git reset --hard Correctness: - undo.py: reflog loop uses continue instead of break (matches Go fix) Cleanup: - Deleted dead src/gx/ui/shelf_app.py (Textual TUI, no longer used)
1 parent 6634b45 commit b9549bc

4 files changed

Lines changed: 21 additions & 225 deletions

File tree

src/gx/commands/retarget.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
branch_exists,
2323
ensure_git_repo,
2424
get_current_branch,
25+
is_clean_working_tree,
2526
run_git,
2627
)
2728
from 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)

src/gx/commands/sync.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
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?"):

src/gx/commands/undo.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@
1919
print_info,
2020
print_success,
2121
print_table,
22+
print_warning,
2223
)
2324
from 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:

src/gx/ui/shelf_app.py

Lines changed: 0 additions & 224 deletions
This file was deleted.

0 commit comments

Comments
 (0)