-
Notifications
You must be signed in to change notification settings - Fork 0
Implement wt sync command for worktrees #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -385,3 +385,109 @@ def get_default_branch(path: Optional[Path] = None) -> str: | |||||||||
|
|
||||||||||
| # Last resort: return main | ||||||||||
| return "main" | ||||||||||
|
|
||||||||||
|
|
||||||||||
| def stash_changes(path: Optional[Path] = None, include_untracked: bool = True) -> bool: | ||||||||||
| """ | ||||||||||
| Stash uncommitted changes. | ||||||||||
|
|
||||||||||
| Args: | ||||||||||
| path: Repository path | ||||||||||
| include_untracked: Include untracked files in stash | ||||||||||
|
|
||||||||||
| Returns: | ||||||||||
| True if changes were stashed, False if nothing to stash | ||||||||||
| """ | ||||||||||
| args = ["stash", "push"] | ||||||||||
| if include_untracked: | ||||||||||
| args.append("--include-untracked") | ||||||||||
| args.extend(["-m", "wt sync auto-stash"]) | ||||||||||
|
|
||||||||||
| result = run_git(args, cwd=path, check=False) | ||||||||||
| # Git stash returns 0 even if nothing to stash, so check output | ||||||||||
| return result.returncode == 0 and "No local changes to save" not in result.stdout | ||||||||||
|
|
||||||||||
|
|
||||||||||
| def stash_pop(path: Optional[Path] = None) -> bool: | ||||||||||
| """ | ||||||||||
| Pop the most recent stash. | ||||||||||
|
|
||||||||||
| Args: | ||||||||||
| path: Repository path | ||||||||||
|
|
||||||||||
| Returns: | ||||||||||
| True if successful, False if conflicts or no stash | ||||||||||
| """ | ||||||||||
| result = run_git(["stash", "pop"], cwd=path, check=False) | ||||||||||
| return result.returncode == 0 | ||||||||||
|
|
||||||||||
|
|
||||||||||
| def pull_branch(branch: str, path: Optional[Path] = None, remote: str = "origin") -> Tuple[bool, str]: | ||||||||||
| """ | ||||||||||
| Pull changes from remote branch. | ||||||||||
|
|
||||||||||
| Args: | ||||||||||
| branch: Branch name | ||||||||||
| path: Repository path | ||||||||||
| remote: Remote name | ||||||||||
|
|
||||||||||
| Returns: | ||||||||||
| Tuple of (success, message) | ||||||||||
| """ | ||||||||||
| result = run_git(["pull", remote, branch], cwd=path, check=False) | ||||||||||
|
|
||||||||||
| if result.returncode == 0: | ||||||||||
| # Check if it was a fast-forward or already up to date | ||||||||||
| if "Already up to date" in result.stdout: | ||||||||||
| return True, "already_up_to_date" | ||||||||||
| elif "Fast-forward" in result.stdout: | ||||||||||
| return True, "fast_forward" | ||||||||||
| else: | ||||||||||
| return True, "merged" | ||||||||||
| else: | ||||||||||
| # Check for conflict | ||||||||||
| if "CONFLICT" in result.stdout or "CONFLICT" in result.stderr: | ||||||||||
|
||||||||||
| if "CONFLICT" in result.stdout or "CONFLICT" in result.stderr: | |
| if "CONFLICT" in result.stdout or "CONFLICT" in result.stderr: | |
| # Abort the merge to leave repo in clean state | |
| run_git(["merge", "--abort"], cwd=path, check=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The stash conflict message has inconsistent indentation. Line 554 adds a newline followed by 9 spaces of indentation, but line 552 only has 2 spaces. This will result in misaligned output. The indentation should match or the formatting should be adjusted for better readability.