Skip to content
Merged
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
2 changes: 2 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.x'
- uses: pre-commit/[email protected]
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 6 additions & 6 deletions src/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()), &[]) {
Expand Down Expand Up @@ -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()), &[])?;
Expand All @@ -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}"),
))
}
}
Expand All @@ -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()), &[]) {
Expand Down Expand Up @@ -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()), &[]) {
Expand Down
30 changes: 12 additions & 18 deletions src/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
));
}

Expand Down Expand Up @@ -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)?;
Expand Down Expand Up @@ -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}"),
)),
}
}
Expand Down Expand Up @@ -459,15 +459,15 @@ 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}"),
)
})?;

std::fs::write(temp.path(), literal_key).map_err(|e| {
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();
Expand All @@ -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}"),
)
})?;

Expand Down Expand Up @@ -557,15 +557,15 @@ 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 {
literal_key_file.close().map_err(|e| {
git2::Error::new(
git2::ErrorCode::GenericError,
git2::ErrorClass::Os,
format!("failed writing ssh signing key: {}", e),
format!("failed writing ssh signing key: {e}"),
)
})?;
}
Expand All @@ -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()
}
Expand Down Expand Up @@ -630,20 +630,14 @@ fn get_default_ssh_signing_key(config: &git2::Config) -> Result<Option<String>,
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}"),
));
}

Expand Down
8 changes: 4 additions & 4 deletions src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(())
}
Expand All @@ -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()
Expand All @@ -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<git2::Oid> {
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.
Expand Down
6 changes: 3 additions & 3 deletions tests/testsuite/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down Expand Up @@ -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));
}

Expand Down Expand Up @@ -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));
}

Expand Down
Loading