Skip to content

Commit

Permalink
<feature> 支持仓库配置 sparse-checkout-dirs 字段
Browse files Browse the repository at this point in the history
  • Loading branch information
顽强 committed Feb 2, 2024
1 parent c9505cf commit 70559d2
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ members = [
]

[workspace.package]
version = "1.2.2"
version = "1.2.3"
edition = "2021"
repository = "https://github.com/funny/mgit"

Expand Down
14 changes: 14 additions & 0 deletions core/src/core/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,3 +273,17 @@ pub fn log_current(path: impl AsRef<Path>) -> Result<String, anyhow::Error> {
];
exec_cmd(path, "git", &args)
}

pub fn sparse_checkout_set(path: impl AsRef<Path>, dirs: &Vec<String>) -> Result<(), anyhow::Error> {
let mut args = vec!["sparse-checkout", "set", "--no-cone"];
for dir in dirs{
args.push(dir)
}

exec_cmd(path, "git", &args).map(|_| ())
}

pub fn sparse_checkout_disable(path: impl AsRef<Path>) -> Result<(), anyhow::Error> {
let args = vec!["sparse-checkout", "disable"];
exec_cmd(path, "git", &args).map(|_| ())
}
1 change: 1 addition & 0 deletions core/src/core/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub struct TomlRepo {
pub branch: Option<String>,
pub tag: Option<String>,
pub commit: Option<String>,
pub sparse_checkout_dirs: Option<Vec<String>>,
}

impl RepoId {
Expand Down
1 change: 1 addition & 0 deletions core/src/ops/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ pub fn snapshot_repo(options: SnapshotOptions) -> MgitResult {
branch,
tag: None,
commit,
sparse_checkout_dirs: None,
};
repos.push(toml_repo);
logger::info(format!(" + {}", norm_str));
Expand Down
11 changes: 9 additions & 2 deletions core/src/ops/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,12 @@ fn inner_exec(
// reset --hard
exec_reset(input_path, repo_info, progress, ResetType::Hard)
}
}
}?;

match repo_info.toml_repo.sparse_checkout_dirs.as_ref(){
Some(dirs) => git::sparse_checkout_set(&full_path,dirs),
None=>git::sparse_checkout_disable(&full_path)
}
}

fn exec_init(
Expand Down Expand Up @@ -420,7 +425,9 @@ fn exec_reset(
ResetType::Mixed => "--mixed",
ResetType::Hard => "--hard",
};
git::reset(full_path, reset_type, remote_ref_str)

git::reset(&full_path, reset_type, remote_ref_str)

}

fn exec_stash(
Expand Down

0 comments on commit 70559d2

Please sign in to comment.