mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-14 16:37:42 +00:00
abandon: add --restore-descendants flag
This commit is contained in:
parent
f76ee1872f
commit
e8deb08f78
4 changed files with 53 additions and 2 deletions
|
@ -72,6 +72,9 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|||
* `jj diffedit` now accepts a `--restore-descendants` flag. When used,
|
||||
descendants of the edited commit will keep their original content.
|
||||
|
||||
* `jj abandon` now accepts a `--restore-descendants` flag. When used,
|
||||
descendants of the abandoned commits will keep their original content.
|
||||
|
||||
### Fixed bugs
|
||||
|
||||
* Update working copy before reporting changes. This prevents errors during reporting
|
||||
|
|
|
@ -43,6 +43,9 @@ pub(crate) struct AbandonArgs {
|
|||
/// Ignored (but lets you pass `-r` for consistency with other commands)
|
||||
#[arg(short = 'r', hide = true, action = clap::ArgAction::Count)]
|
||||
unused_revision: u8,
|
||||
/// Do not modify the content of the children of the abandoned commits
|
||||
#[arg(long)]
|
||||
restore_descendants: bool,
|
||||
}
|
||||
|
||||
#[instrument(skip_all)]
|
||||
|
@ -66,7 +69,14 @@ pub(crate) fn cmd_abandon(
|
|||
for commit in &to_abandon {
|
||||
tx.repo_mut().record_abandoned_commit(commit.id().clone());
|
||||
}
|
||||
let num_rebased = tx.repo_mut().rebase_descendants(command.settings())?;
|
||||
let (num_rebased, extra_msg) = if args.restore_descendants {
|
||||
(
|
||||
tx.repo_mut().reparent_descendants(command.settings())?,
|
||||
" (while preserving their content)",
|
||||
)
|
||||
} else {
|
||||
(tx.repo_mut().rebase_descendants(command.settings())?, "")
|
||||
};
|
||||
|
||||
if let Some(mut formatter) = ui.status_formatter() {
|
||||
if to_abandon.len() == 1 {
|
||||
|
@ -88,7 +98,8 @@ pub(crate) fn cmd_abandon(
|
|||
if num_rebased > 0 {
|
||||
writeln!(
|
||||
formatter,
|
||||
"Rebased {num_rebased} descendant commits onto parents of abandoned commits"
|
||||
"Rebased {num_rebased} descendant commits{extra_msg} onto parents of abandoned \
|
||||
commits",
|
||||
)?;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -207,6 +207,7 @@ If a working-copy commit gets abandoned, it will be given a new, empty commit. T
|
|||
###### **Options:**
|
||||
|
||||
* `-s`, `--summary` — Do not print every abandoned commit on a separate line
|
||||
* `--restore-descendants` — Do not modify the content of the children of the abandoned commits
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -364,6 +364,42 @@ fn test_double_abandon() {
|
|||
"###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_abandon_restore_descendants() {
|
||||
let test_env = TestEnvironment::default();
|
||||
test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]);
|
||||
let repo_path = test_env.env_root().join("repo");
|
||||
|
||||
std::fs::write(repo_path.join("file"), "foo\n").unwrap();
|
||||
test_env.jj_cmd_ok(&repo_path, &["new"]);
|
||||
std::fs::write(repo_path.join("file"), "bar\n").unwrap();
|
||||
test_env.jj_cmd_ok(&repo_path, &["new"]);
|
||||
std::fs::write(repo_path.join("file"), "baz\n").unwrap();
|
||||
|
||||
// Remove the commit containing "bar"
|
||||
let (stdout, stderr) = test_env.jj_cmd_ok(
|
||||
&repo_path,
|
||||
&["abandon", "-r", "@-", "--restore-descendants"],
|
||||
);
|
||||
insta::assert_snapshot!(stdout, @"");
|
||||
insta::assert_snapshot!(stderr, @r#"
|
||||
Abandoned commit rlvkpnrz 225adef1 (no description set)
|
||||
Rebased 1 descendant commits (while preserving their content) onto parents of abandoned commits
|
||||
Working copy now at: kkmpptxz a734deb0 (no description set)
|
||||
Parent commit : qpvuntsm 485d52a9 (no description set)
|
||||
"#);
|
||||
let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "--git"]);
|
||||
insta::assert_snapshot!(stdout, @r#"
|
||||
diff --git a/file b/file
|
||||
index 257cc5642c..76018072e0 100644
|
||||
--- a/file
|
||||
+++ b/file
|
||||
@@ -1,1 +1,1 @@
|
||||
-foo
|
||||
+baz
|
||||
"#);
|
||||
}
|
||||
|
||||
fn get_log_output(test_env: &TestEnvironment, repo_path: &Path) -> String {
|
||||
test_env.jj_cmd_success(
|
||||
repo_path,
|
||||
|
|
Loading…
Reference in a new issue