Skip to content

Commit

Permalink
cli: refactor clone args
Browse files Browse the repository at this point in the history
the `do_git_clone` function takes a lot of arguments.
This commit reduces that by introducing a CloneArgs type that aggregates
the arguments that are actually related to the git clone operation
  • Loading branch information
bsdinis committed Jan 18, 2025
1 parent 801028b commit 4e367af
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions cli/src/commands/git/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ fn is_empty_dir(path: &Path) -> bool {
}
}

struct CloneArgs<'a> {
depth: Option<NonZeroU32>,
remote_name: &'a str,
source: &'a str,
wc_path: &'a Path,
}

pub fn cmd_git_clone(
ui: &mut Ui,
command: &CommandHelper,
Expand Down Expand Up @@ -119,10 +126,12 @@ pub fn cmd_git_clone(
ui,
command,
args.colocate,
args.depth,
remote_name,
&source,
&canonical_wc_path,
CloneArgs {
depth: args.depth,
remote_name,
source: &source,
wc_path: &canonical_wc_path,
},
);
if clone_result.is_err() {
let clean_up_dirs = || -> io::Result<()> {
Expand Down Expand Up @@ -178,11 +187,15 @@ fn do_git_clone(
ui: &mut Ui,
command: &CommandHelper,
colocate: bool,
depth: Option<NonZeroU32>,
remote_name: &str,
source: &str,
wc_path: &Path,
clone_args: CloneArgs<'_>,
) -> Result<(WorkspaceCommandHelper, GitFetchStats), CommandError> {
let CloneArgs {
depth,
remote_name,
source,
wc_path,
} = clone_args;

let settings = command.settings_for_new_workspace(wc_path)?;
let (workspace, repo) = if colocate {
Workspace::init_colocated_git(&settings, wc_path)?
Expand Down

0 comments on commit 4e367af

Please sign in to comment.