Skip to content

Commit

Permalink
Merge pull request #145 from siketyan/feat/recursive-pathspec
Browse files Browse the repository at this point in the history
feat: Support specifying pathspec on recursive option
  • Loading branch information
siketyan authored Apr 25, 2023
2 parents fbcfbe7 + 55d3282 commit bba05ed
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/cmd/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ pub struct Cmd {
parallel: bool,

/// Clones their submodules recursively.
#[clap(short, long)]
recursive: bool,
#[clap(short, long, alias = "recurse-submodules")]
recursive: Option<Option<String>>,

/// Clones only the default branch.
#[clap(long)]
Expand Down Expand Up @@ -178,7 +178,7 @@ impl Cmd {
url.clone(),
&path,
&CloneOptions {
recursive: self.recursive,
recursive: self.recursive.clone(),
single_branch: self.single_branch,
},
) {
Expand Down
2 changes: 1 addition & 1 deletion src/git/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use anyhow::Result;

#[derive(Debug, Default)]
pub struct CloneOptions {
pub recursive: bool,
pub recursive: Option<Option<String>>,
pub single_branch: bool,
}

Expand Down
17 changes: 12 additions & 5 deletions src/git/strategy/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,20 @@ impl CloneRepository for Cli {
{
debug!("Cloning the repository using CLI strategy");

let url = url.to_string();
let mut args = vec!["clone", &url, path.as_ref().to_str().unwrap()];
if options.recursive {
args.push("--recursive");
let mut args = vec![
"clone".to_string(),
url.to_string(),
path.as_ref().to_string_lossy().to_string(),
];

if let Some(recursive) = options.recursive.as_ref() {
args.push(match recursive.as_deref() {
Some(path) => format!("--recurse-submodules={path}"),
_ => "--recurse-submodules".to_string(),
});
}
if options.single_branch {
args.push("--single-branch")
args.push("--single-branch".to_string());
}

let output = Command::new("git").args(args).output()?;
Expand Down

0 comments on commit bba05ed

Please sign in to comment.