mod constructors;
mod helpers;
mod methods;
mod traits;
use std::path::PathBuf;
use crate::services::file_watcher::{FileWatcher, WatchConfig, WatchMode};
use crate::services::git_watcher::{GitWatchConfig, GitWatcher};
#[derive(Debug, Clone)]
pub struct RepoWatchConfig {
pub git: GitWatchConfig,
pub files: WatchConfig,
pub include_untracked: bool,
}
impl Default for RepoWatchConfig {
fn default() -> Self {
Self {
git: GitWatchConfig::default(),
files: WatchConfig {
mode: WatchMode::Recursive,
debounce_ms: 200,
},
include_untracked: true,
}
}
}
impl RepoWatchConfig {
pub fn new() -> Self {
Self::default()
}
pub fn git_config(mut self, config: GitWatchConfig) -> Self {
self.git = config;
self
}
pub fn file_config(mut self, config: WatchConfig) -> Self {
self.files = config;
self
}
pub fn include_untracked(mut self, include: bool) -> Self {
self.include_untracked = include;
self
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum GitFileStatus {
Added,
Modified,
Deleted,
Renamed,
Untracked,
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct GitChangeSet {
pub added: Vec<PathBuf>,
pub modified: Vec<PathBuf>,
pub deleted: Vec<PathBuf>,
pub renamed: Vec<PathBuf>,
pub untracked: Vec<PathBuf>,
}
impl GitChangeSet {
pub fn is_empty(&self) -> bool {
self.added.is_empty()
&& self.modified.is_empty()
&& self.deleted.is_empty()
&& self.renamed.is_empty()
&& self.untracked.is_empty()
}
pub fn all_paths(&self) -> Vec<PathBuf> {
let mut paths = Vec::new();
paths.extend(self.added.iter().cloned());
paths.extend(self.modified.iter().cloned());
paths.extend(self.deleted.iter().cloned());
paths.extend(self.renamed.iter().cloned());
paths.extend(self.untracked.iter().cloned());
paths
}
}
pub struct RepoWatcher {
pub(crate) git_watcher: GitWatcher,
pub(crate) file_watcher: FileWatcher,
pub(crate) config: RepoWatchConfig,
pub(crate) repo_path: Option<PathBuf>,
pub(crate) change_set: GitChangeSet,
pub(crate) has_pending_changes: bool,
}