Skip to content

Commit 73092be

Browse files
authored
Enable clippy and fmt (#17)
1 parent 23a1bd1 commit 73092be

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

.github/workflows/rust.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,14 @@ jobs:
2020
steps:
2121
- uses: actions/checkout@v4
2222
- name: Install Rust
23-
uses: dtolnay/rust-toolchain@stable
23+
uses: dtolnay/rust-toolchain@master
2424
with:
2525
toolchain: ${{ matrix.rustv }}
26-
override: true
26+
components: clippy, rustfmt
2727
- uses: swatinem/rust-cache@v2
2828
- name: Test
2929
run: cargo test
30+
- name: Clippy
31+
run: cargo clippy -- -Dwarnings
32+
- name: fmt
33+
run: cargo fmt --check

src/lib.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ pub fn rebase_onto(onto: &str) -> Result<(), anyhow::Error> {
3737
let repo = Repository::open(".")?;
3838
let onto = repo
3939
.reference_to_annotated_commit(
40-
&repo
41-
.find_branch(onto, git2::BranchType::Local)
40+
repo.find_branch(onto, git2::BranchType::Local)
4241
.context("Chosing parent")?
4342
.get(),
4443
)
@@ -50,7 +49,7 @@ pub fn rebase_onto(onto: &str) -> Result<(), anyhow::Error> {
5049
.rebase(Some(&head), None, Some(&onto), None)
5150
.context("creating rebase")?;
5251

53-
if let Ok(_) = do_rebase_inner(&repo, rebase, None) {
52+
if do_rebase_inner(&repo, rebase, None).is_ok() {
5453
rebase.finish(None).context("finishing")?;
5554
}
5655

@@ -169,7 +168,7 @@ fn do_rebase_inner(
169168
fn commit_parent<'a>(commit: &'a Commit) -> Result<Commit<'a>, anyhow::Error> {
170169
match commit.parents().next() {
171170
Some(c) => Ok(c),
172-
None => bail!("Commit '{}' has no parents", disp(&commit)),
171+
None => bail!("Commit '{}' has no parents", disp(commit)),
173172
}
174173
}
175174

@@ -198,12 +197,10 @@ fn get_upstream<'a>(
198197
})
199198
.ok_or_else(|| anyhow!("cannot find branch with name {:?}", upstream_name))?;
200199
branch.into_reference().peel(ObjectType::Commit)?
200+
} else if let Ok(upstream) = head_branch.upstream() {
201+
upstream.into_reference().peel(ObjectType::Commit)?
201202
} else {
202-
if let Ok(upstream) = head_branch.upstream() {
203-
upstream.into_reference().peel(ObjectType::Commit)?
204-
} else {
205-
return Ok(None);
206-
}
203+
return Ok(None);
207204
};
208205

209206
let mb = repo.merge_base(
@@ -282,19 +279,19 @@ fn select_commit_to_amend<'a>(
282279
let commits = if let Some(upstream) = upstream.as_ref() {
283280
let upstream_oid = upstream.id();
284281
walker
285-
.flat_map(|r| r)
282+
.flatten()
286283
.take_while(|rev| *rev != upstream_oid)
287284
.take(max_commits)
288285
.map(|rev| repo.find_commit(rev))
289286
.collect::<Result<Vec<_>, _>>()?
290287
} else {
291288
walker
292-
.flat_map(|r| r)
289+
.flatten()
293290
.take(max_commits)
294291
.map(|rev| repo.find_commit(rev))
295292
.collect::<Result<Vec<_>, _>>()?
296293
};
297-
if commits.len() == 0 {
294+
if commits.is_empty() {
298295
bail!(
299296
"No commits between {} and {:?}",
300297
format_ref(&repo.head()?)?,
@@ -330,7 +327,7 @@ fn select_commit_to_amend<'a>(
330327
branches
331328
.get(&commit.id())
332329
.map(|n| format!("({}) ", n))
333-
.unwrap_or_else(String::new)
330+
.unwrap_or_default()
334331
} else {
335332
String::new()
336333
};

0 commit comments

Comments
 (0)