Skip to content

Commit

Permalink
backout: include backed out commit's subject in new commit
Browse files Browse the repository at this point in the history
  • Loading branch information
bnjmnt4n committed Jul 5, 2024
1 parent 82bab36 commit d2eb4d9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
* `jj workspace forget` now abandons the workspace's working-copy commit if it
was empty.

* `jj backout` now includes the backed out commit's subject in the new commit
message.

### Fixed bugs

## [0.19.0] - 2024-07-03
Expand Down Expand Up @@ -178,7 +181,6 @@ Thanks to the people who made this release happen!
were global flags and specifying them once would insert the new commit before/
after all the specified commits.


### Deprecations

* Attempting to alias a built-in command now gives a warning, rather than being
Expand Down
15 changes: 11 additions & 4 deletions cli/src/commands/backout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,24 @@ pub(crate) fn cmd_backout(
parents.push(destination);
}
let mut tx = workspace_command.start_transaction();
let commit_to_back_out_subject = commit_to_back_out
.description()
.lines()
.next()
.unwrap_or_default();
let new_commit_description = format!(
"Back out \"{}\"\n\nThis backs out commit {}.\n",
commit_to_back_out_subject,
&commit_to_back_out.id().hex()
);
let old_base_tree = commit_to_back_out.parent_tree(tx.mut_repo())?;
let new_base_tree = merge_commit_trees(tx.mut_repo(), &parents)?;
let old_tree = commit_to_back_out.tree()?;
let new_tree = new_base_tree.merge(&old_tree, &old_base_tree)?;
let new_parent_ids = parents.iter().map(|commit| commit.id().clone()).collect();
tx.mut_repo()
.new_commit(command.settings(), new_parent_ids, new_tree.id())
.set_description(format!(
"backout of commit {}",
&commit_to_back_out.id().hex()
))
.set_description(new_commit_description)
.write()?;
tx.finish(
ui,
Expand Down
12 changes: 9 additions & 3 deletions cli/tests/test_backout_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ fn test_backout() {
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
◉ 8fe4e9345020 backout of commit 2443ea76b0b1c531326908326aab7020abab8e6c
◉ 6d845ed9fb6a Back out "a"
│ This backs out commit 2443ea76b0b1c531326908326aab7020abab8e6c.
@ 2443ea76b0b1 a
◉ 000000000000
"###);
Expand All @@ -65,8 +67,12 @@ fn test_backout() {
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
◉ 46f192066e5e backout of commit 8fe4e93450209a70a6b9cd9af612e86634fd31fd
@ 8fe4e9345020 backout of commit 2443ea76b0b1c531326908326aab7020abab8e6c
◉ 79555ea9040b Back out "Back out "a""
│ This backs out commit 6d845ed9fb6a3d367e2d7068ef0256b1a10705a9.
@ 6d845ed9fb6a Back out "a"
│ This backs out commit 2443ea76b0b1c531326908326aab7020abab8e6c.
◉ 2443ea76b0b1 a
◉ 000000000000
"###);
Expand Down

0 comments on commit d2eb4d9

Please sign in to comment.