Add live git status indicators (#458)

This commit is contained in:
Gregory Schier
2026-05-08 11:25:39 -07:00
committed by GitHub
parent 1b154ba550
commit d7e67cf13c
35 changed files with 1702 additions and 578 deletions
+22 -1
View File
@@ -1,5 +1,12 @@
use crate::error::Error::{GitRepoNotFound, GitUnknown};
use std::path::Path;
use crate::error::{Error, Result};
use std::path::{Path, PathBuf};
#[derive(Debug, Clone)]
pub struct GitRepositoryPaths {
pub workdir: PathBuf,
pub gitdir: PathBuf,
}
pub(crate) fn open_repo(dir: &Path) -> crate::error::Result<git2::Repository> {
match git2::Repository::discover(dir) {
@@ -8,3 +15,17 @@ pub(crate) fn open_repo(dir: &Path) -> crate::error::Result<git2::Repository> {
Err(e) => Err(GitUnknown(e)),
}
}
pub fn git_repository_paths(dir: &Path) -> Result<GitRepositoryPaths> {
let repo = open_repo(dir)?;
let workdir = repo
.workdir()
.ok_or_else(|| Error::GenericError("Git repository does not have a worktree".into()))?
.to_path_buf();
Ok(GitRepositoryPaths { workdir, gitdir: repo.path().to_path_buf() })
}
pub fn git_path_is_ignored(dir: &Path, rela_path: &Path) -> Result<bool> {
let repo = open_repo(dir)?;
Ok(repo.status_should_ignore(rela_path)?)
}