diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 1b000ab..7b55a3d 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -24,4 +24,6 @@ jobs: steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 + with: + python-version: '3.x' - uses: pre-commit/action@v3.0.1 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a8d63e0..f57b7d7 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -45,7 +45,7 @@ We ask that commits are atomic, meaning they are complete and have a single resp PRs should tell a cohesive story, with test and refactor commits that keep the fix or feature commits simple and clear. -Specifically, we would encouage +Specifically, we would encourage - File renames be isolated into their own commit - Add tests in a commit before their feature or fix, showing the current behavior. The diff for the feature/fix commit will then show how the behavior changed, diff --git a/Cargo.toml b/Cargo.toml index f3a1f10..c2a6418 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -80,6 +80,7 @@ string_lit_as_bytes = "warn" string_to_string = "warn" todo = "warn" trait_duplication_in_bounds = "warn" +uninlined_format_args = "warn" verbose_file_reads = "warn" wildcard_imports = "warn" zero_sized_map_values = "warn" diff --git a/src/hooks.rs b/src/hooks.rs index 6ca8e55..bc0852c 100644 --- a/src/hooks.rs +++ b/src/hooks.rs @@ -89,7 +89,7 @@ impl Hooks { let mut cmd = std::process::Command::new(sh_path); cmd.arg("-c") - .arg(format!("{} \"$@\"", bin_name)) + .arg(format!("{bin_name} \"$@\"")) .arg(bin_name) // "$@" expands "$1" "$2" "$3" ... but we also must specify $0. .args(args) .env("PATH", path) @@ -131,7 +131,7 @@ impl Hooks { let mut stdin = String::new(); for (old_oid, new_oid) in changed_oids { use std::fmt::Write; - writeln!(stdin, "{} {}", old_oid, new_oid).expect("Always writeable"); + writeln!(stdin, "{old_oid} {new_oid}").expect("Always writeable"); } match self.run_hook(repo, name, &args, Some(stdin.as_bytes()), &[]) { @@ -188,7 +188,7 @@ impl Hooks { let mut stdin = String::new(); for (old_oid, new_oid, ref_name) in changed_refs { use std::fmt::Write; - writeln!(stdin, "{} {} {}", old_oid, new_oid, ref_name).expect("Always writeable"); + writeln!(stdin, "{old_oid} {new_oid} {ref_name}").expect("Always writeable"); } let code = self.run_hook(repo, name, &args, Some(stdin.as_bytes()), &[])?; @@ -198,7 +198,7 @@ impl Hooks { log::trace!("Hook `{}` failed with code {}", name, code); Err(std::io::Error::new( std::io::ErrorKind::Interrupted, - format!("`{}` hook failed with code {}", name, code), + format!("`{name}` hook failed with code {code}"), )) } } @@ -220,7 +220,7 @@ impl Hooks { let mut stdin = String::new(); for (old_oid, new_oid, ref_name) in changed_refs { use std::fmt::Write; - writeln!(stdin, "{} {} {}", old_oid, new_oid, ref_name).expect("Always writeable"); + writeln!(stdin, "{old_oid} {new_oid} {ref_name}").expect("Always writeable"); } match self.run_hook(repo, name, &args, Some(stdin.as_bytes()), &[]) { @@ -251,7 +251,7 @@ impl Hooks { let mut stdin = String::new(); for (old_oid, new_oid, ref_name) in changed_refs { use std::fmt::Write; - writeln!(stdin, "{} {} {}", old_oid, new_oid, ref_name).expect("Always writeable"); + writeln!(stdin, "{old_oid} {new_oid} {ref_name}").expect("Always writeable"); } match self.run_hook(repo, name, &args, Some(stdin.as_bytes()), &[]) { diff --git a/src/ops.rs b/src/ops.rs index ccad7e8..84522dc 100644 --- a/src/ops.rs +++ b/src/ops.rs @@ -113,7 +113,7 @@ pub fn cherry_pick( return Err(git2::Error::new( git2::ErrorCode::Unmerged, git2::ErrorClass::Index, - format!("cherry-pick conflicts:\n {}\n", conflicts), + format!("cherry-pick conflicts:\n {conflicts}\n"), )); } @@ -219,7 +219,7 @@ pub fn squash( return Err(git2::Error::new( git2::ErrorCode::Unmerged, git2::ErrorClass::Index, - format!("squash conflicts:\n {}\n", conflicts), + format!("squash conflicts:\n {conflicts}\n"), )); } let result_id = result_index.write_tree_to(repo)?; @@ -362,7 +362,7 @@ impl UserSign { _ => Err(git2::Error::new( git2::ErrorCode::Invalid, git2::ErrorClass::Config, - format!("invalid valid for gpg.format: {}", format), + format!("invalid valid for gpg.format: {format}"), )), } } @@ -459,7 +459,7 @@ impl Sign for SshSign { git2::Error::new( git2::ErrorCode::GenericError, git2::ErrorClass::Os, - format!("failed writing ssh signing key: {}", e), + format!("failed writing ssh signing key: {e}"), ) })?; @@ -467,7 +467,7 @@ impl Sign for SshSign { git2::Error::new( git2::ErrorCode::GenericError, git2::ErrorClass::Os, - format!("failed writing ssh signing key: {}", e), + format!("failed writing ssh signing key: {e}"), ) })?; let path = temp.path().to_owned(); @@ -487,14 +487,14 @@ impl Sign for SshSign { git2::Error::new( git2::ErrorCode::GenericError, git2::ErrorClass::Os, - format!("failed writing buffer: {}", e), + format!("failed writing buffer: {e}"), ) })?; std::fs::write(buffer_file.path(), buffer).map_err(|e| { git2::Error::new( git2::ErrorCode::GenericError, git2::ErrorClass::Os, - format!("failed writing buffer: {}", e), + format!("failed writing buffer: {e}"), ) })?; @@ -557,7 +557,7 @@ impl Sign for SshSign { git2::Error::new( git2::ErrorCode::GenericError, git2::ErrorClass::Os, - format!("failed writing buffer: {}", e), + format!("failed writing buffer: {e}"), ) })?; if let Some(literal_key_file) = literal_key_file { @@ -565,7 +565,7 @@ impl Sign for SshSign { git2::Error::new( git2::ErrorCode::GenericError, git2::ErrorClass::Os, - format!("failed writing ssh signing key: {}", e), + format!("failed writing ssh signing key: {e}"), ) })?; } @@ -591,7 +591,7 @@ fn pipe_command( .spawn()?; if let Some(stdin) = stdin { let mut stdin_sync = child.stdin.take().expect("stdin is piped"); - write!(stdin_sync, "{}", stdin)?; + write!(stdin_sync, "{stdin}")?; } child.wait_with_output() } @@ -630,20 +630,14 @@ fn get_default_ssh_signing_key(config: &git2::Config) -> Result, git2::Error::new( git2::ErrorCode::Invalid, git2::ErrorClass::Config, - format!( - "malformed gpg.ssh.defaultKeyCommand: {}", - ssh_default_key_command - ), + format!("malformed gpg.ssh.defaultKeyCommand: {ssh_default_key_command}"), ) })?; if ssh_default_key_args.is_empty() { return Err(git2::Error::new( git2::ErrorCode::Invalid, git2::ErrorClass::Config, - format!( - "malformed gpg.ssh.defaultKeyCommand: {}", - ssh_default_key_command - ), + format!("malformed gpg.ssh.defaultKeyCommand: {ssh_default_key_command}"), )); } diff --git a/src/testing.rs b/src/testing.rs index 09e2cfb..4948dcc 100644 --- a/src/testing.rs +++ b/src/testing.rs @@ -169,7 +169,7 @@ impl Git { pub(crate) fn get_base_env(&self, time: isize) -> Vec<(OsString, OsString)> { // Required for determinism, as these values will be baked into the commit // hash. - let date: OsString = format!("{date} -{time:0>2}", date = DUMMY_DATE, time = time).into(); + let date: OsString = format!("{DUMMY_DATE} -{time:0>2}").into(); // Fake "editor" which accepts the default contents of any commit // messages. Usually, we can set this with `git commit -m`, but we have @@ -332,7 +332,7 @@ stderr: if let Some(dir) = path.parent() { std::fs::create_dir_all(self.repo_path.join(dir))?; } - let file_path = self.repo_path.join(format!("{}.txt", name)); + let file_path = self.repo_path.join(format!("{name}.txt")); std::fs::write(file_path, contents)?; Ok(()) } @@ -348,7 +348,7 @@ stderr: self.write_file(name, contents)?; self.run(&["add", "."])?; self.run_with_options( - &["commit", "-m", &format!("create {}.txt", name)], + &["commit", "-m", &format!("create {name}.txt")], &GitRunOptions { time, ..Default::default() @@ -366,7 +366,7 @@ stderr: /// Commit a file with default contents. The `time` argument is used to set /// the commit timestamp, which is factored into the commit hash. pub(crate) fn commit_file(&self, name: &str, time: isize) -> eyre::Result { - self.commit_file_with_contents(name, time, &format!("{} contents\n", name)) + self.commit_file_with_contents(name, time, &format!("{name} contents\n")) } /// Get a `Repo` object for this repository. diff --git a/tests/testsuite/ops.rs b/tests/testsuite/ops.rs index 2af27c4..02867dc 100644 --- a/tests/testsuite/ops.rs +++ b/tests/testsuite/ops.rs @@ -60,7 +60,7 @@ fn cherry_pick_conflict() { let dest_id = git2_ext::ops::cherry_pick(&repo, base_id, source_id, None); - println!("{:#?}", dest_id); + println!("{dest_id:#?}"); assert!(dest_id.is_err()); assert!(!git2_ext::ops::is_dirty(&repo)); } @@ -91,7 +91,7 @@ fn squash_clean() { let dest_id = git2_ext::ops::squash(&repo, source_id, base_id, None).unwrap(); - println!("{:#?}", dest_id); + println!("{dest_id:#?}"); assert!(!git2_ext::ops::is_dirty(&repo)); } @@ -119,7 +119,7 @@ fn reword() { let new_id = git2_ext::ops::reword(&repo, feature2_id, "New message", None).unwrap(); - println!("{:#?}", new_id); + println!("{new_id:#?}"); assert!(!git2_ext::ops::is_dirty(&repo)); }