修复git仓库初始化功能
This commit is contained in:
@@ -432,15 +432,31 @@ pub async fn get_git_branch(path: String) -> Result<Option<String>, AppCommandEr
|
|||||||
.await
|
.await
|
||||||
.map_err(AppCommandError::io)?;
|
.map_err(AppCommandError::io)?;
|
||||||
|
|
||||||
if !output.status.success() {
|
if output.status.success() {
|
||||||
return Ok(None);
|
let branch = String::from_utf8_lossy(&output.stdout).trim().to_string();
|
||||||
|
if !branch.is_empty() && branch != "HEAD" {
|
||||||
|
return Ok(Some(branch));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let branch = String::from_utf8_lossy(&output.stdout).trim().to_string();
|
// Fallback: symbolic-ref works on unborn branches (after git init, before first commit)
|
||||||
if branch.is_empty() || branch == "HEAD" {
|
let sym_output = crate::process::tokio_command("git")
|
||||||
return Ok(None);
|
.args(["symbolic-ref", "--short", "HEAD"])
|
||||||
|
.current_dir(&path)
|
||||||
|
.output()
|
||||||
|
.await
|
||||||
|
.map_err(AppCommandError::io)?;
|
||||||
|
|
||||||
|
if sym_output.status.success() {
|
||||||
|
let branch = String::from_utf8_lossy(&sym_output.stdout)
|
||||||
|
.trim()
|
||||||
|
.to_string();
|
||||||
|
if !branch.is_empty() {
|
||||||
|
return Ok(Some(branch));
|
||||||
}
|
}
|
||||||
Ok(Some(branch))
|
}
|
||||||
|
|
||||||
|
Ok(None)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
|
|||||||
Reference in New Issue
Block a user