ratatui_toolkit/services/git_watcher/methods/
unwatch.rs

1//! Stop watching a git repository.
2
3use notify::Watcher;
4use std::path::Path;
5
6use crate::services::git_watcher::GitWatcher;
7
8impl GitWatcher {
9    /// Stop watching a git repository.
10    ///
11    /// # Arguments
12    ///
13    /// * `repo_path` - Path to the repository root (where `.git` is located).
14    ///
15    /// # Errors
16    ///
17    /// Returns a `notify::Error` if the path cannot be unwatched.
18    ///
19    /// # Example
20    ///
21    /// ```no_run
22    /// use ratatui_toolkit::services::git_watcher::GitWatcher;
23    /// use std::path::Path;
24    ///
25    /// let mut watcher = GitWatcher::new().unwrap();
26    /// let path = Path::new("/path/to/repo");
27    /// watcher.watch(path).unwrap();
28    /// // Later...
29    /// watcher.unwatch(path).unwrap();
30    /// ```
31    pub fn unwatch(&mut self, repo_path: &Path) -> Result<(), notify::Error> {
32        let git_dir = repo_path.join(".git");
33        self.watcher.unwatch(&git_dir)?;
34        self.repo_path = None;
35        self.has_pending_changes = false;
36        Ok(())
37    }
38}