git-multi 0.2.2

A CLI tool for managing multiple Git remotes and syncing content between them
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
mod cli;
mod config;
mod error;
mod git;
mod tui;

use cli::*;
use error::*;
use git::*;

use clap::Parser;
use console::style;
use dialoguer::Confirm;
use std::process;
use tracing::{info, warn};

fn main() {
    let cli = Cli::parse();
    
    if cli.gui {
        if let Err(e) = tui::run_tui() {
            eprintln!("TUI error: {}", e);
            std::process::exit(1);
        }
        return;
    }
    
    // Initialize tracing
    let filter = match cli.verbose {
        0 => "git_multi=info",
        1 => "git_multi=debug",
        _ => "git_multi=trace",
    };
    
    tracing_subscriber::fmt()
        .with_env_filter(filter)
        .init();

    if let Err(e) = run(&cli) {
        eprintln!("{}", style("Error: ").red().bold());
        eprintln!("{}", style(e.to_string()).red());
        process::exit(1);
    }
}

fn run(cli: &Cli) -> Result<()> {
    if let Some(command) = &cli.command {
        match command {
            Commands::Init => cmd_init(),
            Commands::Remote { command } => cmd_remote(command),
            Commands::Branch { command } => cmd_branch(command),
            Commands::Fetch { all, remote, branches, all_branches } => {
                cmd_fetch(*all, remote.clone(), branches.clone(), *all_branches)
            }
            Commands::Pull { all, remote, branches, all_branches } => {
                cmd_pull(*all, remote.clone(), branches.clone(), *all_branches)
            }
            Commands::Push { all, remote, branches, all_branches, force } => {
                cmd_push(*all, remote.clone(), branches.clone(), *all_branches, *force)
            }
            Commands::Checkout { branch, remote, new } => cmd_checkout(branch.clone(), remote.clone(), *new),
            Commands::Sync { from_remote, to_remote, from_branch, to_branch, commits, strategy, force } => {
                cmd_sync(from_remote.clone(), to_remote.clone(), from_branch.clone(), to_branch.clone(), 
                        commits.clone(), *strategy, *force)
            }
            Commands::Merge { from_remote, from_branch, to_branch, to_remote, push } => {
                cmd_merge(from_remote.clone(), from_branch.clone(), to_branch.clone(), to_remote.clone(), *push)
            }
            Commands::Copy { from, to, files, prune } => cmd_copy(from.clone(), to.clone(), files.clone(), *prune),
            Commands::Pr { remote, base, head, title, description, open } => {
                cmd_pr(remote.clone(), base.clone(), head.clone(), title.clone(), description.clone(), *open)
            }
            Commands::Use { remote } => cmd_use(remote.clone()),
            Commands::Status => cmd_status(),
            Commands::List => cmd_list(),
        }
    } else {
        println!("No command specified. Use --help for usage.");
        Ok(())
    }
}

// ========== INIT ==========

fn cmd_init() -> Result<()> {
    info!("Initializing git-multi configuration");
    let _repo = GitRepo::init()?;
    info!("Git-multi initialized successfully!");
    println!("{}", style("Git-multi initialized successfully!").green());
    Ok(())
}

// ========== REMOTE ==========

