forked from mirrors/jj
cli: make jj workspace add
preserve all parents of current workspace
This commit is contained in:
parent
2d3fe7eee2
commit
23a0baba14
3 changed files with 51 additions and 6 deletions
|
@ -69,6 +69,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
* The new template keywords `local_branches`/`remote_branches` are added to show
|
||||
only local/remote branches.
|
||||
|
||||
* `jj workspace add` now preserves all parents of the old working-copy commit
|
||||
instead of just the first one.
|
||||
|
||||
### Fixed bugs
|
||||
|
||||
* Updating the working copy to a commit where a file that's currently ignored
|
||||
|
|
|
@ -1698,23 +1698,30 @@ fn cmd_workspace_add(
|
|||
&name
|
||||
));
|
||||
|
||||
let new_wc_commit = if let Some(specific_rev) = &args.revision {
|
||||
old_workspace_command.resolve_single_rev(specific_rev, ui)?
|
||||
let parents = if let Some(specific_rev) = &args.revision {
|
||||
vec![old_workspace_command.resolve_single_rev(specific_rev, ui)?]
|
||||
} else {
|
||||
// Check out a parent of the current workspace's working-copy commit, or the
|
||||
// Check out parents of the current workspace's working-copy commit, or the
|
||||
// root if there is no working-copy commit in the current workspace.
|
||||
if let Some(old_wc_commit_id) = tx
|
||||
.base_repo()
|
||||
.view()
|
||||
.get_wc_commit_id(old_workspace_command.workspace_id())
|
||||
{
|
||||
tx.repo().store().get_commit(old_wc_commit_id)?.parents()[0].clone()
|
||||
tx.repo().store().get_commit(old_wc_commit_id)?.parents()
|
||||
} else {
|
||||
tx.repo().store().root_commit()
|
||||
vec![tx.repo().store().root_commit()]
|
||||
}
|
||||
};
|
||||
|
||||
tx.check_out(&new_wc_commit)?;
|
||||
let tree = merge_commit_trees(tx.repo(), &parents)?;
|
||||
let parent_ids = parents.iter().map(|c| c.id().clone()).collect_vec();
|
||||
let new_wc_commit = tx
|
||||
.mut_repo()
|
||||
.new_commit(command.settings(), parent_ids, tree.id())
|
||||
.write()?;
|
||||
|
||||
tx.edit(&new_wc_commit)?;
|
||||
tx.finish(ui)?;
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -71,6 +71,41 @@ fn test_workspaces_add_second_workspace() {
|
|||
"###);
|
||||
}
|
||||
|
||||
/// Test adding a second workspace while the current workspace is editing a
|
||||
/// merge
|
||||
#[test]
|
||||
fn test_workspaces_add_second_workspace_on_merge() {
|
||||
let test_env = TestEnvironment::default();
|
||||
test_env.jj_cmd_ok(test_env.env_root(), &["init", "--git", "main"]);
|
||||
let main_path = test_env.env_root().join("main");
|
||||
|
||||
test_env.jj_cmd_ok(&main_path, &["describe", "-m=left"]);
|
||||
test_env.jj_cmd_ok(&main_path, &["new", "@-", "-m=right"]);
|
||||
test_env.jj_cmd_ok(&main_path, &["new", "all:@-+", "-m=merge"]);
|
||||
|
||||
let stdout = test_env.jj_cmd_success(&main_path, &["workspace", "list"]);
|
||||
insta::assert_snapshot!(stdout, @r###"
|
||||
default: zsuskuln 21a0ea6d (empty) merge
|
||||
"###);
|
||||
|
||||
test_env.jj_cmd_ok(
|
||||
&main_path,
|
||||
&["workspace", "add", "--name", "second", "../secondary"],
|
||||
);
|
||||
|
||||
// The new workspace's working-copy commit shares all parents with the old one.
|
||||
insta::assert_snapshot!(get_log_output(&test_env, &main_path), @r###"
|
||||
◉ 6d4c2b8ab610148410b6a346d900cb7ad6298ede second@
|
||||
├─╮
|
||||
│ │ @ 21a0ea6d1c86c413cb30d7f7d216a74754b148c4 default@
|
||||
╭─┬─╯
|
||||
│ ◉ 09ba8d9dfa21b8572c2361e6947ca024d8f0a198
|
||||
◉ │ 1694f2ddf8ecf9e55ca3cd9554bc0654186b07e0
|
||||
├─╯
|
||||
◉ 0000000000000000000000000000000000000000
|
||||
"###);
|
||||
}
|
||||
|
||||
/// Test adding a workspace, but at a specific revision using '-r'
|
||||
#[test]
|
||||
fn test_workspaces_add_workspace_at_revision() {
|
||||
|
|
Loading…
Reference in a new issue