cli: display how many commits were rebased when merging operations (#111)

This involved copying `UnresolvedHeadRepo::resolve()` into the CLI
crate (and modifying it a bit to print number of rebased commit),
which is unfortunate.
This commit is contained in:
Martin von Zweigbergk 2022-03-26 10:44:28 -07:00 committed by Martin von Zweigbergk
parent f7abeed2a6
commit 12bce70bed
3 changed files with 53 additions and 6 deletions

View file

@ -303,9 +303,9 @@ impl RepoAtHead {
} }
pub struct UnresolvedHeadRepo { pub struct UnresolvedHeadRepo {
repo_loader: RepoLoader, pub repo_loader: RepoLoader,
locked_op_heads: LockedOpHeads, pub locked_op_heads: LockedOpHeads,
op_heads: Vec<Operation>, pub op_heads: Vec<Operation>,
} }
impl UnresolvedHeadRepo { impl UnresolvedHeadRepo {

View file

@ -218,8 +218,27 @@ jj init --git-repo=.";
ui, ui,
"Concurrent modification detected, resolving automatically.", "Concurrent modification detected, resolving automatically.",
)?; )?;
// TODO: Tell the user how many commits were rebased. let base_repo = repo_loader.load_at(&unresolved.op_heads[0]);
unresolved.resolve(ui.settings()) // TODO: It may be helpful to print each operation we're merging here
let mut workspace_command = self.for_loaded_repo(ui, workspace, base_repo)?;
let mut tx =
workspace_command.start_transaction("resolve concurrent operations");
for other_op_head in unresolved.op_heads.into_iter().skip(1) {
tx.merge_operation(other_op_head);
let num_rebased = tx.mut_repo().rebase_descendants(ui.settings());
if num_rebased > 0 {
writeln!(
ui,
"Rebased {} descendant commits onto commits rewritten by other \
operation",
num_rebased
)?;
}
}
let merged_repo = tx.write().leave_unpublished();
unresolved.locked_op_heads.finish(merged_repo.operation());
workspace_command.repo = merged_repo;
return Ok(workspace_command);
} }
} }
} else { } else {

View file

@ -15,7 +15,7 @@
use jujutsu::testutils::TestEnvironment; use jujutsu::testutils::TestEnvironment;
#[test] #[test]
fn test_concurrent_operations() { fn test_concurrent_operation_divergence() {
let test_env = TestEnvironment::default(); let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]); test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo"); let repo_path = test_env.env_root().join("repo");
@ -39,3 +39,31 @@ fn test_concurrent_operations() {
o o
"###); "###);
} }
#[test]
fn test_concurrent_operations_auto_rebase() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
std::fs::write(repo_path.join("file"), "contents").unwrap();
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "initial"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["op", "log"]);
let op_id_hex = stdout[2..14].to_string();
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "rewritten"]);
test_env.jj_cmd_success(
&repo_path,
&["new", "--at-op", &op_id_hex, "-m", "new child"],
);
// We should be informed about the concurrent modification
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", "commit_id \" \" description"]);
insta::assert_snapshot!(stdout, @r###"
Concurrent modification detected, resolving automatically.
Rebased 1 descendant commits onto commits rewritten by other operation
o 4eeb7d76372418118a91c34f09e5e3936f0deeb5 new child
@ 14176aeadc0259b2150fc7374969e74b1552a498 rewritten
o 0000000000000000000000000000000000000000
"###);
}