From 5de0d572c55e173a7dcdef024b44a6f2e6c9e56f Mon Sep 17 00:00:00 2001 From: Natsuki Ikeguchi Date: Wed, 26 Apr 2023 01:29:03 +0900 Subject: [PATCH] feat: Support --origin and --branch options on cloning --- src/cmd/clone.rs | 10 ++++++++++ src/git/mod.rs | 2 ++ src/git/strategy/cli.rs | 6 ++++++ 3 files changed, 18 insertions(+) diff --git a/src/cmd/clone.rs b/src/cmd/clone.rs index 69f8d5e..0cd2d2b 100644 --- a/src/cmd/clone.rs +++ b/src/cmd/clone.rs @@ -44,6 +44,14 @@ pub struct Cmd { #[clap(long)] single_branch: bool, + /// Uses this name instead of `origin` for the upstream remote. + #[clap(short, long)] + origin: Option, + + /// Points the specified branch instead of the default branch after cloned the repository. + #[clap(short, long)] + branch: Option, + /// Change directory after cloning the repository (Shell extension required). #[clap(long)] cd: bool, @@ -180,6 +188,8 @@ impl Cmd { &CloneOptions { recursive: self.recursive.clone(), single_branch: self.single_branch, + origin: self.origin.clone(), + branch: self.branch.clone(), }, ) { retries += 1; diff --git a/src/git/mod.rs b/src/git/mod.rs index d6738c3..af401ee 100644 --- a/src/git/mod.rs +++ b/src/git/mod.rs @@ -11,6 +11,8 @@ use anyhow::Result; pub struct CloneOptions { pub recursive: Option>, pub single_branch: bool, + pub origin: Option, + pub branch: Option, } pub trait CloneRepository { diff --git a/src/git/strategy/cli.rs b/src/git/strategy/cli.rs index 7c92f4b..ac60a1b 100644 --- a/src/git/strategy/cli.rs +++ b/src/git/strategy/cli.rs @@ -31,6 +31,12 @@ impl CloneRepository for Cli { if options.single_branch { args.push("--single-branch".to_string()); } + if let Some(origin) = options.origin.as_deref() { + args.push(format!("--origin={origin}")); + } + if let Some(branch) = options.branch.as_deref() { + args.push(format!("--branch={branch}")); + } let output = Command::new("git").args(args).output()?; match output.status.success() {