fix looking for git dir
This commit is contained in:
parent
815508b9e9
commit
dba911d2ae
|
|
@ -106,7 +106,6 @@ impl UnityProject {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_info(&mut self) {
|
pub fn update_info(&mut self) {
|
||||||
const HEAD_PREFIX: &str = "ref: refs/heads/";
|
|
||||||
|
|
||||||
let is_project = UnityProject::is_project_at_path(&self.path);
|
let is_project = UnityProject::is_project_at_path(&self.path);
|
||||||
self.is_valid = is_project;
|
self.is_valid = is_project;
|
||||||
|
|
@ -116,24 +115,41 @@ impl UnityProject {
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut base_path = Path::new(&self.path);
|
let mut base_path = Path::new(&self.path);
|
||||||
self.version = Self::get_version_at_path(&self.path).unwrap();
|
self.version = Self::get_version_at_path(&self.path).unwrap();
|
||||||
|
|
||||||
|
|
||||||
while let Some(path) = base_path.parent() {
|
match self.try_read_from_path(base_path) {
|
||||||
base_path = path;
|
None => {
|
||||||
let head_path = Path::new(&path).join(".git").join("HEAD");
|
while let Some(path) = base_path.parent() {
|
||||||
if !head_path.exists() {
|
base_path = path;
|
||||||
continue;
|
let new_branch = self.try_read_from_path(base_path);
|
||||||
}
|
if new_branch.is_some() {
|
||||||
let head_content =
|
self.branch = new_branch.unwrap();
|
||||||
std::fs::read_to_string(&head_path).expect("Could not read HEAD file");
|
break;
|
||||||
if head_content.contains(HEAD_PREFIX) {
|
}
|
||||||
self.branch = head_content.replace(HEAD_PREFIX, "").trim().to_string();
|
}
|
||||||
}
|
}
|
||||||
|
Some(value) => {
|
||||||
|
self.branch = value;
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Ok(meta) = std::fs::metadata(&self.path) {
|
if let Ok(meta) = std::fs::metadata(&self.path) {
|
||||||
if let Ok(data) = meta.modified() {
|
if let Ok(data) = meta.modified() {
|
||||||
self.edit_time = data;
|
self.edit_time = data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn try_read_from_path(&self, path: &std::path::Path) -> Option<String> {
|
||||||
|
const HEAD_PREFIX: &str = "ref: refs/heads/";
|
||||||
|
|
||||||
|
let head_path = Path::new(&path).join(".git").join("HEAD");
|
||||||
|
if !head_path.exists() { return None;}
|
||||||
|
let head_content =
|
||||||
|
std::fs::read_to_string(&head_path).expect("Could not read HEAD file");
|
||||||
|
if head_content.contains(HEAD_PREFIX) {
|
||||||
|
Some(head_content.replace(HEAD_PREFIX, "").trim().to_string())
|
||||||
|
} else {None}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue