Skip to content

Commit 526e569

Browse files
author
Test User
committed
fix: resolve worktree display name vs git name inconsistency
1 parent e3b8e31 commit 526e569

27 files changed

Lines changed: 2900 additions & 20 deletions

src/commands/delete.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ pub fn delete_worktree_with_ui(manager: &GitWorktreeManager, ui: &dyn UserInterf
240240

241241
// Create deletion configuration
242242
let config = WorktreeDeleteConfig {
243-
name: analysis.worktree.name.clone(),
243+
name: analysis.worktree.git_name.clone(), // Use git_name for internal operations
244244
path: analysis.worktree.path.clone(),
245245
branch: analysis.worktree.branch.clone(),
246246
delete_branch,
@@ -304,6 +304,7 @@ mod tests {
304304
let worktrees = vec![
305305
WorktreeInfo {
306306
name: "main".to_string(),
307+
git_name: "main".to_string(),
307308
path: PathBuf::from("/tmp/main"),
308309
branch: "main".to_string(),
309310
is_current: true,
@@ -314,6 +315,7 @@ mod tests {
314315
},
315316
WorktreeInfo {
316317
name: "feature".to_string(),
318+
git_name: "feature".to_string(),
317319
path: PathBuf::from("/tmp/feature"),
318320
branch: "feature".to_string(),
319321
is_current: false,
@@ -339,6 +341,7 @@ mod tests {
339341
fn test_deletion_analysis_creation() {
340342
let worktree = WorktreeInfo {
341343
name: "feature".to_string(),
344+
git_name: "feature".to_string(),
342345
path: PathBuf::from("/tmp/feature"),
343346
branch: "feature".to_string(),
344347
is_current: false,

src/commands/list.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ pub fn list_worktrees_with_ui(manager: &GitWorktreeManager, _ui: &dyn UserInterf
127127
// Display repository info
128128
let repo_info = get_repository_info();
129129
println!("Repository: {}", repo_info.bright_cyan());
130-
println!();
131130

132131
// Calculate column widths
133132
let max_name_len = sorted_worktrees
@@ -207,6 +206,7 @@ mod tests {
207206
fn test_format_worktree_display_basic() {
208207
let worktree = WorktreeInfo {
209208
name: "feature".to_string(),
209+
git_name: "feature".to_string(),
210210
path: PathBuf::from("/tmp/feature"),
211211
branch: "feature".to_string(),
212212
is_current: false,
@@ -224,6 +224,7 @@ mod tests {
224224
fn test_format_worktree_display_current() {
225225
let worktree = WorktreeInfo {
226226
name: "main".to_string(),
227+
git_name: "main".to_string(),
227228
path: PathBuf::from("/tmp/main"),
228229
branch: "main".to_string(),
229230
is_current: true,
@@ -241,6 +242,7 @@ mod tests {
241242
fn test_format_worktree_display_locked_changes() {
242243
let worktree = WorktreeInfo {
243244
name: "locked".to_string(),
245+
git_name: "locked".to_string(),
244246
path: PathBuf::from("/tmp/locked"),
245247
branch: "locked".to_string(),
246248
is_current: false,
@@ -258,6 +260,7 @@ mod tests {
258260
fn test_format_worktree_display_verbose() {
259261
let worktree = WorktreeInfo {
260262
name: "feature".to_string(),
263+
git_name: "feature".to_string(),
261264
path: PathBuf::from("/tmp/feature"),
262265
branch: "feature".to_string(),
263266
is_current: false,
@@ -275,6 +278,7 @@ mod tests {
275278
fn test_should_show_worktree_with_filter_match() {
276279
let worktree = WorktreeInfo {
277280
name: "feature-auth".to_string(),
281+
git_name: "feature-auth".to_string(),
278282
path: PathBuf::from("/tmp/feature"),
279283
branch: "feature".to_string(),
280284
is_current: false,
@@ -291,6 +295,7 @@ mod tests {
291295
fn test_should_show_worktree_with_filter_no_match() {
292296
let worktree = WorktreeInfo {
293297
name: "feature-ui".to_string(),
298+
git_name: "feature-ui".to_string(),
294299
path: PathBuf::from("/tmp/feature"),
295300
branch: "feature".to_string(),
296301
is_current: false,
@@ -307,6 +312,7 @@ mod tests {
307312
fn test_should_show_worktree_show_all() {
308313
let worktree = WorktreeInfo {
309314
name: "clean".to_string(),
315+
git_name: "clean".to_string(),
310316
path: PathBuf::from("/tmp/clean"),
311317
branch: "clean".to_string(),
312318
is_current: false,
@@ -323,6 +329,7 @@ mod tests {
323329
fn test_should_show_worktree_only_changes() {
324330
let clean_worktree = WorktreeInfo {
325331
name: "clean".to_string(),
332+
git_name: "clean".to_string(),
326333
path: PathBuf::from("/tmp/clean"),
327334
branch: "clean".to_string(),
328335
is_current: false,
@@ -334,6 +341,7 @@ mod tests {
334341

335342
let dirty_worktree = WorktreeInfo {
336343
name: "dirty".to_string(),
344+
git_name: "dirty".to_string(),
337345
path: PathBuf::from("/tmp/dirty"),
338346
branch: "dirty".to_string(),
339347
is_current: false,
@@ -354,6 +362,7 @@ mod tests {
354362
let test_path = "/tmp/feature";
355363
let worktree = WorktreeInfo {
356364
name: "feature".to_string(),
365+
git_name: "feature".to_string(),
357366
path: PathBuf::from(test_path),
358367
branch: "feature".to_string(),
359368
is_current: false,
@@ -379,6 +388,7 @@ mod tests {
379388
let behind_count = 3;
380389
let worktree = WorktreeInfo {
381390
name: "feature".to_string(),
391+
git_name: "feature".to_string(),
382392
path: PathBuf::from("/tmp/feature"),
383393
branch: "feature".to_string(),
384394
is_current: false,
@@ -397,6 +407,7 @@ mod tests {
397407
let worktree_name = "complex";
398408
let worktree = WorktreeInfo {
399409
name: worktree_name.to_string(),
410+
git_name: worktree_name.to_string(),
400411
path: PathBuf::from("/tmp/complex"),
401412
branch: "complex".to_string(),
402413
is_current: true,
@@ -417,6 +428,7 @@ mod tests {
417428
fn test_should_show_worktree_empty_filter() {
418429
let worktree = WorktreeInfo {
419430
name: "any".to_string(),
431+
git_name: "any".to_string(),
420432
path: PathBuf::from("/tmp/any"),
421433
branch: "any".to_string(),
422434
is_current: false,
@@ -436,6 +448,7 @@ mod tests {
436448
let no_match_filter = "ui";
437449
let worktree = WorktreeInfo {
438450
name: "feature-auth-login".to_string(),
451+
git_name: "feature-auth-login".to_string(),
439452
path: PathBuf::from("/tmp/feature"),
440453
branch: "feature".to_string(),
441454
is_current: false,
@@ -462,6 +475,7 @@ mod tests {
462475
// Create test worktrees with one being current
463476
let worktree1 = WorktreeInfo {
464477
name: "zebra".to_string(),
478+
git_name: "zebra".to_string(),
465479
path: PathBuf::from("/tmp/zebra"),
466480
branch: "zebra".to_string(),
467481
is_current: false,
@@ -472,6 +486,7 @@ mod tests {
472486
};
473487
let worktree2 = WorktreeInfo {
474488
name: "alpha".to_string(),
489+
git_name: "alpha".to_string(),
475490
path: PathBuf::from("/tmp/alpha"),
476491
branch: "alpha".to_string(),
477492
is_current: true,
@@ -482,6 +497,7 @@ mod tests {
482497
};
483498
let worktree3 = WorktreeInfo {
484499
name: "beta".to_string(),
500+
git_name: "beta".to_string(),
485501
path: PathBuf::from("/tmp/beta"),
486502
branch: "beta".to_string(),
487503
is_current: false,
@@ -517,6 +533,7 @@ mod tests {
517533
let worktrees = vec![
518534
WorktreeInfo {
519535
name: "short".to_string(),
536+
git_name: "short".to_string(),
520537
path: PathBuf::from("/tmp/short"),
521538
branch: "main".to_string(),
522539
is_current: false,
@@ -527,6 +544,7 @@ mod tests {
527544
},
528545
WorktreeInfo {
529546
name: "very-long-worktree-name".to_string(),
547+
git_name: "very-long-worktree-name".to_string(),
530548
path: PathBuf::from("/tmp/very-long-worktree-name"),
531549
branch: "feature-with-very-long-branch-name".to_string(),
532550
is_current: true,
@@ -562,6 +580,7 @@ mod tests {
562580
fn test_table_display_icon_selection() {
563581
let current_worktree = WorktreeInfo {
564582
name: "current".to_string(),
583+
git_name: "current".to_string(),
565584
path: PathBuf::from("/tmp/current"),
566585
branch: "main".to_string(),
567586
is_current: true,
@@ -572,6 +591,7 @@ mod tests {
572591
};
573592
let other_worktree = WorktreeInfo {
574593
name: "other".to_string(),
594+
git_name: "other".to_string(),
575595
path: PathBuf::from("/tmp/other"),
576596
branch: "feature".to_string(),
577597
is_current: false,
@@ -601,6 +621,7 @@ mod tests {
601621
fn test_table_display_branch_formatting() {
602622
let current_worktree = WorktreeInfo {
603623
name: "current".to_string(),
624+
git_name: "current".to_string(),
604625
path: PathBuf::from("/tmp/current"),
605626
branch: "main".to_string(),
606627
is_current: true,
@@ -611,6 +632,7 @@ mod tests {
611632
};
612633
let other_worktree = WorktreeInfo {
613634
name: "other".to_string(),
635+
git_name: "other".to_string(),
614636
path: PathBuf::from("/tmp/other"),
615637
branch: "feature".to_string(),
616638
is_current: false,
@@ -640,6 +662,7 @@ mod tests {
640662
fn test_table_display_modified_status() {
641663
let clean_worktree = WorktreeInfo {
642664
name: "clean".to_string(),
665+
git_name: "clean".to_string(),
643666
path: PathBuf::from("/tmp/clean"),
644667
branch: "main".to_string(),
645668
is_current: false,
@@ -650,6 +673,7 @@ mod tests {
650673
};
651674
let dirty_worktree = WorktreeInfo {
652675
name: "dirty".to_string(),
676+
git_name: "dirty".to_string(),
653677
path: PathBuf::from("/tmp/dirty"),
654678
branch: "feature".to_string(),
655679
is_current: false,

src/commands/rename.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ pub fn rename_worktree_with_ui(manager: &GitWorktreeManager, ui: &dyn UserInterf
257257
};
258258

259259
// Use business logic to validate rename operation
260-
if let Err(e) = validate_rename_operation(&worktree.name, &new_name) {
260+
if let Err(e) = validate_rename_operation(&worktree.git_name, &new_name) {
261261
utils::print_warning(&e.to_string());
262262
return Ok(());
263263
}
@@ -331,7 +331,7 @@ pub fn rename_worktree_with_ui(manager: &GitWorktreeManager, ui: &dyn UserInterf
331331

332332
// Create rename configuration
333333
let config = WorktreeRenameConfig {
334-
old_name: worktree.name.clone(),
334+
old_name: worktree.git_name.clone(), // Use git_name for internal operations
335335
new_name: new_name.clone(),
336336
old_path: worktree.path.clone(),
337337
new_path,
@@ -432,6 +432,7 @@ mod tests {
432432
let worktrees = vec![
433433
WorktreeInfo {
434434
name: main_name.to_string(),
435+
git_name: main_name.to_string(),
435436
path: PathBuf::from("/tmp/main"),
436437
branch: main_name.to_string(),
437438
is_current: true, // Current worktree - should be filtered out
@@ -442,6 +443,7 @@ mod tests {
442443
},
443444
WorktreeInfo {
444445
name: feature_name.to_string(),
446+
git_name: feature_name.to_string(),
445447
path: PathBuf::from("/tmp/feature"),
446448
branch: feature_name.to_string(),
447449
is_current: false,
@@ -462,6 +464,7 @@ mod tests {
462464
let feature_name = "feature";
463465
let worktree = WorktreeInfo {
464466
name: feature_name.to_string(),
467+
git_name: feature_name.to_string(),
465468
path: PathBuf::from("/tmp/feature"),
466469
branch: feature_name.to_string(),
467470
is_current: false,
@@ -515,6 +518,7 @@ mod tests {
515518
let feature_branch = "feature/auth";
516519
let worktree = WorktreeInfo {
517520
name: worktree_name.to_string(),
521+
git_name: worktree_name.to_string(),
518522
path: PathBuf::from("/tmp/auth"),
519523
branch: feature_branch.to_string(),
520524
is_current: false,
@@ -537,6 +541,7 @@ mod tests {
537541
fn test_analyze_rename_requirements_detached_head() {
538542
let worktree = WorktreeInfo {
539543
name: "detached".to_string(),
544+
git_name: "detached".to_string(),
540545
path: PathBuf::from("/tmp/detached"),
541546
branch: DEFAULT_BRANCH_DETACHED.to_string(),
542547
is_current: false,

src/commands/shared.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ fn batch_delete_worktrees_internal(manager: &GitWorktreeManager) -> Result<()> {
380380
utils::print_warning(&format!("Hook execution warning: {e}"));
381381
}
382382

383-
match manager.remove_worktree(&wt.name) {
383+
match manager.remove_worktree(&wt.git_name) {
384384
Ok(_) => {
385385
let name_red = wt.name.bright_red();
386386
utils::print_success(&format!("Deleted worktree '{name_red}'"));
@@ -846,6 +846,7 @@ mod tests {
846846
fn test_create_search_items() -> Result<()> {
847847
let worktree_info = WorktreeInfo {
848848
name: "feature-branch".to_string(),
849+
git_name: "feature-branch".to_string(),
849850
path: std::path::PathBuf::from("/test/feature-branch"),
850851
branch: "feature/test".to_string(),
851852
is_current: true,
@@ -872,6 +873,7 @@ mod tests {
872873
fn test_validate_search_selection() -> Result<()> {
873874
let worktree_info = WorktreeInfo {
874875
name: "feature-branch".to_string(),
876+
git_name: "feature-branch".to_string(),
875877
path: std::path::PathBuf::from("/test/feature-branch"),
876878
branch: "feature/test".to_string(),
877879
is_current: false,
@@ -898,6 +900,7 @@ mod tests {
898900
let worktrees = vec![
899901
WorktreeInfo {
900902
name: "main".to_string(),
903+
git_name: "main".to_string(),
901904
path: std::path::PathBuf::from("/test/main"),
902905
branch: "main".to_string(),
903906
is_current: true,
@@ -908,6 +911,7 @@ mod tests {
908911
},
909912
WorktreeInfo {
910913
name: "feature-branch".to_string(),
914+
git_name: "feature-branch".to_string(),
911915
path: std::path::PathBuf::from("/test/feature-branch"),
912916
branch: "feature/test".to_string(),
913917
is_current: false,

src/commands/switch.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ mod tests {
307307
let worktrees = vec![
308308
WorktreeInfo {
309309
name: "zzz-last".to_string(),
310+
git_name: "zzz-last".to_string(),
310311
path: PathBuf::from("/tmp/zzz"),
311312
branch: "zzz-branch".to_string(),
312313
is_locked: false,
@@ -317,6 +318,7 @@ mod tests {
317318
},
318319
WorktreeInfo {
319320
name: "aaa-first".to_string(),
321+
git_name: "aaa-first".to_string(),
320322
path: PathBuf::from("/tmp/aaa"),
321323
branch: "aaa-branch".to_string(),
322324
is_locked: false,
@@ -338,6 +340,7 @@ mod tests {
338340
fn test_analyze_switch_target_basic() {
339341
let worktrees = vec![WorktreeInfo {
340342
name: "main".to_string(),
343+
git_name: "main".to_string(),
341344
path: PathBuf::from("/tmp/main"),
342345
branch: "main".to_string(),
343346
is_locked: false,

src/git_interface.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ pub mod mock {
192192
pub fn with_worktree(self, name: &str, path: &str, branch: Option<&str>) -> Self {
193193
let info = WorktreeInfo {
194194
name: name.to_string(),
195+
git_name: name.to_string(), // For test mock, use same name
195196
path: PathBuf::from(path),
196197
branch: branch.unwrap_or("HEAD").to_string(),
197198
is_locked: false,

0 commit comments

Comments
 (0)