@@ -51,6 +51,11 @@ def resolve_worktree(
5151 if not create_branch :
5252 raise RuntimeError ("Branch does not exist" )
5353
54+ try :
55+ git .create_branch (repo_cfg , branch )
56+ except git .GitCommandFailed as exc :
57+ raise RuntimeError (f"Failed to create branch '{ branch } ': { exc } " ) from exc
58+
5459 create_worktree = typer .confirm (
5560 f"Worktree for branch '{ branch } ' does not exist. Create it?" ,
5661 default = True ,
@@ -70,18 +75,26 @@ def resolve_worktree(
7075# go
7176# ===========================================================================
7277
73- @app .command ()
74- def debug (repo : str ) -> None :
75- repo_cfg : RepoConfig | None = _config .resolve_workspace (repo )
76- pprint (git .iter_worktrees (repo_cfg ), expand_all = True , console = console )
77-
7878@app .command ()
7979def go (repo : str , branch : Optional [str ] = None ) -> None :
8080 repo_cfg : RepoConfig | None = _config .resolve_workspace (repo )
8181
8282 if repo_cfg is None :
83- console .print (f"[yellow]Repository '{ repo } ' does not exist.[/]" )
84- raise typer .Exit (code = 1 )
83+ clone_repo = typer .confirm (
84+ f"Repository '{ repo } ' does not exist. Clone it?" ,
85+ default = True ,
86+ )
87+ if not clone_repo :
88+ raise typer .Exit (code = 1 )
89+
90+ try :
91+ repo_cfg = git .clone_and_add_worktree (repo )
92+ except Exception as exc : # GitCommandFailed, GitxError, etc.
93+ console .print (f"[red]{ exc } [/]" )
94+ raise typer .Exit (code = 1 )
95+
96+ _config .workspaces .update ({repo : repo_cfg })
97+ _config .save ()
8598
8699 try :
87100 path = resolve_worktree (repo_cfg , branch )
@@ -94,16 +107,29 @@ def go(repo: str, branch: Optional[str] = None) -> None:
94107
95108
96109# ===========================================================================
97- # jump
110+ # code
98111# ===========================================================================
99112
100113@app .command ()
101- def jump (repo : str , branch : Optional [str ] = None ) -> None :
114+ def code (repo : str , branch : Optional [str ] = None ) -> None :
102115 repo_cfg : RepoConfig | None = _config .resolve_workspace (repo )
103116
104117 if repo_cfg is None :
105- console .print (f"[yellow]Repository '{ repo } ' does not exist.[/]" )
106- raise typer .Exit (code = 1 )
118+ clone_repo = typer .confirm (
119+ f"Repository '{ repo } ' does not exist. Clone it?" ,
120+ default = True ,
121+ )
122+ if not clone_repo :
123+ raise typer .Exit (code = 1 )
124+
125+ try :
126+ repo_cfg = git .clone_and_add_worktree (repo )
127+ except Exception as exc : # GitCommandFailed, GitxError, etc.
128+ console .print (f"[red]{ exc } [/]" )
129+ raise typer .Exit (code = 1 )
130+
131+ _config .workspaces .update ({repo : repo_cfg })
132+ _config .save ()
107133
108134 try :
109135 path = resolve_worktree (repo_cfg , branch )
@@ -138,10 +164,11 @@ def clone(repo: str) -> None:
138164 )
139165 raise typer .Exit (code = 1 )
140166
141- repo_cfg = git .clone_and_add_worktree (repo )
142-
143- if isinstance (repo_cfg , int ):
144- raise typer .Exit (code = repo_cfg )
167+ try :
168+ repo_cfg = git .clone_and_add_worktree (repo )
169+ except Exception as exc : # GitCommandFailed, GitxError, etc.
170+ console .print (f"[red]{ exc } [/]" )
171+ raise typer .Exit (code = 1 )
145172
146173 _config .workspaces .update ({repo : repo_cfg })
147174 _config .save ()
@@ -198,10 +225,26 @@ def branch_add(repo: str, branch: str) -> None:
198225 repo_cfg : RepoConfig | None = _config .resolve_workspace (repo )
199226
200227 if repo_cfg is None :
201- console .print (f"[yellow]Repository '{ repo } ' does not exist.[/]" )
202- raise typer .Exit (code = 1 )
228+ clone_repo = typer .confirm (
229+ f"Repository '{ repo } ' does not exist. Clone it?" ,
230+ default = True ,
231+ )
232+ if not clone_repo :
233+ raise typer .Exit (code = 1 )
234+
235+ if git .branch_exists (repo_cfg .repo_root_path (), branch ):
236+ console .print (f"[red]Branch '{ branch } ' already exists locally.[/]" )
237+ raise typer .Exit (code = 0 )
238+
239+ try :
240+ repo_cfg = git .clone_and_add_worktree (repo )
241+ except Exception as exc : # GitCommandFailed, GitxError, etc.
242+ console .print (f"[red]{ exc } [/]" )
243+ raise typer .Exit (code = 1 )
244+
245+ _config .workspaces .update ({repo : repo_cfg })
246+ _config .save ()
203247
204- git .add_worktree (repo_cfg , branch )
205248 raise typer .Exit (code = 0 )
206249
207250
@@ -217,8 +260,21 @@ def branch_delete(repo: str, branch: str) -> None:
217260 console .print (f"[yellow]Repository '{ repo } ' does not exist.[/]" )
218261 raise typer .Exit (code = 1 )
219262
220- code = git .delete_branch (repo_cfg , branch )
221- raise typer .Exit (code = code )
263+ delete_remote = typer .confirm (
264+ f"Also delete remote branch 'origin/{ branch } '?" ,
265+ default = False ,
266+ )
267+
268+ try :
269+ git .delete_branch (repo_cfg , branch , delete_remote = delete_remote )
270+ except git .BranchDoesNotExist as exc :
271+ console .print (f"[red]{ exc } [/]" )
272+ raise typer .Exit (code = 1 )
273+ except git .GitCommandFailed as exc :
274+ console .print (f"[red]{ exc } [/]" )
275+ raise typer .Exit (code = 1 )
276+
277+ raise typer .Exit (code = 0 )
222278
223279
224280# ===========================================================================
0 commit comments