1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
use std::path::{Path, PathBuf};
use crate::config::repository_config::MerkleStoreKind;
use crate::opts::FetchOpts;
#[derive(Clone, Debug, Default)]
pub struct CloneOpts {
// The url of the remote repository to clone
pub url: String,
// The local destination path to clone the repository to
pub dst: PathBuf,
// FetchOpts
pub fetch_opts: FetchOpts,
// Flag for cloning on VFS
pub is_vfs: bool,
// Flag for remote mode
pub is_remote: bool,
// Which Merkle tree store to use locally for the cloned repo. A per-disk choice
// (like the one `oxen init` lets the caller make) — independent of the remote's
// backend. Defaults to [`MerkleStoreKind::default()`] (File) so existing callers
// are byte-for-byte unchanged.
pub merkle_store_kind: MerkleStoreKind,
}
impl CloneOpts {
/// Sets `branch` to `DEFAULT_BRANCH_NAME` and defaults `all` to `false`
pub fn new(url: impl AsRef<str>, dst: impl AsRef<Path>) -> CloneOpts {
CloneOpts {
url: url.as_ref().to_string(),
dst: dst.as_ref().to_path_buf(),
fetch_opts: FetchOpts::new(),
is_vfs: false,
is_remote: false,
merkle_store_kind: MerkleStoreKind::default(),
}
}
pub fn from_branch(
url: impl AsRef<str>,
dst: impl AsRef<Path>,
branch: impl AsRef<str>,
) -> CloneOpts {
CloneOpts {
fetch_opts: FetchOpts::from_branch(branch.as_ref()),
is_vfs: false,
is_remote: false,
merkle_store_kind: MerkleStoreKind::default(),
..CloneOpts::new(url, dst)
}
}
}
#[cfg(test)]
mod tests {
use super::*;
/// `CloneOpts::default()` (also reached via `..Default::default()` from
/// callers like `oxen-py`) picks the type-level default for
/// `merkle_store_kind`, which is `File`. This preserves every existing
/// caller byte-for-byte after the Phase I plumbing change.
#[test]
fn test_clone_opts_default_uses_file_merkle_store() {
let opts = CloneOpts::default();
assert_eq!(opts.merkle_store_kind, MerkleStoreKind::File);
assert!(!opts.is_vfs);
}
/// `CloneOpts::new` is the most commonly used constructor — confirm it
/// also defaults to File so existing call sites are unchanged.
#[test]
fn test_clone_opts_new_uses_file_merkle_store() {
let opts = CloneOpts::new("http://example.com/ns/repo", "/tmp/dst");
assert_eq!(opts.merkle_store_kind, MerkleStoreKind::File);
}
}