Skip to content

Commit b8f6bcf

Browse files
committed
fix: Address clippy issues
1 parent f2ea473 commit b8f6bcf

File tree

6 files changed

+31
-25
lines changed

6 files changed

+31
-25
lines changed

src/main.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use git2::{
1313
};
1414
use rand::Rng;
1515
use regex::Regex;
16-
use serde_json;
1716

1817
// Merge options types
1918
#[derive(Debug, PartialEq, Clone, Copy)]
@@ -2297,7 +2296,7 @@ impl GitChain {
22972296
serde_json::from_str(&stdout).unwrap_or_default();
22982297
if !pr_objects.is_empty() {
22992298
if let Some(pr_url) = pr_objects
2300-
.get(0)
2299+
.first()
23012300
.and_then(|pr| pr.get("url"))
23022301
.and_then(|url| url.as_str())
23032302
{
@@ -2385,7 +2384,7 @@ impl GitChain {
23852384
// If draft mode, open the PR in browser separately
23862385
if draft {
23872386
let pr_url = String::from_utf8_lossy(&output.stdout).trim().to_string();
2388-
if let Some(pr_number) = pr_url.split('/').last() {
2387+
if let Some(pr_number) = pr_url.split('/').next_back() {
23892388
let browse_output =
23902389
Command::new("gh").arg("browse").arg(pr_number).output();
23912390

tests/backup.rs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,14 @@ fn backup_subcommand() {
108108
let args: Vec<&str> = vec!["init", "chain_name_2"];
109109
run_test_bin_expect_ok(&path_to_repo, args);
110110

111-
assert_eq!(
112-
branch_exists(&repo, &backup_name("chain_name_2", "some_branch_2")),
113-
false
114-
);
115-
assert_eq!(
116-
branch_exists(&repo, &backup_name("chain_name_2", "some_branch_3")),
117-
false
118-
);
111+
assert!(!branch_exists(
112+
&repo,
113+
&backup_name("chain_name_2", "some_branch_2")
114+
));
115+
assert!(!branch_exists(
116+
&repo,
117+
&backup_name("chain_name_2", "some_branch_3")
118+
));
119119

120120
let args: Vec<&str> = vec!["backup"];
121121
let output = run_test_bin_expect_ok(&path_to_repo, args);
@@ -156,13 +156,11 @@ fn backup_subcommand() {
156156
commit_all(&repo, "message");
157157
};
158158

159-
assert!(
160-
branch_equal(
161-
&repo,
162-
"some_branch_3",
163-
&backup_name("chain_name_2", "some_branch_3")
164-
) == false
165-
);
159+
assert!(!branch_equal(
160+
&repo,
161+
"some_branch_3",
162+
&backup_name("chain_name_2", "some_branch_3")
163+
));
166164

167165
let args: Vec<&str> = vec!["backup"];
168166
let output = run_test_bin_expect_ok(&path_to_repo, args);

tests/common/mod.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ where
1818
path_to_repo
1919
}
2020

21+
#[allow(dead_code)]
2122
pub fn generate_path_to_bare_repo<S>(repo_name: S) -> PathBuf
2223
where
2324
S: Into<String>,
@@ -47,6 +48,7 @@ where
4748
repo
4849
}
4950

51+
#[allow(dead_code)]
5052
pub fn setup_git_bare_repo<S>(repo_name: S) -> Repository
5153
where
5254
S: Into<String>,
@@ -72,6 +74,7 @@ where
7274
fs::remove_dir_all(&path_to_repo).ok();
7375
}
7476

77+
#[allow(dead_code)]
7578
pub fn teardown_git_bare_repo<S>(repo_name: S)
7679
where
7780
S: Into<String>,
@@ -99,11 +102,13 @@ pub fn checkout_branch(repo: &Repository, branch_name: &str) {
99102
.unwrap();
100103
}
101104

105+
#[allow(dead_code)]
102106
pub fn branch_exists(repo: &Repository, branch_name: &str) -> bool {
103107
repo.revparse_single(&("refs/heads/".to_owned() + branch_name))
104108
.is_ok()
105109
}
106110

111+
#[allow(dead_code)]
107112
pub fn branch_equal(repo: &Repository, branch_name: &str, other_branch: &str) -> bool {
108113
let obj = repo
109114
.revparse_single(&format!("{}^{{commit}}", branch_name))
@@ -169,6 +174,7 @@ pub fn commit_all(repo: &Repository, message: &str) {
169174
create_commit(repo, root_tree_oid, message);
170175
}
171176

177+
#[allow(dead_code)]
172178
pub fn delete_local_branch(repo: &Repository, branch_name: &str) {
173179
let mut some_branch = repo.find_branch(branch_name, BranchType::Local).unwrap();
174180

@@ -178,6 +184,7 @@ pub fn delete_local_branch(repo: &Repository, branch_name: &str) {
178184
some_branch.delete().unwrap();
179185
}
180186

187+
#[allow(dead_code)]
181188
pub fn get_current_branch_name(repo: &Repository) -> String {
182189
let head = repo.head().unwrap();
183190
head.shorthand().unwrap().to_string()
@@ -194,9 +201,9 @@ pub fn create_new_file(path_to_repo: &Path, file_name: &str, file_contents: &str
194201
writeln!(file, "{}", file_contents).unwrap();
195202
}
196203

204+
#[allow(dead_code)]
197205
pub fn append_file(path_to_repo: &Path, file_name: &str, file_contents: &str) {
198206
let mut file = OpenOptions::new()
199-
.write(true)
200207
.append(true)
201208
.open(path_to_repo.join(file_name))
202209
.unwrap();
@@ -222,6 +229,7 @@ where
222229
.expect("Failed to run git-chain")
223230
}
224231

232+
#[allow(dead_code)]
225233
pub fn run_test_bin_expect_err<I, T, P: AsRef<Path>>(current_dir: P, arguments: I) -> Output
226234
where
227235
I: IntoIterator<Item = T>,
@@ -257,11 +265,13 @@ where
257265
output
258266
}
259267

268+
#[allow(dead_code)]
260269
pub fn display_outputs(output: &Output) {
261270
io::stdout().write_all(&output.stdout).unwrap();
262271
io::stderr().write_all(&output.stderr).unwrap();
263272
}
264273

274+
#[allow(dead_code)]
265275
pub fn run_git_command<I, T, P: AsRef<Path>>(current_dir: P, arguments: I) -> Output
266276
where
267277
I: IntoIterator<Item = T>,
@@ -281,6 +291,7 @@ where
281291
output
282292
}
283293

294+
#[allow(dead_code)]
284295
pub fn run_test_bin_for_rebase<I, T, P: AsRef<Path>>(current_dir: P, arguments: I) -> Output
285296
where
286297
I: IntoIterator<Item = T>,

tests/init.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ chain_name
9797
let count = {
9898
let mut iter = local_config.entries(Some(&config_chain_name)).unwrap();
9999
let mut count = 0;
100-
while let Some(_) = iter.next() {
100+
while iter.next().is_some() {
101101
count += 1;
102102
}
103103
count
@@ -113,7 +113,7 @@ chain_name
113113
let count = {
114114
let mut iter = local_config.entries(Some(&config_chain_order)).unwrap();
115115
let mut count = 0;
116-
while let Some(_) = iter.next() {
116+
while iter.next().is_some() {
117117
count += 1;
118118
}
119119
count
@@ -131,7 +131,7 @@ chain_name
131131
let count = {
132132
let mut iter = local_config.entries(Some(&config_root_branch)).unwrap();
133133
let mut count = 0;
134-
while let Some(_) = iter.next() {
134+
while iter.next().is_some() {
135135
count += 1;
136136
}
137137
count

tests/merge.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6827,7 +6827,7 @@ fn merge_subcommand_complex_conflicts() {
68276827
);
68286828

68296829
// Rather than asserting on a specific branch, verify it's a valid branch in our chain
6830-
let valid_chain_branches = vec!["master", "feature_1", "feature_2"];
6830+
let valid_chain_branches = ["master", "feature_1", "feature_2"];
68316831
let is_valid_chain_branch = valid_chain_branches.contains(&branch_after_abort.as_str());
68326832
assert!(
68336833
is_valid_chain_branch,

tests/rebase.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use console;
2-
31
use git2::RepositoryState;
42

53
#[path = "common/mod.rs"]

0 commit comments

Comments
 (0)