Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,34 @@ jobs:
- run: cargo run -p systest
- run: cargo run -p systest --features unstable-sha256

clippy:
name: Clippy
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
build: [stable, beta, windows]
include:
- build: stable
os: ubuntu-latest
rust: stable
- build: beta
os: ubuntu-latest
rust: beta
- build: windows
os: windows-2022
rust: stable
steps:
- uses: actions/checkout@master
with:
submodules: true
- name: Install Rust (rustup)
run: rustup update ${{ matrix.rust }} --no-self-update && rustup default ${{ matrix.rust }}
shell: bash
- name: Install Clippy (rustup)
run: rustup component add clippy
- run: cargo clippy --all-targets --all-features -- -Dwarnings

rustfmt:
name: Rustfmt
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions examples/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#![deny(warnings)]
#![allow(trivial_casts)]
#![allow(clippy::needless_borrows_for_generic_args)]

use clap::Parser;
use git2::Repository;
Expand Down
2 changes: 2 additions & 0 deletions examples/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
*/

#![deny(warnings)]
#![allow(clippy::explicit_auto_deref)]
#![allow(clippy::manual_checked_ops)]

use clap::Parser;
use git2::build::{CheckoutBuilder, RepoBuilder};
Expand Down
3 changes: 3 additions & 0 deletions examples/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
*/

#![deny(warnings)]
#![allow(clippy::explicit_auto_deref)]
#![allow(clippy::needless_borrows_for_generic_args)]
#![allow(clippy::redundant_closure)]

use clap::Parser;
use git2::{Blob, Diff, DiffOptions, Error, Object, ObjectType, Oid, Repository};
Expand Down
1 change: 1 addition & 0 deletions examples/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/

#![deny(warnings)]
#![allow(clippy::manual_strip)]

use clap::Parser;
use git2::ObjectFormat;
Expand Down
2 changes: 2 additions & 0 deletions examples/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
*/

#![deny(warnings)]
#![allow(clippy::manual_strip)]
#![allow(clippy::needless_borrowed_reference)]

use clap::Parser;
use git2::{Commit, DiffOptions, ObjectType, Repository, Signature, Time};
Expand Down
3 changes: 3 additions & 0 deletions examples/pull.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
* <http://creativecommons.org/publicdomain/zero/1.0/>.
*/

#![allow(clippy::needless_borrow)]
#![allow(clippy::needless_question_mark)]

use clap::Parser;
use git2::Repository;
use std::io::{self, Write};
Expand Down
1 change: 1 addition & 0 deletions examples/rev-list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/

#![deny(warnings)]
#![allow(clippy::manual_strip)]

use clap::Parser;
use git2::{Error, Oid, Repository, Revwalk};
Expand Down
1 change: 1 addition & 0 deletions examples/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/

#![deny(warnings)]
#![allow(clippy::explicit_auto_deref)]

use clap::Parser;
use git2::{Commit, Error, Repository, Tag};
Expand Down
3 changes: 3 additions & 0 deletions libgit2-sys/build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#![allow(clippy::needless_borrows_for_generic_args)]
#![allow(clippy::unnecessary_map_or)]

use std::env;
use std::fs;
use std::io;
Expand Down
1 change: 1 addition & 0 deletions libgit2-sys/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![doc(html_root_url = "https://docs.rs/libgit2-sys/0.18")]
#![allow(non_camel_case_types, unused_extern_crates)]
#![allow(clippy::legacy_numeric_constants)]

// This is required to link libz when libssh2-sys is not included.
extern crate libz_sys as libz;
Expand Down
4 changes: 4 additions & 0 deletions src/apply.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
//! git_apply support
//! see original: <https://github.com/libgit2/libgit2/blob/master/include/git2/apply.h>

#![allow(clippy::missing_safety_doc)]
#![allow(clippy::new_without_default)]

use crate::{panic, raw, util::Binding, DiffDelta, DiffHunk};
use libc::c_int;
use std::{ffi::c_void, mem};
Expand Down Expand Up @@ -149,6 +152,7 @@ impl<'cb> ApplyOptions<'cb> {
}

#[cfg(test)]
#[allow(clippy::needless_borrows_for_generic_args)]
mod tests {
use super::*;
use std::{fs::File, io::Write, path::Path};
Expand Down
5 changes: 5 additions & 0 deletions src/blame.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::redundant_closure)]

use crate::util::{self, Binding};
use crate::{raw, signature, Error, Oid, Repository, Signature};
use libc::c_char;
Expand Down Expand Up @@ -388,6 +390,9 @@ impl<'blame> FusedIterator for BlameIter<'blame> {}
impl<'blame> ExactSizeIterator for BlameIter<'blame> {}