fn cmd_remote(command: &RemoteCommands) -> Result<()> {
    match command {
        RemoteCommands::Add { name, url, default } => {
            let mut repo = GitRepo::open()?;
            repo.add_remote(name, url)?;
            
            if *default {
                repo.config.set_default_remote(name.clone())?;
                repo.config.save(&repo.repo)?;
            }
            
            println!("Added remote '{}' with URL: {}", style(name).green(), url);
            if *default {
                println!("Set as default remote");
            }
            Ok(())
        }
        RemoteCommands::Remove { name, force } => {
            let mut repo = GitRepo::open()?;
            
            if !*force {
                let confirm = Confirm::new()
                    .with_prompt(format!("Remove remote '{}'? This cannot be undone.", name))
                    .interact()?;
                if !confirm {
                    return Ok(());
                }
            }
            
            repo.remove_remote(name)?;
            println!("Removed remote '{}'", style(name).green());
            Ok(())
        }
        RemoteCommands::List { urls } => {
            let repo = GitRepo::open()?;
            let remotes = if *urls {
                repo.list_remotes_with_urls()?
            } else {
                let names = repo.list_remotes()?;
                names.into_iter().map(|n| (n, "".to_string())).collect()
            };
            
            println!("Remotes:");
            for (name, url) in remotes {
                let default_marker = if repo.config.get_default_remote() == Some(&name) {
                    " *"
                } else {
                    ""
                };
                if *urls {
                    println!("  {}{}: {}", style(&name).cyan(), default_marker, url);
                } else {
                    println!("  {}{}", style(&name).cyan(), default_marker);
                }
            }
            Ok(())
        }
        RemoteCommands::Rename { old_name, new_name } => {
            let mut repo = GitRepo::open()?;
            
            // Rename in git config
            let remote = repo.repo.find_remote(old_name)?;
            let url = remote.url().unwrap().to_string();
            repo.repo.remote_delete(old_name)?;
            repo.repo.remote(new_name, &url)?;
            
            // Update in git-multi config
            if let Some(remote_config) = repo.config.remotes.remove(old_name) {
                repo.config.remotes.insert(new_name.clone(), remote_config);
            }
            
            // Update default remote if needed
            if repo.config.get_default_remote() == Some(old_name) {
                repo.config.set_default_remote(new_name.clone())?;
            }
            
            repo.config.save(&repo.repo)?;
            println!("Renamed remote '{}' to '{}'", old_name, style(new_name).green());
            Ok(())
        }
        RemoteCommands::SetDefault { name } => {
            let mut repo = GitRepo::open()?;
            repo.config.set_default_remote(name.clone())?;
            repo.config.save(&repo.repo)?;
            println!("Default remote set to '{}'", style(name).green());
            Ok(())
        }
        RemoteCommands::SetPrimary { name } => {
            let mut repo = GitRepo::open()?;
            repo.config.set_primary_remote(name)?;
            repo.config.save(&repo.repo)?;
            println!("Primary remote set to '{}'", style(name).green());
            Ok(())
        }
        RemoteCommands::Show { name } => {
            let repo = GitRepo::open()?;
            let remote = repo.repo.find_remote(name)?;

            println!("Remote: {}", style(name).cyan().bold());
            println!("URL: {}", remote.url().unwrap_or("unknown"));

            if let Some(push_url) = remote.pushurl() {
                println!("Push URL: {}", push_url);
            }

            // Show config details
            if let Ok(config) = repo.config.get_remote(name) {
                println!("Is Primary: {}", config.is_primary);
            }
            if let Some((name, _)) = repo.config.get_primary_remote() {
                println!("Primary Remote: {}", name);
            }

            let branches = repo.list_remote_branches(name)?;
            println!("\nBranches:");
            for branch in branches {
                println!("  {}", branch);
            }
            Ok(())
        }
        RemoteCommands::ListNames {} => {
            let repo = GitRepo::open()?;
            for name in repo.config.get_remote_names() {
                println!("{}", name);
            }
            Ok(())
        }
    }
}

// ========== BRANCH ==========

fn cmd_branch(command: &BranchCommands) -> Result<()> {
    match command {
        BranchCommands::List { all, remote } => {
            let repo = GitRepo::open()?;
            
            if let Some(remote_name) = remote {
                let branches = repo.list_remote_branches(remote_name)?;
                println!("Branches on remote '{}':", style(remote_name).cyan());
                for branch in branches {
                    println!("  {}", style(&branch).green());
                }
            } else if *all {
                let info = repo.list_all_branches()?;
                
                println!("Local branches:");
                for branch in &info.local {
                    println!("  {}", style(branch.to_string()).green());
                }
                
                println!("\nRemote branches:");
                for (remote_name, branches) in &info.remote {
                    println!("  {}:", style(remote_name).cyan());
                    for branch in branches {
                        println!("    {}", style(&branch.name).green());
                    }
                }
            } else {
                let info = repo.list_all_branches()?;
                println!("Local branches:");
                for branch in &info.local {
                    println!("  {}", style(branch.to_string()).green());
                }
            }
            Ok(())
        }
        BranchCommands::Delete { branch, force, remote } => {
            let repo = GitRepo::open()?;
            
            if !*force {
                let confirm = Confirm::new()
                    .with_prompt(format!("Delete branch '{}'? This cannot be undone.", branch))
                    .interact()?;
                if !confirm {
                    return Ok(());
                }
            }
            
            if *remote {
                // Delete remote branch
                let remote_names = repo.repo.remotes()?;
                for remote_name in remote_names.iter().flatten() {
                    let refspec = format!(":refs/heads/{}", branch);
                    let mut remote = repo.repo.find_remote(remote_name)?;
                    remote.push(&[&refspec], None)?;
                    println!("Deleted branch '{}' from remote '{}'", branch, remote_name);
                }
            } else {
                // Delete local branch
                let mut local_branch = repo.repo.find_branch(branch, git2::BranchType::Local)?;
                local_branch.delete()?;
                println!("Deleted local branch '{}'", style(branch).green());
            }
            Ok(())
        }
        BranchCommands::Create { branch, base, remotes, checkout } => {
            let repo = GitRepo::open()?;
            
            let base_oid = repo.resolve_commit_spec(base)?;
            let base_commit = repo.repo.find_commit(base_oid)?;
            
            // Create local branch
            repo.repo.branch(branch, &base_commit, false)?;
            println!("Created local branch '{}' from '{}'", style(branch).green(), base);
            
            // Create on remotes
            if let Some(remote_names) = remotes {
                for remote_name in remote_names {
                    let mut remote = repo.repo.find_remote(remote_name)?;
                    let refspec = format!("refs/heads/{}:refs/heads/{}", branch, branch);
                    remote.push(&[&refspec], None)?;
                    println!("Created branch '{}' on remote '{}'", style(branch).green(), style(&remote_name).cyan());
                }
            }
            
            if *checkout {
                repo.checkout_branch(branch)?;
                println!("Checked out '{}'", branch);
            }
            
            Ok(())
        }
        BranchCommands::Rename { old_name, new_name } => {
            let repo = GitRepo::open()?;
            repo.rename_branch(old_name, new_name)?;
            println!("Renamed branch '{}' to '{}'", style(old_name).green(), style(new_name).green());
            Ok(())
        }
    }
}

// ========== FETCH ==========

fn cmd_fetch(all: bool, remote: Option<String>, branches: Vec<String>, all_branches: bool) -> Result<()> {
    let repo = GitRepo::open()?;
    
    if all {
        let fetched = repo.fetch_all()?;
        println!("Fetched from {} remote(s):", style(fetched.len()).green());
        for name in fetched {
            println!("  {}", style(&name).cyan());
        }
    } else if let Some(remote_name) = remote {
        if !branches.is_empty() {
            repo.fetch_branches(&remote_name, &branches)?;
            println!("Fetched branches {:?} from '{}'", branches, style(&remote_name).green());
        } else if all_branches {
            repo.fetch_remote(&remote_name)?;
            println!("Fetched all branches from '{}'", style(&remote_name).green());
        } else {
            repo.fetch_remote(&remote_name)?;
            println!("Fetched from '{}'", style(&remote_name).green());
        }
    } else {
        // Default: fetch from all remotes
        let fetched = repo.fetch_all()?;
        println!("Fetched from {} remote(s)", style(fetched.len()).green());
    }
    Ok(())
}

// ========== PULL ==========

fn cmd_pull(all: bool, remote: Option<String>, branches: Vec<String>, all_branches: bool) -> Result<()> {
    let repo = GitRepo::open()?;
    
    if all {
        let pulled = repo.pull_from_all(None)?;
        println!("Pulled from {} remote(s):", style(pulled.len()).green());
        for name in pulled {
            println!("  {}", style(&name).cyan());
        }
    } else if let Some(remote_name) = remote {
        if !branches.is_empty() {
            repo.pull_branches(&remote_name, &branches)?;
            println!("Pulled branches {:?} from '{}'", branches, style(&remote_name).green());
        } else if all_branches {
            repo.fetch_remote(&remote_name)?;
            let brs = repo.list_remote_branches(&remote_name)?;
            repo.pull_branches(&remote_name, &brs)?;
            println!("Pulled all branches from '{}'", style(&remote_name).green());
        } else {
            // Default: pull current branch
            repo.pull_from_remote(&remote_name, None)?;
            println!("Pulled from '{}'", style(&remote_name).green());
        }
    } else {
        // Default: pull from default remote
        if let Some(default_remote) = repo.config.get_default_remote() {
            repo.pull_from_remote(default_remote, None)?;
            println!("Pulled from default remote '{}'", style(default_remote).green());
        } else {
            return Err(GitMultiError::NoRemotesConfigured);
        }
    }
    Ok(())
}

// ========== PUSH ==========

