@@ -60,7 +60,12 @@ fn main() -> Result<()> {
6060 let cli = Cli :: parse ( ) ;
6161 match cli. command {
6262 Commands :: List => cmd_list ( ) ,
63- Commands :: Create { name, path, branch, from } => cmd_create ( & name, path, branch, from) ,
63+ Commands :: Create {
64+ name,
65+ path,
66+ branch,
67+ from,
68+ } => cmd_create ( & name, path, branch, from) ,
6469 Commands :: Delete { target, force } => cmd_delete ( & target, force) ,
6570 Commands :: Path { target } => cmd_path ( & target) ,
6671 }
@@ -73,7 +78,12 @@ fn cmd_list() -> Result<()> {
7378 Ok ( ( ) )
7479}
7580
76- fn cmd_create ( name : & str , path : Option < PathBuf > , branch : Option < String > , from : Option < String > ) -> Result < ( ) > {
81+ fn cmd_create (
82+ name : & str ,
83+ path : Option < PathBuf > ,
84+ branch : Option < String > ,
85+ from : Option < String > ,
86+ ) -> Result < ( ) > {
7787 let root = git_root ( ) ?;
7888 let cwd = std:: env:: current_dir ( ) . context ( "read current directory" ) ?;
7989 let repo_name = root
@@ -87,17 +97,17 @@ fn cmd_create(name: &str, path: Option<PathBuf>, branch: Option<String>, from: O
8797 Some ( p) => resolve_path ( & cwd, p) ,
8898 None => default_worktree_path ( & repo_name, & branch) ?,
8999 } ;
90- if is_default_path {
91- if let Some ( parent) = target_path. parent ( ) {
92- std:: fs:: create_dir_all ( parent) . with_context ( || {
93- format ! ( "create worktree base directory '{}'" , parent. display( ) )
94- } ) ?;
95- }
100+ if is_default_path && let Some ( parent) = target_path. parent ( ) {
101+ std:: fs:: create_dir_all ( parent)
102+ . with_context ( || format ! ( "create worktree base directory '{}'" , parent. display( ) ) ) ?;
96103 }
97104
98105 let branch_exists = git_branch_exists ( & root, & branch) ?;
99106 if branch_exists && from. is_some ( ) {
100- bail ! ( "branch '{}' already exists; --from is only for new branches" , branch) ;
107+ bail ! (
108+ "branch '{}' already exists; --from is only for new branches" ,
109+ branch
110+ ) ;
101111 }
102112
103113 let mut args: Vec < String > = vec ! [ "worktree" . into( ) , "add" . into( ) ] ;
@@ -232,11 +242,23 @@ fn print_worktrees(worktrees: &[Worktree]) {
232242 let name_width = rows. iter ( ) . map ( |r| r. 0 . len ( ) ) . max ( ) . unwrap_or ( 4 ) . max ( 4 ) ;
233243 let branch_width = rows. iter ( ) . map ( |r| r. 1 . len ( ) ) . max ( ) . unwrap_or ( 6 ) . max ( 6 ) ;
234244
235- println ! ( "{:name_width$} {:branch_width$} {} {}" , "NAME" , "BRANCH" , "PATH" , "FLAGS" ,
236- name_width = name_width, branch_width = branch_width) ;
245+ println ! (
246+ "{:name_width$} {:branch_width$} PATH FLAGS" ,
247+ "NAME" ,
248+ "BRANCH" ,
249+ name_width = name_width,
250+ branch_width = branch_width
251+ ) ;
237252 for ( name, branch, path, flags) in rows {
238- println ! ( "{:name_width$} {:branch_width$} {} {}" , name, branch, path, flags,
239- name_width = name_width, branch_width = branch_width) ;
253+ println ! (
254+ "{:name_width$} {:branch_width$} {} {}" ,
255+ name,
256+ branch,
257+ path,
258+ flags,
259+ name_width = name_width,
260+ branch_width = branch_width
261+ ) ;
240262 }
241263}
242264
@@ -252,7 +274,9 @@ fn worktree_name(wt: &Worktree) -> String {
252274}
253275
254276fn worktree_branch_short ( wt : & Worktree ) -> Option < & str > {
255- wt. branch . as_deref ( ) . map ( |b| b. strip_prefix ( "refs/heads/" ) . unwrap_or ( b) )
277+ wt. branch
278+ . as_deref ( )
279+ . map ( |b| b. strip_prefix ( "refs/heads/" ) . unwrap_or ( b) )
256280}
257281
258282fn worktree_flags ( wt : & Worktree ) -> String {
@@ -286,7 +310,10 @@ fn resolve_worktree<'a>(target: &str, worktrees: &'a [Worktree]) -> Result<&'a W
286310 bail ! ( "no worktree matches '{}'" , target) ;
287311 }
288312 if matches. len ( ) > 1 {
289- let names: Vec < String > = matches. iter ( ) . map ( |w| w. path . display ( ) . to_string ( ) ) . collect ( ) ;
313+ let names: Vec < String > = matches
314+ . iter ( )
315+ . map ( |w| w. path . display ( ) . to_string ( ) )
316+ . collect ( ) ;
290317 bail ! ( "'{}' is ambiguous: {}" , target, names. join( ", " ) ) ;
291318 }
292319 Ok ( matches[ 0 ] )
@@ -454,8 +481,14 @@ prunable stale
454481 let _ = std:: fs:: create_dir_all ( & wt2_path) ;
455482
456483 let worktrees = vec ! [
457- wt( wt1_path. to_string_lossy( ) . as_ref( ) , Some ( "refs/heads/alpha" ) ) ,
458- wt( wt2_path. to_string_lossy( ) . as_ref( ) , Some ( "refs/heads/alpha" ) ) ,
484+ wt(
485+ wt1_path. to_string_lossy( ) . as_ref( ) ,
486+ Some ( "refs/heads/alpha" ) ,
487+ ) ,
488+ wt(
489+ wt2_path. to_string_lossy( ) . as_ref( ) ,
490+ Some ( "refs/heads/alpha" ) ,
491+ ) ,
459492 ] ;
460493
461494 let by_path = resolve_worktree ( wt1_path. to_string_lossy ( ) . as_ref ( ) , & worktrees) . unwrap ( ) ;
0 commit comments