#[cfg(test)]
#[allow(clippy::bool_assert_comparison)]
#[allow(clippy::needless_borrow)]
#[allow(clippy::needless_borrows_for_generic_args)]
mod tests {
use std::fs::{self, File};
use std::path::Path;
Expand Down
2 changes: 2 additions & 0 deletions src/blob.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::io_other_error)]

use std::io;
use std::marker;
use std::mem;
Expand Down
2 changes: 2 additions & 0 deletions src/branch.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::missing_safety_doc)]

use std::ffi::CString;
use std::marker;
use std::ptr;
Expand Down
2 changes: 2 additions & 0 deletions src/buf.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::explicit_auto_deref)]

use std::ops::{Deref, DerefMut};
use std::ptr;
use std::slice;
Expand Down
5 changes: 5 additions & 0 deletions src/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
//! Builder-pattern objects for configuration various git operations.

#![allow(clippy::manual_non_exhaustive)]
#![allow(clippy::missing_safety_doc)]

use libc::{c_char, c_int, c_uint, c_void, size_t};
use std::ffi::{CStr, CString};
use std::mem;
Expand Down Expand Up @@ -767,6 +770,8 @@ impl TreeUpdateBuilder {
}

#[cfg(test)]
#[allow(clippy::needless_borrow)]

@weihanglo weihanglo Jun 15, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to add these allow to [lints.clippy] table?

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to make it clear where the existing violations were so that it would be clear what needs fixing, and so that we don't introduce more warnings in other files. If this is merged (or if you expect to merge this soon) I can start sending the PRs to fix the violations and remove the allowing

#[allow(clippy::needless_borrows_for_generic_args)]
mod tests {
use super::{CheckoutBuilder, RepoBuilder, TreeUpdateBuilder};
use crate::{CheckoutNotificationType, FileMode, Repository};
Expand Down
1 change: 1 addition & 0 deletions src/call.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(clippy::needless_lifetimes)]
#![macro_use]

use crate::Error;
Expand Down
2 changes: 2 additions & 0 deletions src/cherrypick.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::new_without_default)]

use std::mem;

use crate::build::CheckoutBuilder;
Expand Down
4 changes: 4 additions & 0 deletions src/commit.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::redundant_closure)]

use std::iter::FusedIterator;
use std::marker;
use std::mem;
Expand Down Expand Up @@ -413,6 +415,8 @@ impl<'repo> Drop for Commit<'repo> {
}

#[cfg(test)]
#[allow(clippy::bool_assert_comparison)]
#[allow(clippy::let_and_return)]
mod tests {
#[test]
fn smoke() {
Expand Down
3 changes: 3 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::should_implement_trait)]

use std::ffi::CString;
use std::marker;
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -639,6 +641,7 @@ impl<'cfg> Drop for ConfigEntry<'cfg> {
}

#[cfg(test)]
#[allow(clippy::bool_assert_comparison)]
mod tests {
use std::fs::File;
use tempfile::TempDir;
Expand Down
9 changes: 9 additions & 0 deletions src/cred.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
#![allow(clippy::manual_strip)]
#![allow(clippy::match_result_ok)]
#![allow(clippy::missing_safety_doc)]
#![allow(clippy::needless_borrowed_reference)]
#![allow(clippy::needless_borrows_for_generic_args)]
#![allow(clippy::should_implement_trait)]

#[cfg(feature = "cred")]
use log::{debug, trace};
use std::ffi::CString;
Expand Down Expand Up @@ -495,6 +502,8 @@ impl CredentialHelper {

#[cfg(test)]
#[cfg(feature = "cred")]
#[allow(clippy::unused_io_amount)]
#[allow(clippy::useless_conversion)]
mod test {
use std::env;
use std::fs::File;
Expand Down
7 changes: 7 additions & 0 deletions src/diff.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#![allow(clippy::empty_docs)]
#![allow(clippy::missing_safety_doc)]
#![allow(clippy::new_without_default)]

use libc::{c_char, c_int, c_void, size_t};
use std::ffi::CString;
use std::iter::FusedIterator;
Expand Down Expand Up @@ -1588,6 +1592,9 @@ impl DiffPatchidOptions {
}

#[cfg(test)]
#[allow(clippy::assign_op_pattern)]
#[allow(clippy::needless_borrows_for_generic_args)]
#[allow(clippy::while_let_on_iterator)]
mod tests {
#[cfg(feature = "unstable-sha256")]
use crate::Diff;
Expand Down
2 changes: 2 additions & 0 deletions src/email.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::too_many_arguments)]

use std::ffi::CString;
use std::{mem, ptr};

Expand Down
2 changes: 2 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::should_implement_trait)]

