Просмотр исходного кода

Add SubdirGitRepo::from_path() (#730)

	modified:   src/fs/feature/git.rs
alpn 5 лет назад
Родитель
Сommit
f931eecde0
1 измененных файлов с 24 добавлено и 0 удалено
  1. 24 0
      src/fs/feature/git.rs

+ 24 - 0
src/fs/feature/git.rs

@@ -311,3 +311,27 @@ fn index_status(status: git2::Status) -> f::GitStatus {
         _                                                => f::GitStatus::NotModified,
         _                                                => f::GitStatus::NotModified,
     }
     }
 }
 }
+
+impl f::SubdirGitRepo{
+    pub fn from_path(dir : &Path) -> Self{
+
+        let path = &reorient(&dir);
+        let g = git2::Repository::open(path);
+        if let Ok(repo) = g{
+
+            match repo.statuses(None) {
+                Ok(es) => {
+                    if es.iter().filter(|s| s.status() != git2::Status::IGNORED).count() > 0{
+                        return Self{status : f::SubdirGitRepoStatus::GitDirty};
+                    }
+                    return Self{status : f::SubdirGitRepoStatus::GitClean};
+                }
+                Err(e) => {
+                    error!("Error looking up Git statuses: {:?}", e)
+                }
+            }
+        }
+
+        Self{status : f::SubdirGitRepoStatus::NotRepo}
+    }
+}