fn cmd_push(all: bool, remote: Option<String>, branches: Vec<String>, all_branches: bool, force: bool) -> Result<()> {
    let repo = GitRepo::open()?;
    
    if all {
        let pushed = repo.push_to_all(None)?;
        println!("Pushed to {} remote(s):", style(pushed.len()).green());
        for name in pushed {
            println!("  {}", style(&name).cyan());
        }
    } else if let Some(remote_name) = remote {
        if !branches.is_empty() {
            repo.push_branches(&remote_name, &branches, force)?;
            println!("Pushed branches {:?} to '{}'", branches, style(&remote_name).green());
            if force {
                println!("  Force: yes");
            }
        } else if all_branches {
            let brs = repo.local_branch_names()?;
            repo.push_branches(&remote_name, &brs, force)?;
            println!("Pushed all local branches to '{}'", style(&remote_name).green());
            if force {
                println!("  Force: yes");
            }
        } else {
            // Default: push current branch
            repo.push_to_remote(&remote_name, None)?;
            println!("Pushed to '{}'", style(&remote_name).green());
        }
    } else {
        // Default: push to default remote
        if let Some(default_remote) = repo.config.get_default_remote() {
            repo.push_to_remote(default_remote, None)?;
            println!("Pushed to default remote '{}'", style(default_remote).green());
        } else {
            return Err(GitMultiError::NoRemotesConfigured);
        }
    }
    Ok(())
}

// ========== CHECKOUT ==========

fn cmd_checkout(branch: String, remote: Option<String>, new: bool) -> Result<()> {
    let repo = GitRepo::open()?;
    
    if let Some(remote_name) = remote {
        repo.checkout_remote_branch(&remote_name, &branch)?;
        println!("Checked out '{}' from remote '{}'", style(&branch).green(), remote_name);
    } else if new {
        // Create new branch
        let head_commit = repo.head_commit()?;
        repo.repo.branch(&branch, &head_commit, false)?;
        repo.checkout_branch(&branch)?;
        println!("Created and checked out new branch '{}'", style(&branch).green());
    } else {
        repo.checkout_branch(&branch)?;
        println!("Checked out '{}'", style(&branch).green());
    }
    Ok(())
}

// ========== SYNC ==========

fn cmd_sync(
    from_remote: String,
    to_remote: String,
    from_branch: String,
    to_branch: String,
    commits: String,
    strategy: SyncStrategy,
    _force: bool,
) -> Result<()> {
    let repo = GitRepo::open()?;
    
    info!("Syncing from {}/{}", from_remote, from_branch);
    info!("Syncing to   {}/{}", to_remote, to_branch);
    info!("Strategy: {}", strategy);
    info!("Commit range: {}", commits);
    
    // Parse source and destination
    let from_ref = format!("refs/remotes/{}/{}", from_remote, from_branch);
    let to_ref = format!("refs/remotes/{}/{}", to_remote, to_branch);
    
    match strategy {
        SyncStrategy::CherryPick => {
            let picked = repo.cherry_pick_range(&from_ref, &to_ref, &commits)?;
            println!("Cherry-picked {} commit(s):", style(picked.len()).green());
            for sha in picked {
                println!("  {}", style(&sha[..8]).cyan());
            }
        }
        SyncStrategy::Merge => {
            // For merge, we need to fetch both branches first
            repo.fetch_remote(&from_remote)?;
            repo.fetch_remote(&to_remote)?;
            
            // Checkout target branch
            repo.checkout_branch(&to_branch)?;
            
            // Merge source branch
            repo.merge_branch(&from_branch)?;
            println!("Merged '{}' into '{}'", style(&from_branch).green(), to_branch);
        }
        SyncStrategy::Rebase => {
            repo.fetch_remote(&from_remote)?;
            repo.fetch_remote(&to_remote)?;
            
            // Checkout source branch
            repo.checkout_branch(&from_branch)?;
            
            // Rebase onto target branch
            repo.rebase_branch(&to_branch)?;
            println!("Rebased '{}' onto '{}'", style(&from_branch).green(), to_branch);
        }
    }
    
    Ok(())
}

// ========== MERGE ==========

fn cmd_merge(
    from_remote: String,
    from_branch: String,
    to_branch: Option<String>,
    to_remote: Option<String>,
    push: bool,
) -> Result<()> {
    let repo = GitRepo::open()?;

    let target_branch = match to_branch {
        Some(b) => b,
        None => repo.current_branch()?
            .ok_or_else(|| GitMultiError::SyncError("Cannot determine current branch to merge into".to_string()))?,
    };

    let src_ref = format!("refs/remotes/{}/{}", from_remote, from_branch);

    info!("Merging {}/{} into {}", from_remote, from_branch, target_branch);

    repo.fetch_remote(&from_remote)?;
    repo.checkout_branch(&target_branch)?;
    repo.merge_and_commit(&src_ref)?;
    println!(
        "Merged '{}/{}' into '{}'",
        style(&from_remote).cyan(),
        style(&from_branch).green(),
        style(&target_branch).green()
    );

    if push {
        let target = to_remote.ok_or_else(|| {
            GitMultiError::SyncError("Specify --to-remote to push the merged result".to_string())
        })?;
        repo.push_to_remote(&target, Some(&target_branch))?;
        println!("Pushed '{}' to '{}'", style(&target_branch).green(), style(&target).cyan());
    }

    Ok(())
}

