Skip to content

Commit 70559d2

Browse files
author
顽强
committed
<feature> 支持仓库配置 sparse-checkout-dirs 字段
1 parent c9505cf commit 70559d2

File tree

5 files changed

+26
-3
lines changed

5 files changed

+26
-3
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ members = [
66
]
77

88
[workspace.package]
9-
version = "1.2.2"
9+
version = "1.2.3"
1010
edition = "2021"
1111
repository = "https://github.com/funny/mgit"
1212

core/src/core/git.rs

+14
Original file line numberDiff line numberDiff line change
@@ -273,3 +273,17 @@ pub fn log_current(path: impl AsRef<Path>) -> Result<String, anyhow::Error> {
273273
];
274274
exec_cmd(path, "git", &args)
275275
}
276+
277+
pub fn sparse_checkout_set(path: impl AsRef<Path>, dirs: &Vec<String>) -> Result<(), anyhow::Error> {
278+
let mut args = vec!["sparse-checkout", "set", "--no-cone"];
279+
for dir in dirs{
280+
args.push(dir)
281+
}
282+
283+
exec_cmd(path, "git", &args).map(|_| ())
284+
}
285+
286+
pub fn sparse_checkout_disable(path: impl AsRef<Path>) -> Result<(), anyhow::Error> {
287+
let args = vec!["sparse-checkout", "disable"];
288+
exec_cmd(path, "git", &args).map(|_| ())
289+
}

core/src/core/repo.rs

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub struct TomlRepo {
2222
pub branch: Option<String>,
2323
pub tag: Option<String>,
2424
pub commit: Option<String>,
25+
pub sparse_checkout_dirs: Option<Vec<String>>,
2526
}
2627

2728
impl RepoId {

core/src/ops/snapshot.rs

+1
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ pub fn snapshot_repo(options: SnapshotOptions) -> MgitResult {
154154
branch,
155155
tag: None,
156156
commit,
157+
sparse_checkout_dirs: None,
157158
};
158159
repos.push(toml_repo);
159160
logger::info(format!(" + {}", norm_str));

core/src/ops/sync.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,12 @@ fn inner_exec(
365365
// reset --hard
366366
exec_reset(input_path, repo_info, progress, ResetType::Hard)
367367
}
368-
}
368+
}?;
369+
370+
match repo_info.toml_repo.sparse_checkout_dirs.as_ref(){
371+
Some(dirs) => git::sparse_checkout_set(&full_path,dirs),
372+
None=>git::sparse_checkout_disable(&full_path)
373+
}
369374
}
370375

371376
fn exec_init(
@@ -420,7 +425,9 @@ fn exec_reset(
420425
ResetType::Mixed => "--mixed",
421426
ResetType::Hard => "--hard",
422427
};
423-
git::reset(full_path, reset_type, remote_ref_str)
428+
429+
git::reset(&full_path, reset_type, remote_ref_str)
430+
424431
}
425432

426433
fn exec_stash(

0 commit comments

Comments
 (0)