Skip to content

Commit

Permalink
Merge pull request #146 from siketyan/feat/origin-branch-name
Browse files Browse the repository at this point in the history
feat: Support --origin and --branch options on cloning
siketyan authored Apr 25, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents bba05ed + 5de0d57 commit 13d96b3
Showing 3 changed files with 18 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/cmd/clone.rs
Original file line number Diff line number Diff line change
@@ -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<String>,

/// Points the specified branch instead of the default branch after cloned the repository.
#[clap(short, long)]
branch: Option<String>,

/// 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;
2 changes: 2 additions & 0 deletions src/git/mod.rs
Original file line number Diff line number Diff line change
@@ -11,6 +11,8 @@ use anyhow::Result;
pub struct CloneOptions {
pub recursive: Option<Option<String>>,
pub single_branch: bool,
pub origin: Option<String>,
pub branch: Option<String>,
}

pub trait CloneRepository {
6 changes: 6 additions & 0 deletions src/git/strategy/cli.rs
Original file line number Diff line number Diff line change
@@ -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() {

0 comments on commit 13d96b3

Please sign in to comment.