Skip to content

Commit 2227eb3

Browse files
committed
Reenable the unused lint, and cleanup unused
1 parent a2f99b7 commit 2227eb3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+222
-288
lines changed

src/application.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ mod tests {
194194
use super::*;
195195
use crate::{
196196
display::Size,
197-
input::{Event, KeyCode, KeyEvent, KeyModifiers},
197+
input::{KeyCode, KeyEvent, KeyModifiers},
198198
module::Modules,
199199
runtime::{Installer, RuntimeError},
200200
test_helpers::{

src/components/choice/tests.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
use rstest::rstest;
22

33
use super::*;
4-
use crate::{
5-
assert_rendered_output,
6-
input::StandardEvent,
7-
test_helpers::{assertions::assert_rendered_output::AssertRenderOptions, with_view_state},
8-
};
4+
use crate::{assert_rendered_output, input::StandardEvent, test_helpers::with_view_state};
95

106
#[derive(Clone, Debug, PartialEq)]
117
enum TestAction {

src/components/search_bar/tests.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
use claims::{assert_none, assert_some_eq};
22

33
use super::*;
4-
use crate::{assert_rendered_output, view::ViewData};
4+
use crate::{
5+
assert_rendered_output,
6+
test_helpers::assertions::assert_rendered_output::AssertRenderOptions,
7+
view::ViewData,
8+
};
59

610
fn create_view_data(search_bar: &SearchBar) -> ViewData {
711
let view_line = search_bar.build_view_line();

src/config/theme.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ mod tests {
138138

139139
use super::*;
140140
use crate::{
141-
config::{ConfigErrorCause, InvalidColorError},
141+
config::InvalidColorError,
142142
test_helpers::{invalid_utf, with_git_config},
143143
};
144144

src/display.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![cfg_attr(test, allow(dead_code, unused_imports))]
12
//! Git Interactive Rebase Tool - Display Module
23
//!
34
//! # Description

src/git/errors.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use thiserror::Error;
1313
pub(crate) enum RepositoryLoadKind {
1414
/// Repository was loaded from the path provided through an environment variable
1515
Environment,
16+
#[cfg(test)]
1617
/// Repository was loaded from a direct path
1718
Path,
1819
}
@@ -21,6 +22,7 @@ impl Display for RepositoryLoadKind {
2122
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
2223
match *self {
2324
Self::Environment => write!(f, "environment"),
25+
#[cfg(test)]
2426
Self::Path => write!(f, "path"),
2527
}
2628
}
@@ -29,6 +31,7 @@ impl Display for RepositoryLoadKind {
2931
/// Git errors
3032
#[derive(Error, Debug, PartialEq)]
3133
#[non_exhaustive]
34+
#[allow(clippy::enum_variant_names)]
3235
pub(crate) enum GitError {
3336
/// The repository could not be loaded
3437
#[error("Could not open repository from {kind}")]
@@ -47,6 +50,7 @@ pub(crate) enum GitError {
4750
cause: git2::Error,
4851
},
4952
/// The configuration could not be loaded
53+
#[cfg(test)]
5054
#[error("Could not load configuration")]
5155
ReferenceNotFound {
5256
/// The internal cause of the load error.

src/git/repository.rs

Lines changed: 105 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,11 @@
11
use std::{
22
fmt::{Debug, Formatter},
3-
path::{Path, PathBuf},
43
sync::Arc,
54
};
65

7-
use git2::{Oid, Signature};
86
use parking_lot::Mutex;
97

10-
use crate::git::{
11-
Commit,
12-
CommitDiff,
13-
CommitDiffLoader,
14-
CommitDiffLoaderOptions,
15-
Config,
16-
GitError,
17-
Reference,
18-
RepositoryLoadKind,
19-
};
8+
use crate::git::{CommitDiff, CommitDiffLoader, CommitDiffLoaderOptions, Config, GitError, RepositoryLoadKind};
209

2110
/// A light cloneable, simple wrapper around the `git2::Repository` struct
2211
#[derive(Clone)]
@@ -43,22 +32,6 @@ impl Repository {
4332
})
4433
}
4534

46-
/// Attempt to open an already-existing repository at `path`.
47-
///
48-
/// # Errors
49-
/// Will result in an error if the repository cannot be opened.
50-
pub(crate) fn open_from_path(path: &Path) -> Result<Self, GitError> {
51-
let repository = git2::Repository::open(path).map_err(|e| {
52-
GitError::RepositoryLoad {
53-
kind: RepositoryLoadKind::Path,
54-
cause: e,
55-
}
56-
})?;
57-
Ok(Self {
58-
repository: Arc::new(Mutex::new(repository)),
59-
})
60-
}
61-
6235
/// Load the git configuration for the repository.
6336
///
6437
/// # Errors
@@ -93,78 +66,6 @@ impl Repository {
9366
.map_err(|e| GitError::CommitLoad { cause: e })?
9467
.remove(0))
9568
}
96-
97-
/// Find a reference by the reference name.
98-
///
99-
/// # Errors
100-
/// Will result in an error if the reference cannot be found.
101-
pub(crate) fn find_reference(&self, reference: &str) -> Result<Reference, GitError> {
102-
let repo = self.repository.lock();
103-
let git2_reference = repo
104-
.find_reference(reference)
105-
.map_err(|e| GitError::ReferenceNotFound { cause: e })?;
106-
Ok(Reference::from(&git2_reference))
107-
}
108-
109-
/// Find a commit by a reference name.
110-
///
111-
/// # Errors
112-
/// Will result in an error if the reference cannot be found or is not a commit.
113-
pub(crate) fn find_commit(&self, reference: &str) -> Result<Commit, GitError> {
114-
let repo = self.repository.lock();
115-
let git2_reference = repo
116-
.find_reference(reference)
117-
.map_err(|e| GitError::ReferenceNotFound { cause: e })?;
118-
Commit::try_from(&git2_reference)
119-
}
120-
121-
pub(crate) fn repo_path(&self) -> PathBuf {
122-
self.repository.lock().path().to_path_buf()
123-
}
124-
125-
pub(crate) fn head_id(&self, head_name: &str) -> Result<Oid, git2::Error> {
126-
let repo = self.repository.lock();
127-
let ref_name = format!("refs/heads/{head_name}");
128-
let revision = repo.revparse_single(ref_name.as_str())?;
129-
Ok(revision.id())
130-
}
131-
132-
pub(crate) fn commit_id_from_ref(&self, reference: &str) -> Result<Oid, git2::Error> {
133-
let repo = self.repository.lock();
134-
let commit = repo.find_reference(reference)?.peel_to_commit()?;
135-
Ok(commit.id())
136-
}
137-
138-
pub(crate) fn add_path_to_index(&self, path: &Path) -> Result<(), git2::Error> {
139-
let repo = self.repository.lock();
140-
let mut index = repo.index()?;
141-
index.add_path(path)
142-
}
143-
144-
pub(crate) fn remove_path_from_index(&self, path: &Path) -> Result<(), git2::Error> {
145-
let repo = self.repository.lock();
146-
let mut index = repo.index()?;
147-
index.remove_path(path)
148-
}
149-
150-
pub(crate) fn create_commit_on_index(
151-
&self,
152-
reference: &str,
153-
author: &Signature<'_>,
154-
committer: &Signature<'_>,
155-
message: &str,
156-
) -> Result<(), git2::Error> {
157-
let repo = self.repository.lock();
158-
let tree = repo.find_tree(repo.index()?.write_tree()?)?;
159-
let head = repo.find_reference(reference)?.peel_to_commit()?;
160-
_ = repo.commit(Some("HEAD"), author, committer, message, &tree, &[&head])?;
161-
Ok(())
162-
}
163-
164-
#[cfg(test)]
165-
pub(crate) fn repository(&self) -> Arc<Mutex<git2::Repository>> {
166-
Arc::clone(&self.repository)
167-
}
16869
}
16970

17071
impl From<git2::Repository> for Repository {
@@ -183,10 +84,112 @@ impl Debug for Repository {
18384
}
18485
}
18586

87+
#[cfg(test)]
88+
mod tests {
89+
use std::{
90+
path::{Path, PathBuf},
91+
sync::Arc,
92+
};
93+
94+
use git2::{Oid, Signature};
95+
use parking_lot::Mutex;
96+
97+
use crate::git::{Commit, GitError, Reference, Repository, RepositoryLoadKind};
98+
99+
impl Repository {
100+
/// Attempt to open an already-existing repository at `path`.
101+
///
102+
/// # Errors
103+
/// Will result in an error if the repository cannot be opened.
104+
pub(crate) fn open_from_path(path: &Path) -> Result<Self, GitError> {
105+
let repository = git2::Repository::open(path).map_err(|e| {
106+
GitError::RepositoryLoad {
107+
kind: RepositoryLoadKind::Path,
108+
cause: e,
109+
}
110+
})?;
111+
Ok(Self {
112+
repository: Arc::new(Mutex::new(repository)),
113+
})
114+
}
115+
116+
/// Find a reference by the reference name.
117+
///
118+
/// # Errors
119+
/// Will result in an error if the reference cannot be found.
120+
pub(crate) fn find_reference(&self, reference: &str) -> Result<Reference, GitError> {
121+
let repo = self.repository.lock();
122+
let git2_reference = repo
123+
.find_reference(reference)
124+
.map_err(|e| GitError::ReferenceNotFound { cause: e })?;
125+
Ok(Reference::from(&git2_reference))
126+
}
127+
128+
/// Find a commit by a reference name.
129+
///
130+
/// # Errors
131+
/// Will result in an error if the reference cannot be found or is not a commit.
132+
pub(crate) fn find_commit(&self, reference: &str) -> Result<Commit, GitError> {
133+
let repo = self.repository.lock();
134+
let git2_reference = repo
135+
.find_reference(reference)
136+
.map_err(|e| GitError::ReferenceNotFound { cause: e })?;
137+
Commit::try_from(&git2_reference)
138+
}
139+
140+
pub(crate) fn repo_path(&self) -> PathBuf {
141+
self.repository.lock().path().to_path_buf()
142+
}
143+
144+
pub(crate) fn head_id(&self, head_name: &str) -> Result<Oid, git2::Error> {
145+
let repo = self.repository.lock();
146+
let ref_name = format!("refs/heads/{head_name}");
147+
let revision = repo.revparse_single(ref_name.as_str())?;
148+
Ok(revision.id())
149+
}
150+
151+
pub(crate) fn commit_id_from_ref(&self, reference: &str) -> Result<Oid, git2::Error> {
152+
let repo = self.repository.lock();
153+
let commit = repo.find_reference(reference)?.peel_to_commit()?;
154+
Ok(commit.id())
155+
}
156+
157+
pub(crate) fn add_path_to_index(&self, path: &Path) -> Result<(), git2::Error> {
158+
let repo = self.repository.lock();
159+
let mut index = repo.index()?;
160+
index.add_path(path)
161+
}
162+
163+
pub(crate) fn remove_path_from_index(&self, path: &Path) -> Result<(), git2::Error> {
164+
let repo = self.repository.lock();
165+
let mut index = repo.index()?;
166+
index.remove_path(path)
167+
}
168+
169+
pub(crate) fn create_commit_on_index(
170+
&self,
171+
reference: &str,
172+
author: &Signature<'_>,
173+
committer: &Signature<'_>,
174+
message: &str,
175+
) -> Result<(), git2::Error> {
176+
let repo = self.repository.lock();
177+
let tree = repo.find_tree(repo.index()?.write_tree()?)?;
178+
let head = repo.find_reference(reference)?.peel_to_commit()?;
179+
_ = repo.commit(Some("HEAD"), author, committer, message, &tree, &[&head])?;
180+
Ok(())
181+
}
182+
183+
pub(crate) fn repository(&self) -> Arc<Mutex<git2::Repository>> {
184+
Arc::clone(&self.repository)
185+
}
186+
}
187+
}
188+
186189
// Paths in Windows makes these tests difficult, so disable
187190
#[cfg(all(unix, test))]
188-
mod tests {
189-
use std::env::set_var;
191+
mod unix_tests {
192+
use std::path::Path;
190193

191194
use claims::{assert_err_eq, assert_ok};
192195
use git2::{ErrorClass, ErrorCode};

src/input/event_provider.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ mod read_event_mocks {
7474
mod tests {
7575
use std::{io, io::ErrorKind};
7676

77-
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers, MouseButton};
77+
use crossterm::event::{KeyCode, KeyModifiers, MouseButton};
7878

7979
use super::*;
8080

src/input/standard_event.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#[derive(Debug, PartialOrd, PartialEq, Eq, Clone, Copy)]
33
#[non_exhaustive]
44
pub(crate) enum StandardEvent {
5+
#[allow(unused)]
56
/// The exit meta event.
67
Exit,
78
/// The kill meta event.

src/input/thread/state.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ mod tests {
122122
};
123123

124124
use super::*;
125-
use crate::input::Event;
126125

127126
fn create_state() -> State {
128127
State::new()

0 commit comments

Comments
 (0)