Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

repo: pretend root commit exists in the root operation #4594

Merged
merged 6 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions cli/src/cli_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2240,14 +2240,7 @@ pub fn check_stale_working_copy(
// The working copy isn't stale, and no need to reload the repo.
Ok(WorkingCopyFreshness::Fresh)
} else {
let wc_operation_data = repo
.op_store()
.read_operation(locked_wc.old_operation_id())?;
let wc_operation = Operation::new(
repo.op_store().clone(),
locked_wc.old_operation_id().clone(),
wc_operation_data,
);
let wc_operation = repo.loader().load_operation(locked_wc.old_operation_id())?;
let repo_operation = repo.operation();
let ancestor_op = dag_walk::closest_common_node_ok(
[Ok(wc_operation.clone())],
Expand Down
5 changes: 1 addition & 4 deletions cli/src/commands/operation/abandon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use std::slice;

use itertools::Itertools as _;
use jj_lib::op_walk;
use jj_lib::operation::Operation;

use crate::cli_util::short_operation_hash;
use crate::cli_util::CommandHelper;
Expand Down Expand Up @@ -65,9 +64,7 @@ pub fn cmd_op_abandon(
let (abandon_root_op, abandon_head_ops) =
if let Some((root_op_str, head_op_str)) = args.operation.split_once("..") {
let root_op = if root_op_str.is_empty() {
let id = op_store.root_operation_id();
let data = op_store.read_operation(id)?;
Operation::new(op_store.clone(), id.clone(), data)
repo_loader.root_operation()
} else {
resolve_op(root_op_str)?
};
Expand Down
13 changes: 2 additions & 11 deletions cli/src/commands/workspace/update_stale.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use std::sync::Arc;

use jj_lib::object_id::ObjectId;
use jj_lib::op_store::OpStoreError;
use jj_lib::operation::Operation;
use jj_lib::repo::ReadonlyRepo;
use jj_lib::repo::Repo;
use tracing::instrument;
Expand Down Expand Up @@ -148,18 +147,10 @@ fn for_stale_working_copy(
command: &CommandHelper,
) -> Result<(WorkspaceCommandHelper, bool), CommandError> {
let workspace = command.load_workspace()?;
let op_store = workspace.repo_loader().op_store();
let (repo, recovered) = {
let op_id = workspace.working_copy().operation_id();
match op_store.read_operation(op_id) {
Ok(op_data) => (
workspace.repo_loader().load_at(&Operation::new(
op_store.clone(),
op_id.clone(),
op_data,
))?,
false,
),
match workspace.repo_loader().load_operation(op_id) {
Ok(op) => (workspace.repo_loader().load_at(&op)?, false),
Err(e @ OpStoreError::ObjectNotFound { .. }) => {
writeln!(
ui.status(),
Expand Down
51 changes: 22 additions & 29 deletions cli/tests/test_concurrent_operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,21 @@ fn test_concurrent_operation_divergence() {

// "--at-op=@" disables op heads merging, and prints head operation ids.
let stderr = test_env.jj_cmd_failure(&repo_path, &["op", "log", "--at-op=@"]);
insta::assert_snapshot!(stderr, @r###"
insta::assert_snapshot!(stderr, @r#"
Error: The "@" expression resolved to more than one operation
Hint: Try specifying one of the operations by ID: e31015019d90, 48f4a48f3f70
"###);
Hint: Try specifying one of the operations by ID: 0162305507cc, d74dff64472e
"#);

// "op log --at-op" should work without merging the head operations
let stdout = test_env.jj_cmd_success(&repo_path, &["op", "log", "--at-op=48f4a48f3f70"]);
insta::assert_snapshot!(stdout, @r###"
@ 48f4a48f3f70 [email protected] 2001-02-03 04:05:09.000 +07:00 - 2001-02-03 04:05:09.000 +07:00
let stdout = test_env.jj_cmd_success(&repo_path, &["op", "log", "--at-op=d74dff64472e"]);
insta::assert_snapshot!(stdout, @r#"
@ d74dff64472e [email protected] 2001-02-03 04:05:09.000 +07:00 - 2001-02-03 04:05:09.000 +07:00
│ describe commit 230dd059e1b059aefc0da06a2e5a7dbf22362f22
│ args: jj describe -m 'message 2' --at-op @-
b51416386f26 [email protected] 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00
eac759b9ab75 [email protected] 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00
│ add workspace 'default'
○ 9a7d829846af [email protected] 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00
│ initialize repo
○ 000000000000 root()
"###);
"#);

// We should be informed about the concurrent modification
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["log", "-T", "description"]);
Expand All @@ -72,19 +70,17 @@ fn test_concurrent_operations_auto_rebase() {
std::fs::write(repo_path.join("file"), "contents").unwrap();
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "initial"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["op", "log"]);
insta::assert_snapshot!(stdout, @r###"
@ 66d1dd775c54 [email protected] 2001-02-03 04:05:08.000 +07:00 - 2001-02-03 04:05:08.000 +07:00
insta::assert_snapshot!(stdout, @r#"
@ c62ace5c0522 [email protected] 2001-02-03 04:05:08.000 +07:00 - 2001-02-03 04:05:08.000 +07:00
│ describe commit 4e8f9d2be039994f589b4e57ac5e9488703e604d
│ args: jj describe -m initial
130d67859810 [email protected] 2001-02-03 04:05:08.000 +07:00 - 2001-02-03 04:05:08.000 +07:00
82d32fc68fc3 [email protected] 2001-02-03 04:05:08.000 +07:00 - 2001-02-03 04:05:08.000 +07:00
│ snapshot working copy
│ args: jj describe -m initial
b51416386f26 [email protected] 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00
eac759b9ab75 [email protected] 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00
│ add workspace 'default'
○ 9a7d829846af [email protected] 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00
│ initialize repo
○ 000000000000 root()
"###);
"#);
let op_id_hex = stdout[3..15].to_string();

test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "rewritten"]);
Expand Down Expand Up @@ -152,7 +148,7 @@ fn test_concurrent_operations_wc_modified() {

// The working copy should be committed after merging the operations
let stdout = test_env.jj_cmd_success(&repo_path, &["op", "log", "-Tdescription"]);
insta::assert_snapshot!(stdout, @r###"
insta::assert_snapshot!(stdout, @r#"
@ snapshot working copy
○ reconcile divergent operations
├─╮
Expand All @@ -162,9 +158,8 @@ fn test_concurrent_operations_wc_modified() {
○ describe commit 506f4ec3c2c62befa15fabc34ca9d4e6d7bef254
○ snapshot working copy
○ add workspace 'default'
○ initialize repo
"###);
"#);
}

#[test]
Expand All @@ -187,26 +182,24 @@ fn test_concurrent_snapshot_wc_reloadable() {

let template = r#"id ++ "\n" ++ description ++ "\n" ++ tags"#;
let op_log_stdout = test_env.jj_cmd_success(&repo_path, &["op", "log", "-T", template]);
insta::assert_snapshot!(op_log_stdout, @r###"
@ 9f11958bcf79340028eeabf9b0381cd8d2ae2258d0097b8ce8bd24fe7138eca08d9eb113bb4722ebacd9b7a6fa017e3888f72907be7487f275823c8d21359eed
insta::assert_snapshot!(op_log_stdout, @r#"
@ ec6bf266624bbaed55833a34ae62fa95c0e9efa651b94eb28846972da645845052dcdc8580332a5628849f23f48b9e99fc728dc3fb13106df8d0666d746f8b85
│ commit 554d22b2c43c1c47e279430197363e8daabe2fd6
│ args: jj commit -m 'new child1'
f5460e8f43a04fbc61553d12fa5ba8d3b12e4fdcfda1999db6b67cc8e1e473b7e62cc0536196a53b84f34e18c1c6d608f427bb64bd5f834f845a9859e39cb320
23858df860b789e8176a73c0eb21804e3f1848f26d68b70d234c004d08980c41499b6669042bca20fbc2543c437222a084c7cd473e91c7a9a095a02bf38544ab
│ snapshot working copy
│ args: jj commit -m 'new child1'
49359b6597ead3fbb66802a6bbd8761c0ad4646a2b089090d6fd72fb6e2568aa99c4a92f9f1f252a83cce56ec84961c36e85f731f19fc5a4c24d6a3f7282b774
e1db5fa988fc66e5cc0491b00c53fb93e25e730341c850cb42e1e0db0c76d2b4065005787563301b1d292c104f381918897f7deabeb92d2532f42ce75d3fe588
│ commit de71e09289762a65f80bb1c3dae2a949df6bcde7
│ args: jj commit -m initial
86dbba2b96a4a801abef7f77f8fdf338b6e36f81ea4a531aacf06acbd06f4037731fffef42503c2225fdb206488971c1601ca8b2b4a83a3fe2dce64ee4db085e
7de878155a459b7751097222132c935f9dcbb8f69a72b0f3a9036345a963010a553dc7c92964220128679ead72b087ca3aaf4ab9e20a221d1ffa4f9e92a32193
│ snapshot working copy
│ args: jj commit -m initial
b51416386f2685fd5493f2b20e8eec3c24a1776d9e1a7cb5ed7e30d2d9c88c0c1e1fe71b0b7358cba60de42533d1228ed9878f2f89817d892c803395ccf9fe92
eac759b9ab75793fd3da96e60939fb48f2cd2b2a9c1f13ffe723cf620f3005b8d3e7e923634a07ea39513e4f2f360c87b9ad5d331cf90d7a844864b83b72eba1
│ add workspace 'default'
○ 9a7d829846af88a2f7a1e348fb46ff58729e49632bc9c6a052aec8501563cb0d10f4a4e6010ffde529f84a2b9b5b3a4c211a889106a41f6c076dfdacc79f6af7
│ initialize repo
○ 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

"###);
"#);
let op_log_lines = op_log_stdout.lines().collect_vec();
let current_op_id = op_log_lines[0].split_once(" ").unwrap().1;
let previous_op_id = op_log_lines[6].split_once(" ").unwrap().1;
Expand Down
6 changes: 3 additions & 3 deletions cli/tests/test_debug_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,9 @@ fn test_debug_operation_id() {
let workspace_path = test_env.env_root().join("repo");
let stdout =
test_env.jj_cmd_success(&workspace_path, &["debug", "operation", "--display", "id"]);
assert_snapshot!(filter_index_stats(&stdout), @r###"
b51416386f2685fd5493f2b20e8eec3c24a1776d9e1a7cb5ed7e30d2d9c88c0c1e1fe71b0b7358cba60de42533d1228ed9878f2f89817d892c803395ccf9fe92
"###
assert_snapshot!(filter_index_stats(&stdout), @r#"
eac759b9ab75793fd3da96e60939fb48f2cd2b2a9c1f13ffe723cf620f3005b8d3e7e923634a07ea39513e4f2f360c87b9ad5d331cf90d7a844864b83b72eba1
"#
);
}

Expand Down
4 changes: 2 additions & 2 deletions cli/tests/test_duplicate_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ fn test_duplicate() {
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["undo"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @r#"
Undid operation c4b0b2a977fe 2001-02-03 04:05:17.000 +07:00 - 2001-02-03 04:05:17.000 +07:00 duplicate 1 commit(s)
Undid operation b5bdbb51ab28 2001-02-03 04:05:17.000 +07:00 - 2001-02-03 04:05:17.000 +07:00 duplicate 1 commit(s)
"#);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["duplicate" /* duplicates `c` */]);
insta::assert_snapshot!(stdout, @"");
Expand Down Expand Up @@ -280,7 +280,7 @@ fn test_undo_after_duplicate() {
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["undo"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @r#"
Undid operation 5a2bcfcdd78b 2001-02-03 04:05:11.000 +07:00 - 2001-02-03 04:05:11.000 +07:00 duplicate 1 commit(s)
Undid operation e3dbefa46ed5 2001-02-03 04:05:11.000 +07:00 - 2001-02-03 04:05:11.000 +07:00 duplicate 1 commit(s)
"#);
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ 2443ea76b0b1 a
Expand Down
6 changes: 3 additions & 3 deletions cli/tests/test_git_clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,11 +475,11 @@ fn test_git_clone_ignore_working_copy() {

// TODO: Correct, but might be better to check out the root commit?
let stderr = test_env.jj_cmd_failure(&clone_path, &["status"]);
insta::assert_snapshot!(stderr, @r###"
Error: The working copy is stale (not updated since operation b51416386f26).
insta::assert_snapshot!(stderr, @r##"
Error: The working copy is stale (not updated since operation eac759b9ab75).
Hint: Run `jj workspace update-stale` to update it.
See https://martinvonz.github.io/jj/latest/working-copy/#stale-working-copy for more information.
"###);
"##);
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion cli/tests/test_git_colocated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ fn test_git_colocated_undo_head_move() {
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["undo"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @r#"
Undid operation 951a1c249028 2001-02-03 04:05:13.000 +07:00 - 2001-02-03 04:05:13.000 +07:00 new empty commit
Undid operation b50ec983d1c1 2001-02-03 04:05:13.000 +07:00 - 2001-02-03 04:05:13.000 +07:00 new empty commit
Working copy now at: royxmykx eb08b363 (empty) (no description set)
Parent commit : qpvuntsm 230dd059 (empty) (no description set)
"#);
Expand Down
6 changes: 3 additions & 3 deletions cli/tests/test_git_fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ fn test_git_fetch_undo() {
let (stdout, stderr) = test_env.jj_cmd_ok(&target_jj_repo_path, &["undo"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @r#"
Undid operation bbebbf6a6ebe 2001-02-03 04:05:18.000 +07:00 - 2001-02-03 04:05:18.000 +07:00 fetch from git remote(s) origin
Undid operation eb2029853b02 2001-02-03 04:05:18.000 +07:00 - 2001-02-03 04:05:18.000 +07:00 fetch from git remote(s) origin
"#);
// The undo works as expected
insta::assert_snapshot!(get_log_output(&test_env, &target_jj_repo_path), @r###"
Expand Down Expand Up @@ -1018,7 +1018,7 @@ fn test_fetch_undo_what() {
);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @r#"
Restored to operation b51416386f26 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00 add workspace 'default'
Restored to operation eac759b9ab75 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00 add workspace 'default'
"#);
insta::assert_snapshot!(get_bookmark_output(&test_env, &repo_path), @r###"
b (deleted)
Expand Down Expand Up @@ -1047,7 +1047,7 @@ fn test_fetch_undo_what() {
);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @r#"
Restored to operation b51416386f26 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00 add workspace 'default'
Restored to operation eac759b9ab75 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00 add workspace 'default'
"#);
insta::assert_snapshot!(get_bookmark_output(&test_env, &repo_path), @r###"
newbookmark: qpvuntsm 230dd059 (empty) (no description set)
Expand Down
6 changes: 3 additions & 3 deletions cli/tests/test_git_import_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ fn test_git_export_undo() {
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["op", "undo"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @r#"
Undid operation 1bc51ad79d63 2001-02-03 04:05:10.000 +07:00 - 2001-02-03 04:05:10.000 +07:00 export git refs
Undid operation b27a68390bea 2001-02-03 04:05:10.000 +07:00 - 2001-02-03 04:05:10.000 +07:00 export git refs
"#);
insta::assert_debug_snapshot!(get_git_repo_refs(&git_repo), @r###"
[
Expand Down Expand Up @@ -162,7 +162,7 @@ fn test_git_import_undo() {
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["op", "restore", &base_operation_id]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @r#"
Restored to operation b51416386f26 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00 add workspace 'default'
Restored to operation eac759b9ab75 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00 add workspace 'default'
"#);
insta::assert_snapshot!(get_bookmark_output(&test_env, &repo_path), @"");
// Try "git import" again, which should re-import the bookmark "a".
Expand Down Expand Up @@ -228,7 +228,7 @@ fn test_git_import_move_export_with_default_undo() {
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["op", "restore", &base_operation_id]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @r#"
Restored to operation b51416386f26 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00 add workspace 'default'
Restored to operation eac759b9ab75 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00 add workspace 'default'
Working copy now at: qpvuntsm 230dd059 (empty) (no description set)
Parent commit : zzzzzzzz 00000000 (empty) (no description set)
"#);
Expand Down
Loading