Skip to content

Commit

Permalink
cli: display how many commits were rebased when merging operations (#111
Browse files Browse the repository at this point in the history
)

This involved copying `UnresolvedHeadRepo::resolve()` into the CLI
crate (and modifying it a bit to print number of rebased commit),
which is unfortunate.
  • Loading branch information
martinvonz committed Mar 27, 2022
1 parent e609f68 commit 64df092
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 6 deletions.
6 changes: 3 additions & 3 deletions lib/src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,9 @@ impl RepoAtHead {
}

pub struct UnresolvedHeadRepo {
repo_loader: RepoLoader,
locked_op_heads: LockedOpHeads,
op_heads: Vec<Operation>,
pub repo_loader: RepoLoader,
pub locked_op_heads: LockedOpHeads,
pub op_heads: Vec<Operation>,
}

impl UnresolvedHeadRepo {
Expand Down
23 changes: 21 additions & 2 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,27 @@ jj init --git-repo=.";
ui,
"Concurrent modification detected, resolving automatically.",
)?;
// TODO: Tell the user how many commits were rebased.
unresolved.resolve(ui.settings())
let base_repo = repo_loader.load_at(&unresolved.op_heads[0]);
// 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 {
Expand Down
30 changes: 29 additions & 1 deletion tests/test_concurrent_operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use jujutsu::testutils::TestEnvironment;

#[test]
fn test_concurrent_operations() {
fn test_concurrent_operation_divergence() {
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");
Expand All @@ -39,3 +39,31 @@ fn test_concurrent_operations() {
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
"###);
}

0 comments on commit 64df092

Please sign in to comment.