Skip to content

Commit

Permalink
Update to the 2021 edition of Rust & fix issues
Browse files Browse the repository at this point in the history
* Update to the 2021 edition
* Fix some typos
* Remove some unnecessary referencing
* Update version to 0.7.0
  • Loading branch information
dsully authored Jul 10, 2024
1 parent 37adfcf commit ea257ca
Show file tree
Hide file tree
Showing 15 changed files with 295 additions and 284 deletions.
411 changes: 214 additions & 197 deletions Cargo.lock

Large diffs are not rendered by default.

32 changes: 16 additions & 16 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
[package]
name = "autorebase"
version = "0.6.0"
authors = ["Tim Hutt <timh@graphcore.ai>"]
edition = "2018"
license = "MIT"
authors = [ "Tim Hutt <timh@graphcore.ai>" ]
description = "Automatically rebase feature branches onto master"
keywords = ["git", "rebase"]
edition = "2021"
keywords = [ "git", "rebase" ]
license = "MIT"
name = "autorebase"
repository = "https://github.com/Timmmm/autorebase"
version = "0.7.0"

[dependencies]
anyhow = "1.0.40"
argh = "0.1.4"
colored = "2.0.0"
env_logger = "0.10.0"
anyhow = "1.0.86"
argh = "0.1.12"
colored = "2.1.0"
env_logger = "0.11.3"
git_commands = { path = "git_commands", version = "0.2.0" }
itertools = "0.11.0"
log = "0.4.14"
serde = { version = "1.0", features = ["derive"] }
toml = "0.7.6"
itertools = "0.13.0"
log = "0.4.22"
serde = { version = "1.0", features = [ "derive" ] }
toml = "0.8.14"

