From 8bb4f317a8a63714c05f9b2bc8a70e8bfea5dc8e Mon Sep 17 00:00:00 2001 From: alexis-opolka <53085471+alexis-opolka@users.noreply.github.com> Date: Sun, 18 May 2025 12:40:31 +0200 Subject: [PATCH] Fixes the added --branch parameter of repo add Signed-off-by: alexis-opolka <53085471+alexis-opolka@users.noreply.github.com> --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/commands/repo/add.rs | 2 +- src/commands/repo/browse.rs | 2 +- src/commands/repo/mod.rs | 8 ++++---- src/common/git.rs | 7 ++++--- 6 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 954637c..62c85fc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -428,7 +428,7 @@ dependencies = [ [[package]] name = "navi" -version = "2.25.0-beta2" +version = "2.25.0-beta3" dependencies = [ "anyhow", "clap", diff --git a/Cargo.toml b/Cargo.toml index 4f9491f..1df5298 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "navi" -version = "2.25.0-beta2" +version = "2.25.0-beta3" authors = ["Denis Isidoro ", "Alexis Opolka "] edition = "2021" description = "An interactive cheatsheet tool for the command-line" diff --git a/src/commands/repo/add.rs b/src/commands/repo/add.rs index be11533..19833dc 100644 --- a/src/commands/repo/add.rs +++ b/src/commands/repo/add.rs @@ -32,7 +32,7 @@ fn ask_folder_present_question(finder: &FinderChoice) -> Result { finder_yes_no_question(finder, opts) } -pub fn main(uri: String, yes_flag: bool, &branch: Option) -> Result<()> { +pub fn main(uri: String, yes_flag: bool, branch: &Option) -> Result<()> { let finder = CONFIG.finder(); // If the user has set the yes flag, we don't ask a confirmation diff --git a/src/commands/repo/browse.rs b/src/commands/repo/browse.rs index f730f78..6db7c4e 100644 --- a/src/commands/repo/browse.rs +++ b/src/commands/repo/browse.rs @@ -20,7 +20,7 @@ pub fn main() -> Result { filesystem::create_dir(&repo_pathbuf)?; let (repo_url, _, _) = git::meta("denisidoro/cheats"); - git::shallow_clone(repo_url.as_str(), repo_path_str, None) + git::shallow_clone(repo_url.as_str(), repo_path_str, &None) .with_context(|| format!("Failed to clone `{repo_url}`"))?; let feature_repos_file = { diff --git a/src/commands/repo/mod.rs b/src/commands/repo/mod.rs index 3fad381..6c014e1 100644 --- a/src/commands/repo/mod.rs +++ b/src/commands/repo/mod.rs @@ -11,7 +11,7 @@ mod sync; pub enum RepoCommand { /// Browses for featured cheatsheet repos Browse, - /// Imports cheatsheets from a repo + /// Imports cheatsheets from a git repository Add { /// A URI to a git repository containing .cheat files ("user/repo" will download cheats from github.com/user/repo) uri: String, @@ -19,7 +19,7 @@ pub enum RepoCommand { #[clap(short = 'y', long = "yes")] yes_flag: bool, - /// Lets you target a specific git ref (e.g. a commit or a branch), anything accepted by the `--branch` parameter of `git-clone` + /// Lets you target a specific git ref (e.g. a branch), anything accepted by the `--branch` parameter of `git-clone` #[clap(short = 'b', long = "branch")] branch: Option, }, @@ -44,14 +44,14 @@ impl Runnable for Input { fn run(&self) -> Result<()> { match &self.cmd { RepoCommand::Add { uri, yes_flag, branch } => { - add::main(uri.clone(), *yes_flag, &branch) + add::main(uri.clone(), *yes_flag, branch) .with_context(|| format!("Failed to import cheatsheets from `{uri}`"))?; commands::core::main() } RepoCommand::Browse => { let repo = browse::main().context("Failed to browse featured cheatsheets")?; - add::main(repo.clone(), false, None) + add::main(repo.clone(), false, &None) .with_context(|| format!("Failed to import cheatsheets from `{repo}`"))?; commands::core::main() diff --git a/src/common/git.rs b/src/common/git.rs index 5b7f089..e3dad00 100644 --- a/src/common/git.rs +++ b/src/common/git.rs @@ -6,10 +6,10 @@ pub fn shallow_clone(uri: &str, target: &str, branch: &Option) -> Result // If we target a specific ref, we add the parameter inside the arguments to call // git with. - let git_clone_args = if branch.is_some() { - ["clone", uri, target, "--depth", "1", "--branch", branch.unwrap().as_str()] + let git_clone_args: Vec<&str> = if branch.is_some() { + Vec::from(["clone", uri, target, "--depth", "1", "--branch", branch.as_ref().unwrap().as_str()]) } else { - ["clone", uri, target, "--depth", "1", "", ""] + Vec::from(["clone", uri, target, "--depth", "1"]) }; Command::new("git") @@ -18,6 +18,7 @@ pub fn shallow_clone(uri: &str, target: &str, branch: &Option) -> Result .map_err(|e| ShellSpawnError::new("git clone", e))? .wait() .context("Unable to git clone")?; + Ok(()) }