Skip to main content

git_side/commands/
remote.rs

1use colored::Colorize;
2
3use crate::error::Result;
4use crate::side_repo::SideRepo;
5
6/// Manage side repo remotes.
7///
8/// # Errors
9///
10/// Returns an error if the side repo cannot be opened or git commands fail.
11pub fn run(args: &[String]) -> Result<()> {
12    let repo = SideRepo::open()?;
13    repo.ensure_initialized()?;
14
15    if args.is_empty() {
16        // List remotes
17        let output = repo.git(&["remote", "-v"])?;
18        if output.is_empty() {
19            println!("{}", "No remotes configured.".yellow());
20        } else {
21            println!("{output}");
22        }
23    } else {
24        // Pass through to git remote
25        let args_refs: Vec<&str> = std::iter::once("remote")
26            .chain(args.iter().map(String::as_str))
27            .collect();
28        let output = repo.git(&args_refs)?;
29        if !output.is_empty() {
30            println!("{output}");
31        }
32
33        // Show success message for add/remove
34        if args.first().is_some_and(|a| a == "add") {
35            println!("{} Remote added.", "Done.".green().bold());
36        } else if args.first().is_some_and(|a| a == "remove" || a == "rm") {
37            println!("{} Remote removed.", "Done.".green().bold());
38        }
39    }
40
41    Ok(())
42}