use libc::c_int;
use std::env::JoinPathsError;
use std::error;
Expand Down
2 changes: 2 additions & 0 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,8 @@ impl Binding for IndexEntry {
}

#[cfg(test)]
#[allow(clippy::needless_borrow)]
#[allow(clippy::needless_borrows_for_generic_args)]
mod tests {
use std::fs::{self, File};
use std::path::Path;
Expand Down
3 changes: 3 additions & 0 deletions src/indexer.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::io_other_error)]

use std::ffi::CStr;
use std::path::Path;
use std::{io, marker, mem, ptr};
Expand Down Expand Up @@ -242,6 +244,7 @@ impl Drop for Indexer<'_> {
}

#[cfg(test)]
#[allow(clippy::unused_io_amount)]
mod tests {
use crate::{Buf, Indexer};
use std::io::prelude::*;
Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@
#![deny(missing_docs)]
#![warn(rust_2018_idioms)]
#![cfg_attr(test, deny(warnings))]
#![allow(clippy::needless_lifetimes)]
#![allow(clippy::should_implement_trait)]
#![allow(clippy::unnecessary_cast)]

use bitflags::bitflags;
use libgit2_sys as raw;
Expand Down
1 change: 1 addition & 0 deletions src/mailmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ impl Mailmap {
}

#[cfg(test)]
#[allow(clippy::needless_borrow)]
mod tests {
use super::*;

Expand Down
3 changes: 3 additions & 0 deletions src/merge.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#![allow(clippy::missing_safety_doc)]
#![allow(clippy::redundant_closure)]

use libc::{c_char, c_uint, c_ushort, size_t};
use std::ffi::CString;
use std::marker;
Expand Down
5 changes: 5 additions & 0 deletions src/message.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#![allow(clippy::len_without_is_empty)]
#![allow(clippy::needless_borrow)]
#![allow(clippy::redundant_closure)]

use core::ops::Range;
use std::ffi::CStr;
use std::ffi::CString;
Expand Down Expand Up @@ -237,6 +241,7 @@ fn to_bytes_tuple(trailers: &MessageTrailers, index: usize) -> (&[u8], &[u8]) {
}

#[cfg(test)]
#[allow(clippy::char_lit_as_u8)]
mod tests {

#[test]
Expand Down
7 changes: 7 additions & 0 deletions src/odb.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#![allow(clippy::io_other_error)]
#![allow(clippy::len_without_is_empty)]
#![allow(clippy::single_match)]
#![allow(clippy::should_implement_trait)]

use std::io;
use std::marker;
use std::ptr;
Expand Down Expand Up @@ -579,6 +584,8 @@ pub(crate) extern "C" fn write_pack_progress_cb(
}

#[cfg(test)]
#[allow(clippy::bool_assert_comparison)]
#[allow(clippy::unused_io_amount)]
mod tests {
use crate::{Buf, ObjectType, Oid, Repository};
use std::io::prelude::*;
Expand Down
2 changes: 2 additions & 0 deletions src/oid_array.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Bindings to libgit2's raw `git_oidarray` type

#![allow(clippy::extra_unused_lifetimes)]

use std::ops::Deref;

use crate::oid::Oid;
Expand Down
2 changes: 2 additions & 0 deletions src/opts.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Bindings to libgit2's git_libgit2_opts function.

#![allow(clippy::missing_safety_doc)]

use std::ffi::CString;
use std::ptr;

Expand Down
3 changes: 3 additions & 0 deletions src/packbuilder.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::redundant_closure)]

use libc::{c_int, c_uint, c_void, size_t};
use std::marker;
use std::path::Path;
Expand Down Expand Up @@ -296,6 +298,7 @@ extern "C" fn progress_c(
}

#[cfg(test)]
#[allow(clippy::bool_assert_comparison)]
mod tests {
use crate::Buf;

Expand Down
1 change: 1 addition & 0 deletions src/pathspec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ impl<'list> FusedIterator for PathspecFailedEntries<'list> {}
impl<'list> ExactSizeIterator for PathspecFailedEntries<'list> {}

#[cfg(test)]
#[allow(clippy::needless_borrows_for_generic_args)]
mod tests {
use super::Pathspec;
use crate::PathspecFlags;
Expand Down
Loading