Skip to content

Commit

Permalink
check-shallow-before-unshallow-repos (#13)
Browse files Browse the repository at this point in the history
* check-shallow-before-unshallow

* 更改版本号
  • Loading branch information
fslongjin authored Sep 28, 2023
1 parent 09dd740 commit 2ebfffe
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "dadk"
authors = ["longjin <[email protected]>", "chikejian <[email protected]>"]
version = "0.1.2"
version = "0.1.3"
edition = "2021"
description = "DragonOS Application Development Kit\nDragonOS应用开发工具"
license = "GPL-2.0-only"
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2023-01-21"
channel = "nightly-2023-08-15"
components = ["rust-src"]
28 changes: 28 additions & 0 deletions src/executor/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ impl GitSource {
}
/// # 把浅克隆的仓库变成深克隆
fn unshallow(&self, target_dir: &CacheDir) -> Result<(), String> {
if self.is_shallow(target_dir)? == false {
return Ok(());
}

let mut cmd = Command::new("git");
cmd.current_dir(&target_dir.path);
cmd.arg("fetch").arg("--unshallow");
Expand All @@ -245,6 +249,30 @@ impl GitSource {
return Ok(());
}

/// 判断当前仓库是否是浅克隆
fn is_shallow(&self, target_dir: &CacheDir) -> Result<bool, String> {
let mut cmd = Command::new("git");
cmd.current_dir(&target_dir.path);
cmd.arg("rev-parse").arg("--is-shallow-repository");

let proc: std::process::Child = cmd
.stderr(Stdio::piped())
.spawn()
.map_err(|e| e.to_string())?;
let output = proc.wait_with_output().map_err(|e| e.to_string())?;

if !output.status.success() {
return Err(format!(
"Failed to check if shallow {}, message: {}",
target_dir.path.display(),
StdioUtils::tail_n_str(StdioUtils::stderr_to_lines(&output.stderr), 5)
));
}

let is_shallow = String::from_utf8_lossy(&output.stdout).trim() == "true";
return Ok(is_shallow);
}

fn fetch_all(&self, target_dir: &CacheDir) -> Result<(), String> {
self.set_fetch_config(target_dir)?;
let mut cmd = Command::new("git");
Expand Down

0 comments on commit 2ebfffe

Please sign in to comment.