mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-08-24 20:34:05 +02:00
Add live git status indicators (#458)
This commit is contained in:
@@ -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)?)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user