[dev-dependencies]
# For tests
tempfile = "3.1.0"
rand = "0.8.3"
rand = "0.8.5"
tempfile = "3.10.1"
2 changes: 1 addition & 1 deletion examples/create_demo_repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn main() {
.write("a.txt", "hello")
.child(
commit("Write specification")
.write("spec.txt", "Specifcation: Do nothing")
.write("spec.txt", "Specification: Do nothing")
.child(
commit("Implement specification")
.write("code.c", "int main() { return 1; }")
Expand Down
24 changes: 12 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ pub fn autorebase(
None => default_branch_name(path)?,
};

// The first thing we do is set the commiter date to now. If we don't do this
// The first thing we do is set the committer date to now. If we don't do this
// then when we have two branch labels on the same commit, when they get
// rebased they will be given different commiter dates which will mean they
// rebased they will be given different committer dates which will mean they
// get different hashes and end up as separate commits.
set_committer_date_to_now();

Expand Down Expand Up @@ -243,7 +243,7 @@ fn rebase_branch(
}

conflicts.branches.remove(&branch.branch);
conflicts.write_to_file(&conflicts_path)?;
conflicts.write_to_file(conflicts_path)?;

let merge_base = get_merge_base(worktree_path, &branch.branch, onto_branch)?;

Expand All @@ -261,7 +261,7 @@ fn rebase_branch(
&worktree.path
} else {
// It isn't checked out anywhere; switch to it in our temporary worktree.
switch_to_branch(&branch.branch, &worktree_path)?;
switch_to_branch(&branch.branch, worktree_path)?;
worktree_path
};

Expand Down Expand Up @@ -322,7 +322,7 @@ fn rebase_branch(
let result = attempt_rebase(
git_common_dir,
rebase_worktree_path,
&last_nonconflicting_commit,
last_nonconflicting_commit,
)?;
match result {
RebaseResult::Success => {
Expand All @@ -339,7 +339,7 @@ fn rebase_branch(

// Switch to the branch so that we don't leave references to unneeded commits
// around, and detach otherwise we may prevent people checking it out.
git(&["switch", "--detach", &branch.branch], &worktree_path)?;
git(&["switch", "--detach", &branch.branch], worktree_path)?;

if stopped_by_conflicts {
eprintln!(
Expand All @@ -353,7 +353,7 @@ fn rebase_branch(
conflicts
.branches
.insert(branch.branch.clone(), new_branch_commit);
conflicts.write_to_file(&conflicts_path)?;
conflicts.write_to_file(conflicts_path)?;
}

Ok(())
Expand Down Expand Up @@ -531,7 +531,7 @@ fn attempt_rebase(git_common_dir: &Path, worktree_path: &Path, onto: &str) -> Re
Ok(RebaseResult::Conflict)
}

const TEMPORARY_BRANCH_NAME: &'static str = "autorebase_tmp_safe_to_delete";
const TEMPORARY_BRANCH_NAME: &str = "autorebase_tmp_safe_to_delete";

/// Create a temporary branch at master (`onto`), then try to rebase it ont
/// `branch`. Count how many commits were rebased successfully, and
Expand Down Expand Up @@ -639,7 +639,7 @@ enum BranchOrCommit {
fn get_current_branch(working_dir: &Path) -> Result<Option<String>> {
let output = Command::new("git")
.current_dir(working_dir)
.args(&["symbolic-ref", "--quiet", "--short", "HEAD"])
.args(["symbolic-ref", "--quiet", "--short", "HEAD"])
.output()?;

if output.status.success() {
Expand All @@ -654,7 +654,7 @@ fn get_current_branch(working_dir: &Path) -> Result<Option<String>> {
/// return an error if we are on an unborn branch. That's an error for us though
/// so we don't have to treat that case specially.
fn get_commit_hash(working_dir: &Path, branch: &str) -> Result<String> {
let commit = git(&["rev-parse", &branch], working_dir)?.stdout;
let commit = git(&["rev-parse", branch], working_dir)?.stdout;
let commit = std::str::from_utf8(commit.trim_ascii_whitespace())?;
Ok(commit.to_owned())
}
Expand All @@ -671,10 +671,10 @@ fn get_current_branch_or_commit(working_dir: &Path) -> Result<BranchOrCommit> {
fn switch_to_branch_or_commit(working_dir: &Path, branch_or_commit: &BranchOrCommit) -> Result<()> {
match branch_or_commit {
BranchOrCommit::Branch(ref branch) => {
git(&["switch", &branch], working_dir)?;
git(&["switch", branch], working_dir)?;
}
BranchOrCommit::Commit(ref commit) => {
git(&["switch", "--detach", &commit], working_dir)?;
git(&["switch", "--detach", commit], working_dir)?;
}
}
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct CliOptions {
onto: Option<String>,

/// if there are conflicts, try rebasing commit by commit backwards from the
/// target, instead of trying to determind the conflicting commit on the
/// target, instead of trying to determined the conflicting commit on the
/// target branch directly
#[argh(switch)]
slow: bool,
Expand Down
6 changes: 3 additions & 3 deletions tests/tests/all_branches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ fn with_include(include_all_branches: bool) -> BTreeMap<String, CommitGraphNode>

let repo_dir = repo.path();

print_git_log_graph(&repo_dir);
print_git_log_graph(repo_dir);

autorebase(repo_dir, Some("master"), false, include_all_branches, None)
.expect("error autorebasing");

print_git_log_graph(&repo_dir);
print_git_log_graph(repo_dir);

get_repo_graph(&repo_dir).expect("error getting repo graph")
get_repo_graph(repo_dir).expect("error getting repo graph")
}

#[test]
Expand Down
10 changes: 5 additions & 5 deletions tests/tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ fn test_build_repo() {

let repo_dir = repo.path();

print_git_log_graph(&repo_dir);
print_git_log_graph(repo_dir);

let graph = get_repo_graph(&repo_dir).expect("error getting repo graph");
let graph = get_repo_graph(repo_dir).expect("error getting repo graph");

let expected_graph = commit_graph!(
"baf6cf8e026e065d369b3dd103c4cc73ffba52dd": CommitGraphNode {
Expand Down Expand Up @@ -61,7 +61,7 @@ fn basic_autorebase(slow_conflict_detection: bool) {

let repo_dir = repo.path();

print_git_log_graph(&repo_dir);
print_git_log_graph(repo_dir);

autorebase(
repo_dir,
Expand All @@ -72,9 +72,9 @@ fn basic_autorebase(slow_conflict_detection: bool) {
)
.expect("error autorebasing");

print_git_log_graph(&repo_dir);
print_git_log_graph(repo_dir);

let graph = get_repo_graph(&repo_dir).expect("error getting repo graph");
let graph = get_repo_graph(repo_dir).expect("error getting repo graph");

let expected_graph = commit_graph!(
"a6de41485a5af44adc18b599a63840c367043e39": CommitGraphNode {
Expand Down
6 changes: 3 additions & 3 deletions tests/tests/basic_conflict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn conflict(slow_conflict_detection: bool) {

let repo_dir = repo.path();

print_git_log_graph(&repo_dir);
print_git_log_graph(repo_dir);

autorebase(
repo_dir,
Expand All @@ -43,9 +43,9 @@ fn conflict(slow_conflict_detection: bool) {
)
.expect("error autorebasing");

print_git_log_graph(&repo_dir);
print_git_log_graph(repo_dir);

let graph = get_repo_graph(&repo_dir).expect("error getting repo graph");
let graph = get_repo_graph(repo_dir).expect("error getting repo graph");

let expected_graph = commit_graph!(
"386e8eec713b111eca536adc310dfccf22323ad7": CommitGraphNode {
Expand Down
18 changes: 9 additions & 9 deletions tests/tests/checked_out.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn checkedout_clean(slow_conflict_detection: bool) {

let repo_dir = repo.path();

print_git_log_graph(&repo_dir);
print_git_log_graph(repo_dir);

autorebase(
repo_dir,
Expand All @@ -36,9 +36,9 @@ fn checkedout_clean(slow_conflict_detection: bool) {
)
.expect("error autorebasing");

print_git_log_graph(&repo_dir);
print_git_log_graph(repo_dir);

let graph = get_repo_graph(&repo_dir).expect("error getting repo graph");
let graph = get_repo_graph(repo_dir).expect("error getting repo graph");

let expected_graph = commit_graph!(
"a6de41485a5af44adc18b599a63840c367043e39": CommitGraphNode {
Expand Down Expand Up @@ -93,7 +93,7 @@ fn checkedout_dirty(slow_conflict_detection: bool) {
// Make it dirty.
fs::write(repo_dir.join("b.txt"), "baz").expect("error writing file");

print_git_log_graph(&repo_dir);
print_git_log_graph(repo_dir);

autorebase(
repo_dir,
Expand All @@ -104,9 +104,9 @@ fn checkedout_dirty(slow_conflict_detection: bool) {
)
.expect("error autorebasing");

print_git_log_graph(&repo_dir);
print_git_log_graph(repo_dir);

let graph = get_repo_graph(&repo_dir).expect("error getting repo graph");
let graph = get_repo_graph(repo_dir).expect("error getting repo graph");

let expected_graph = commit_graph!(
"a6de41485a5af44adc18b599a63840c367043e39": CommitGraphNode {
Expand Down Expand Up @@ -168,7 +168,7 @@ fn checked_out_conflict(slow_conflict_detection: bool) {

let repo_dir = repo.path();

print_git_log_graph(&repo_dir);
print_git_log_graph(repo_dir);

autorebase(
repo_dir,
Expand All @@ -179,9 +179,9 @@ fn checked_out_conflict(slow_conflict_detection: bool) {
)
.expect("error autorebasing");

print_git_log_graph(&repo_dir);
print_git_log_graph(repo_dir);

let graph = get_repo_graph(&repo_dir).expect("error getting repo graph");
let graph = get_repo_graph(repo_dir).expect("error getting repo graph");

let expected_graph = commit_graph!(
"386e8eec713b111eca536adc310dfccf22323ad7": CommitGraphNode {
Expand Down
20 changes: 10 additions & 10 deletions tests/tests/conflict_resume.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn conflict_resume(slow_conflict_detection: bool) {

let repo_dir = repo.path();

print_git_log_graph(&repo_dir);
print_git_log_graph(repo_dir);

autorebase(
repo_dir,
Expand All @@ -49,9 +49,9 @@ fn conflict_resume(slow_conflict_detection: bool) {
)
.expect("error autorebasing");

print_git_log_graph(&repo_dir);
print_git_log_graph(repo_dir);

let graph = get_repo_graph(&repo_dir).expect("error getting repo graph");
let graph = get_repo_graph(repo_dir).expect("error getting repo graph");

let expected_graph = commit_graph!(
"386e8eec713b111eca536adc310dfccf22323ad7": CommitGraphNode {
Expand Down Expand Up @@ -103,13 +103,13 @@ fn conflict_resume(slow_conflict_detection: bool) {

// Ok if we run `autorebase` again we should expect it not to change anything.

print_git_log_graph(&repo_dir);
print_git_log_graph(repo_dir);

autorebase(repo_dir, Some("master"), true, false, None).expect("error autorebasing");

print_git_log_graph(&repo_dir);
print_git_log_graph(repo_dir);

let graph = get_repo_graph(&repo_dir).expect("error getting repo graph");
let graph = get_repo_graph(repo_dir).expect("error getting repo graph");

let expected_graph = commit_graph!(
"211ae909a7bf0a2052009b8c21bebc6947591277": CommitGraphNode {
Expand Down Expand Up @@ -170,15 +170,15 @@ fn conflict_resume(slow_conflict_detection: bool) {
// Check out master again so `wip` can be autorebased.
git(&["checkout", "master"], repo_dir).expect("error checking out master");

// Ok if we run `autorebase` is should succesfully rebase to master.
// Ok if we run `autorebase` is should successfully rebase to master.

print_git_log_graph(&repo_dir);
print_git_log_graph(repo_dir);

autorebase(repo_dir, Some("master"), true, false, None).expect("error autorebasing");

print_git_log_graph(&repo_dir);
print_git_log_graph(repo_dir);

let graph = get_repo_graph(&repo_dir).expect("error getting repo graph");
let graph = get_repo_graph(repo_dir).expect("error getting repo graph");

let expected_graph = commit_graph!(
"20b78857d9e5095469d9f91a5de77d0c36813b46": CommitGraphNode {
Expand Down
8 changes: 4 additions & 4 deletions tests/tests/from_another_worktree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ fn from_another_worktree(slow_conflict_detection: bool) {
&[
"worktree",
"add",
&another_worktree_repo_dir
another_worktree_repo_dir
.to_str()
.expect("non-unicode test path"),
],
repo_dir,
)
.expect("Couldn't create another worktree");

print_git_log_graph(&repo_dir);
print_git_log_graph(repo_dir);

// Now autorebase from the other worktree dir.
autorebase(
Expand All @@ -53,9 +53,9 @@ fn from_another_worktree(slow_conflict_detection: bool) {
)
.expect("error autorebasing");

print_git_log_graph(&repo_dir);
print_git_log_graph(repo_dir);

let graph = get_repo_graph(&repo_dir).expect("error getting repo graph");
let graph = get_repo_graph(repo_dir).expect("error getting repo graph");

let expected_graph = commit_graph!(
"a6de41485a5af44adc18b599a63840c367043e39": CommitGraphNode {
Expand Down
Loading

0 comments on commit ea257ca

Please sign in to comment.