Skip to content

Commit

Permalink
feat(rewrite): print updated names in reference-transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
arxanas committed Jul 3, 2021
1 parent f4133b1 commit 646185f
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 24 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

- Added: `git move` now supports forcing an in-memory rebase with the `--in-memory` flag.
- Added: The `reference-transaction` hook prints out which references were updated.
- Fixed: `git move` preserves committer timestamps when `branchless.restack.preserveTimestamps` is set. The configuration key may change in the future.
- Fixed: The output of `git` subcommands is streamed to stdout, rather than accumulated and dumped at the end.
- Fixed: Commits rebased in-memory by `git move` are now marked as reachable by the Git garbage collector, so that they aren't collected prematurely.
Expand Down
21 changes: 19 additions & 2 deletions src/commands/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,25 @@ pub fn hook_reference_transaction(transaction_state: &str) -> anyhow::Result<()>
plural: "updates to branches/refs",
};
println!(
"branchless: processing {}",
num_reference_updates.to_string()
"branchless: processing {} {}",
num_reference_updates.to_string(),
console::style(format!(
"({})",
events
.iter()
.filter_map(|event| {
match event {
Event::RefUpdateEvent { ref_name, .. } => Some(ref_name.to_string_lossy()),
Event::RewriteEvent { .. }
| Event::CommitEvent { .. }
| Event::HideEvent { .. }
| Event::UnhideEvent { .. } => None,
}
})
.collect::<Vec<_>>()
.join(", ")
))
.green(),
);
event_log_db.add_events(events)?;

Expand Down
10 changes: 5 additions & 5 deletions src/git/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,11 @@ mod tests {
// Trigger the `post-rewrite` hook that we wrote above.
let (stdout, stderr) = git.run(&["commit", "--amend", "-m", "foo"])?;
insta::assert_snapshot!(stderr, @r###"
branchless: processing 2 updates to branches/refs
branchless: processing commit
Contents of test1.txt:
test1 contents
"###);
branchless: processing 2 updates to branches/refs (HEAD, refs/heads/master)
branchless: processing commit
Contents of test1.txt:
test1 contents
"###);
insta::assert_snapshot!(stdout, @r###"
[master f23bf8f] foo
Date: Thu Oct 29 12:34:56 2020 -0100
Expand Down
28 changes: 14 additions & 14 deletions tests/command/test_move.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,12 @@ fn test_move_with_source_not_in_smartlog_in_memory() -> anyhow::Result<()> {
&test1_oid.to_string(),
])?;
insta::assert_snapshot!(stdout, @r###"
Attempting rebase in-memory...
branchless: processing 1 update to a branch/ref
branchless: processing 2 rewritten commits
branchless: <git-executable> checkout master
In-memory rebase succeeded.
"###);
Attempting rebase in-memory...
branchless: processing 1 update to a branch/ref (master)
branchless: processing 2 rewritten commits
branchless: <git-executable> checkout master
In-memory rebase succeeded.
"###);
}

{
Expand Down Expand Up @@ -392,12 +392,12 @@ fn test_move_branch() -> anyhow::Result<()> {
{
let (stdout, _stderr) = git.run(&["move", "-d", &test2_oid.to_string()])?;
insta::assert_snapshot!(stdout, @r###"
Attempting rebase in-memory...
branchless: processing 1 update to a branch/ref
branchless: processing 1 rewritten commit
branchless: <git-executable> checkout master
In-memory rebase succeeded.
"###);
Attempting rebase in-memory...
branchless: processing 1 update to a branch/ref (master)
branchless: processing 1 rewritten commit
branchless: <git-executable> checkout master
In-memory rebase succeeded.
"###);
}

{
Expand Down Expand Up @@ -438,7 +438,7 @@ fn test_move_base_onto_head() -> anyhow::Result<()> {
let (stdout, stderr) = git.run(&["move", "-b", "HEAD"])?;
insta::assert_snapshot!(stderr, @r###"
Previous HEAD position was 70deb1e create test3.txt
branchless: processing 1 update to a branch/ref
branchless: processing 1 update to a branch/ref (HEAD)
HEAD is now at a45568b create test3.txt
branchless: processing checkout
"###);
Expand Down Expand Up @@ -570,7 +570,7 @@ fn test_move_in_memory_gc() -> anyhow::Result<()> {
let (stdout, stderr) = git.run(&["move", "-d", "master", "--in-memory"])?;
insta::assert_snapshot!(stderr, @r###"
Previous HEAD position was 96d1c37 create test2.txt
branchless: processing 1 update to a branch/ref
branchless: processing 1 update to a branch/ref (HEAD)
HEAD is now at fe65c1f create test2.txt
branchless: processing checkout
"###);
Expand Down
6 changes: 3 additions & 3 deletions tests/command/test_restack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ fn test_move_abandoned_branch() -> anyhow::Result<()> {
let stdout = remove_rebase_lines(stdout);
insta::assert_snapshot!(stdout, @r###"
No abandoned commits to restack.
branchless: processing 1 update to a branch/ref
branchless: processing 1 update to a branch/ref (master)
Finished restacking branches.
branchless: <git-executable> checkout 662b451fb905b92404787e024af717ced49e3045
:
Expand Down Expand Up @@ -168,7 +168,7 @@ fn test_amended_initial_commit() -> anyhow::Result<()> {
Calling Git for on-disk rebase...
branchless: <git-executable> rebase --continue
Finished restacking commits.
branchless: processing 1 update to a branch/ref
branchless: processing 1 update to a branch/ref (master)
Finished restacking branches.
branchless: <git-executable> checkout 9a9f929a0d4f052ff5d58bedd97b2f761120f8ed
@ 9a9f929a new initial commit
Expand Down Expand Up @@ -204,7 +204,7 @@ fn test_restack_amended_master() -> anyhow::Result<()> {
Calling Git for on-disk rebase...
branchless: <git-executable> rebase --continue
Finished restacking commits.
branchless: processing 1 update to a branch/ref
branchless: processing 1 update to a branch/ref (master)
Finished restacking branches.
branchless: <git-executable> checkout ae94dc2a748bc0965c88fcf3edac2e30074ff7e2
:
Expand Down

0 comments on commit 646185f

Please sign in to comment.