// ========== COPY ==========

fn cmd_copy(from: String, to: Option<String>, files: Vec<String>, prune: bool) -> Result<()> {
    let repo = GitRepo::open()?;
    
    // Parse from and to specifications (format: remote:branch or just branch)
    let (from_remote, from_branch) = parse_ref_spec(&from);
    let to_info = to.as_deref().map(parse_ref_spec);
    
    info!("Copying files from {}/{}", from_remote.as_deref().unwrap_or("local"), from_branch);
    if let Some((ref to_remote, ref to_branch)) = to_info {
        info!("Copying files to   {}/{}", to_remote.as_deref().unwrap_or("local"), to_branch);
    } else {
        info!("Copying files to working directory");
    }
    
    let from_ref = if let Some(ref remote) = from_remote {
        format!("refs/remotes/{}/{}", remote, from_branch)
    } else {
        from_branch
    };
    
    let copied = repo.copy_files(&from_ref, &files)?;
    
    println!("Copied {} file(s):", style(copied.len()).green());
    for file in copied {
        println!("  {}", style(&file).cyan());
    }
    
    if prune {
        warn!("Prune option not yet implemented");
    }
    
    Ok(())
}

fn parse_ref_spec(spec: &str) -> (Option<String>, String) {
    if spec.contains(':') {
        let parts: Vec<&str> = spec.splitn(2, ':').collect();
        (Some(parts[0].to_string()), parts[1].to_string())
    } else {
        (None, spec.to_string())
    }
}

// ========== PR ==========

fn cmd_pr(
    remote: String,
    base: String,
    head: Option<String>,
    title: String,
    description: Option<String>,
    open: bool,
) -> Result<()> {
    let repo = GitRepo::open()?;
    
    let head_branch = head.unwrap_or_else(|| {
        repo.current_branch().ok().flatten().unwrap_or_else(|| "HEAD".to_string())
    });
    
    info!("Creating PR on {}", remote);
    info!("Base: {}", base);
    info!("Head: {}", head_branch);
    info!("Title: {}", title);
    
    repo.create_pr(&remote, &base, &head_branch, &title, description.as_deref())?;
    
    println!("Pull request created successfully!");
    println!("  Repository: {}", style(&remote).cyan());
    println!("  Base: {} <- Head: {}", style(&base).green(), style(&head_branch).green());
    println!("  Title: {}", style(&title).yellow());
    
    if open {
        // For now, just print a message
        // Could use `gh pr view --web` to open in browser
        println!("  Run `gh pr view --web` to open in browser");
    }
    
    Ok(())
}

// ========== USE ==========

fn cmd_use(remote: String) -> Result<()> {
    let mut repo = GitRepo::open()?;
    
    repo.config.set_default_remote(remote.clone())?;
    repo.config.save(&repo.repo)?;
    
    println!("Default remote set to '{}'", style(&remote).green());
    Ok(())
}

// ========== STATUS ==========

fn cmd_status() -> Result<()> {
    let repo = GitRepo::open()?;
    
    println!("Git Multi-Remote Status");
    println!("{}", "=".repeat(40));
    
    // Current branch
    if let Some(branch) = repo.current_branch()? {
        println!("Current branch: {}", style(&branch).green().bold());
    }
    
    // Remotes
    println!("\nRemotes:");
    let remotes = repo.list_remotes_with_urls()?;
    for (name, url) in remotes {
        let default_marker = if repo.config.get_default_remote() == Some(&name) {
            " [default]"
        } else {
            ""
        };
        println!("  {}{}: {}", style(&name).cyan(), default_marker, url);
    }
    
    // Branches
    println!("\nLocal branches:");
    let info = repo.list_all_branches()?;
    for branch in &info.local {
        println!("  {}", style(branch.name.clone()).green());
    }
    
    Ok(())
}

// ========== LIST ==========

fn cmd_list() -> Result<()> {
    let repo = GitRepo::open()?;
    
    let remotes = repo.list_remotes()?;
    
    for remote_name in remotes {
        println!("\nRemote: {}", style(&remote_name).cyan().bold());
        let branches = repo.list_remote_branches(&remote_name)?;
        for branch in branches {
            println!("  {}", style(&branch).green());
        }
    }
    
    Ok(())
}