Skip to content

Commit b81f650

Browse files
committed
feat: gix clone <url> is now permitted without specifying a destination directory. (#683)
Note that the implementation doesn't take into account potential redirects and renames as it's implemented only with the first URL it sees (not the redirected ones).
1 parent 41fc2bb commit b81f650

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

Diff for: gitoxide-core/src/repository/clone.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ pub const PROGRESS_RANGE: std::ops::RangeInclusive<u8> = 1..=3;
1212
pub(crate) mod function {
1313
use std::ffi::OsStr;
1414

15-
use anyhow::bail;
15+
use anyhow::{bail, Context};
1616
use git_repository as git;
1717
use git_repository::{bstr::BString, remote::fetch::Status, Progress};
1818

1919
use super::Options;
2020
use crate::{repository::fetch::function::print_updates, OutputFormat};
2121

2222
pub fn clone<P>(
23-
remote: impl AsRef<OsStr>,
24-
directory: impl AsRef<std::path::Path>,
23+
url: impl AsRef<OsStr>,
24+
directory: Option<impl Into<std::path::PathBuf>>,
2525
overrides: Vec<BString>,
2626
mut progress: P,
2727
mut out: impl std::io::Write,
@@ -41,8 +41,16 @@ pub(crate) mod function {
4141
bail!("JSON output isn't yet supported for fetching.");
4242
}
4343

44+
let url: git::Url = url.as_ref().try_into()?;
45+
let directory = directory.map(|dir| Ok(dir.into())).unwrap_or_else(|| {
46+
git::path::from_bstr(url.path.as_ref())
47+
.as_ref()
48+
.file_stem()
49+
.map(Into::into)
50+
.context("Filename extraction failed - path too short")
51+
})?;
4452
let mut prepare = git::clone::PrepareFetch::new(
45-
remote.as_ref(),
53+
url,
4654
directory,
4755
bare.then(|| git::create::Kind::Bare)
4856
.unwrap_or(git::create::Kind::WithWorktree),

Diff for: src/plumbing/options/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ pub mod clone {
182182
pub remote: OsString,
183183

184184
/// The directory to initialize with the new repository and to which all data should be written.
185-
pub directory: PathBuf,
185+
pub directory: Option<PathBuf>,
186186
}
187187
}
188188

0 commit comments

Comments
 (0)