Fixes the added --branch parameter of repo add

Signed-off-by: alexis-opolka <53085471+alexis-opolka@users.noreply.github.com>
This commit is contained in:
alexis-opolka 2025-05-18 12:40:31 +02:00
parent 85ed5e8b05
commit 8bb4f317a8
6 changed files with 12 additions and 11 deletions

2
Cargo.lock generated
View file

@ -428,7 +428,7 @@ dependencies = [
[[package]]
name = "navi"
version = "2.25.0-beta2"
version = "2.25.0-beta3"
dependencies = [
"anyhow",
"clap",

View file

@ -1,6 +1,6 @@
[package]
name = "navi"
version = "2.25.0-beta2"
version = "2.25.0-beta3"
authors = ["Denis Isidoro <denis_isidoro@live.com>", "Alexis Opolka <alexis.opolka@protonmail.com>"]
edition = "2021"
description = "An interactive cheatsheet tool for the command-line"

View file

@ -32,7 +32,7 @@ fn ask_folder_present_question(finder: &FinderChoice) -> Result<bool> {
finder_yes_no_question(finder, opts)
}
pub fn main(uri: String, yes_flag: bool, &branch: Option<String>) -> Result<()> {
pub fn main(uri: String, yes_flag: bool, branch: &Option<String>) -> Result<()> {
let finder = CONFIG.finder();
// If the user has set the yes flag, we don't ask a confirmation

View file

@ -20,7 +20,7 @@ pub fn main() -> Result<String> {
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 = {

View file

@ -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<String>,
},
@ -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()

View file

@ -6,10 +6,10 @@ pub fn shallow_clone(uri: &str, target: &str, branch: &Option<String>) -> 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<String>) -> Result
.map_err(|e| ShellSpawnError::new("git clone", e))?
.wait()
.context("Unable to git clone")?;
Ok(())
}