From 6da0b219dde83df0fea2e4e01929ac1c9e82ecff Mon Sep 17 00:00:00 2001 From: Boshen <1430279+Boshen@users.noreply.github.com> Date: Wed, 18 Dec 2024 08:41:50 +0000 Subject: [PATCH] refactor(oxlint): remove unused `git.rs` (#7990) --- apps/oxlint/src/git.rs | 54 ------------------------------------------ 1 file changed, 54 deletions(-) delete mode 100644 apps/oxlint/src/git.rs diff --git a/apps/oxlint/src/git.rs b/apps/oxlint/src/git.rs deleted file mode 100644 index 6b126c221d2b9..0000000000000 --- a/apps/oxlint/src/git.rs +++ /dev/null @@ -1,54 +0,0 @@ -use std::path::Path; - -use git2::Repository; - -use oxc_diagnostics::{LabeledSpan, OxcDiagnostic}; - -pub struct Git<'a> { - // paths: &'a Vec>, - repos: Vec, -} - -impl<'a> Git<'a> { - pub fn new() -> Self { - // let repos: Vec = - // paths.iter().filter_map(|path| Repository::discover(path).ok()).collect(); - Self { repos } - } - - pub fn verify(&'a self) -> Result<&'a Repository, Error> { - if self.repos.is_empty() { - return Err(OxcDiagnostic::warning("No repository found")) - .with_help("Ensure target path(s) belong to a Git repository"); - } - match self.is_same_repo() { - Ok(repo) => { - for path in self.paths { - if Self::is_uncommitted(repo, path) { - return Err(OxcDiagnostic::warning("Uncommitted changes") - .with_help("Commit any changes before linting")); - } - } - Ok(repo) - } - err => err, - } - } - - /// Given a list of repositories, verify they're all the same repository. - fn is_same_repo(&self) -> Result<&Repository, Error> { - assert!(!self.repos.is_empty()); - let first_repo = self.repos.first().unwrap(); - for repo in &self.repos[1..] { - if repo.path() != first_repo.path() { - return Err(OxcDiagnostic::warning("Multiple repositories found") - .with_help("Ensure all paths belong to a single repository")); - } - } - Ok(first_repo) - } - - fn is_uncommitted(repo: &Repository, path: &Path) -> bool { - repo.status_file(path).map_or(true, |status| !matches!(status, git2::Status::CURRENT)) - } -}