Skip to content

Commit 2ebfffe

Browse files
authored
check-shallow-before-unshallow-repos (#13)
* check-shallow-before-unshallow * 更改版本号
1 parent 09dd740 commit 2ebfffe

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "dadk"
33
authors = ["longjin <longjin@DragonOS.org>", "chikejian <chikejian@DragonOS.org>"]
4-
version = "0.1.2"
4+
version = "0.1.3"
55
edition = "2021"
66
description = "DragonOS Application Development Kit\nDragonOS应用开发工具"
77
license = "GPL-2.0-only"

rust-toolchain.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "nightly-2023-01-21"
2+
channel = "nightly-2023-08-15"
33
components = ["rust-src"]

src/executor/source.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,10 @@ impl GitSource {
222222
}
223223
/// # 把浅克隆的仓库变成深克隆
224224
fn unshallow(&self, target_dir: &CacheDir) -> Result<(), String> {
225+
if self.is_shallow(target_dir)? == false {
226+
return Ok(());
227+
}
228+
225229
let mut cmd = Command::new("git");
226230
cmd.current_dir(&target_dir.path);
227231
cmd.arg("fetch").arg("--unshallow");
@@ -245,6 +249,30 @@ impl GitSource {
245249
return Ok(());
246250
}
247251

252+
/// 判断当前仓库是否是浅克隆
253+
fn is_shallow(&self, target_dir: &CacheDir) -> Result<bool, String> {
254+
let mut cmd = Command::new("git");
255+
cmd.current_dir(&target_dir.path);
256+
cmd.arg("rev-parse").arg("--is-shallow-repository");
257+
258+
let proc: std::process::Child = cmd
259+
.stderr(Stdio::piped())
260+
.spawn()
261+
.map_err(|e| e.to_string())?;
262+
let output = proc.wait_with_output().map_err(|e| e.to_string())?;
263+
264+
if !output.status.success() {
265+
return Err(format!(
266+
"Failed to check if shallow {}, message: {}",
267+
target_dir.path.display(),
268+
StdioUtils::tail_n_str(StdioUtils::stderr_to_lines(&output.stderr), 5)
269+
));
270+
}
271+
272+
let is_shallow = String::from_utf8_lossy(&output.stdout).trim() == "true";
273+
return Ok(is_shallow);
274+
}
275+
248276
fn fetch_all(&self, target_dir: &CacheDir) -> Result<(), String> {
249277
self.set_fetch_config(target_dir)?;
250278
let mut cmd = Command::new("git");

0 commit comments

Comments
 (0)