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