mirror of
https://github.com/martinvonz/jj.git
synced 2024-12-24 12:48:55 +00:00
tests: avoid accessing working copy just to get its commit ID
The view has been the source of truth for the currently checked-out commit for a long time now.
This commit is contained in:
parent
b35086d4c9
commit
6c0f3625ff
5 changed files with 54 additions and 60 deletions
|
@ -53,13 +53,7 @@ fn test_index_commits_empty_repo(use_git: bool) {
|
|||
generation_number(index.as_ref(), repo.store().root_commit_id()),
|
||||
0
|
||||
);
|
||||
assert_eq!(
|
||||
generation_number(
|
||||
index.as_ref(),
|
||||
&repo.working_copy_locked().current_commit_id()
|
||||
),
|
||||
1
|
||||
);
|
||||
assert_eq!(generation_number(index.as_ref(), repo.view().checkout()), 1);
|
||||
}
|
||||
|
||||
#[test_case(false ; "local backend")]
|
||||
|
@ -82,8 +76,8 @@ fn test_index_commits_standard_cases(use_git: bool) {
|
|||
// |/
|
||||
// o root
|
||||
|
||||
let root_commit = repo.store().root_commit();
|
||||
let wc_commit = repo.working_copy_locked().current_commit();
|
||||
let root_commit_id = repo.store().root_commit_id();
|
||||
let checkout_id = repo.view().checkout().clone();
|
||||
let mut tx = repo.start_transaction("test");
|
||||
let mut graph_builder = CommitGraphBuilder::new(&settings, tx.mut_repo());
|
||||
let commit_a = graph_builder.initial_commit();
|
||||
|
@ -106,8 +100,8 @@ fn test_index_commits_standard_cases(use_git: bool) {
|
|||
assert_eq!(stats.num_merges, 1);
|
||||
assert_eq!(stats.max_generation_number, 6);
|
||||
|
||||
assert_eq!(generation_number(index.as_ref(), root_commit.id()), 0);
|
||||
assert_eq!(generation_number(index.as_ref(), wc_commit.id()), 1);
|
||||
assert_eq!(generation_number(index.as_ref(), root_commit_id), 0);
|
||||
assert_eq!(generation_number(index.as_ref(), &checkout_id), 1);
|
||||
assert_eq!(generation_number(index.as_ref(), commit_a.id()), 1);
|
||||
assert_eq!(generation_number(index.as_ref(), commit_b.id()), 2);
|
||||
assert_eq!(generation_number(index.as_ref(), commit_c.id()), 2);
|
||||
|
@ -117,11 +111,11 @@ fn test_index_commits_standard_cases(use_git: bool) {
|
|||
assert_eq!(generation_number(index.as_ref(), commit_g.id()), 6);
|
||||
assert_eq!(generation_number(index.as_ref(), commit_h.id()), 5);
|
||||
|
||||
assert!(index.is_ancestor(root_commit.id(), commit_a.id()));
|
||||
assert!(!index.is_ancestor(commit_a.id(), root_commit.id()));
|
||||
assert!(index.is_ancestor(root_commit_id, commit_a.id()));
|
||||
assert!(!index.is_ancestor(commit_a.id(), root_commit_id));
|
||||
|
||||
assert!(index.is_ancestor(root_commit.id(), commit_b.id()));
|
||||
assert!(!index.is_ancestor(commit_b.id(), root_commit.id()));
|
||||
assert!(index.is_ancestor(root_commit_id, commit_b.id()));
|
||||
assert!(!index.is_ancestor(commit_b.id(), root_commit_id));
|
||||
|
||||
assert!(!index.is_ancestor(commit_b.id(), commit_c.id()));
|
||||
|
||||
|
|
|
@ -74,18 +74,22 @@ fn test_init_no_config_set(use_git: bool) {
|
|||
// Test that we can create a repo without setting any config
|
||||
let settings = UserSettings::from_config(config::Config::new());
|
||||
let (_temp_dir, repo) = testutils::init_repo(&settings, use_git);
|
||||
let wc_commit = repo.working_copy_locked().current_commit();
|
||||
assert_eq!(wc_commit.author().name, "(no name configured)".to_string());
|
||||
let checkout_id = repo.view().checkout();
|
||||
let checkout_commit = repo.store().get_commit(checkout_id).unwrap();
|
||||
assert_eq!(
|
||||
wc_commit.author().email,
|
||||
"(no email configured)".to_string()
|
||||
);
|
||||
assert_eq!(
|
||||
wc_commit.committer().name,
|
||||
checkout_commit.author().name,
|
||||
"(no name configured)".to_string()
|
||||
);
|
||||
assert_eq!(
|
||||
wc_commit.committer().email,
|
||||
checkout_commit.author().email,
|
||||
"(no email configured)".to_string()
|
||||
);
|
||||
assert_eq!(
|
||||
checkout_commit.committer().name,
|
||||
"(no name configured)".to_string()
|
||||
);
|
||||
assert_eq!(
|
||||
checkout_commit.committer().email,
|
||||
"(no email configured)".to_string()
|
||||
);
|
||||
}
|
||||
|
|
|
@ -132,7 +132,7 @@ fn test_isolation(use_git: bool) {
|
|||
let settings = testutils::user_settings();
|
||||
let (_temp_dir, repo) = testutils::init_repo(&settings, use_git);
|
||||
|
||||
let wc_id = repo.working_copy_locked().current_commit_id();
|
||||
let checkout_id = repo.view().checkout().clone();
|
||||
let mut tx = repo.start_transaction("test");
|
||||
let initial = testutils::create_random_commit(&settings, &repo)
|
||||
.set_parents(vec![repo.store().root_commit_id().clone()])
|
||||
|
@ -144,9 +144,9 @@ fn test_isolation(use_git: bool) {
|
|||
let mut tx2 = repo.start_transaction("transaction 2");
|
||||
let mut_repo2 = tx2.mut_repo();
|
||||
|
||||
assert_heads(repo.as_repo_ref(), vec![&wc_id, initial.id()]);
|
||||
assert_heads(mut_repo1.as_repo_ref(), vec![&wc_id, initial.id()]);
|
||||
assert_heads(mut_repo2.as_repo_ref(), vec![&wc_id, initial.id()]);
|
||||
assert_heads(repo.as_repo_ref(), vec![&checkout_id, initial.id()]);
|
||||
assert_heads(mut_repo1.as_repo_ref(), vec![&checkout_id, initial.id()]);
|
||||
assert_heads(mut_repo2.as_repo_ref(), vec![&checkout_id, initial.id()]);
|
||||
|
||||
let rewrite1 = CommitBuilder::for_rewrite_from(&settings, repo.store(), &initial)
|
||||
.set_description("rewrite1".to_string())
|
||||
|
@ -157,31 +157,31 @@ fn test_isolation(use_git: bool) {
|
|||
|
||||
// Neither transaction has committed yet, so each transaction sees its own
|
||||
// commit.
|
||||
assert_heads(repo.as_repo_ref(), vec![&wc_id, initial.id()]);
|
||||
assert_heads(repo.as_repo_ref(), vec![&checkout_id, initial.id()]);
|
||||
assert_heads(
|
||||
mut_repo1.as_repo_ref(),
|
||||
vec![&wc_id, initial.id(), rewrite1.id()],
|
||||
vec![&checkout_id, initial.id(), rewrite1.id()],
|
||||
);
|
||||
assert_heads(
|
||||
mut_repo2.as_repo_ref(),
|
||||
vec![&wc_id, initial.id(), rewrite2.id()],
|
||||
vec![&checkout_id, initial.id(), rewrite2.id()],
|
||||
);
|
||||
|
||||
// The base repo and tx2 don't see the commits from tx1.
|
||||
tx1.commit();
|
||||
assert_heads(repo.as_repo_ref(), vec![&wc_id, initial.id()]);
|
||||
assert_heads(repo.as_repo_ref(), vec![&checkout_id, initial.id()]);
|
||||
assert_heads(
|
||||
mut_repo2.as_repo_ref(),
|
||||
vec![&wc_id, initial.id(), rewrite2.id()],
|
||||
vec![&checkout_id, initial.id(), rewrite2.id()],
|
||||
);
|
||||
|
||||
// The base repo still doesn't see the commits after both transactions commit.
|
||||
tx2.commit();
|
||||
assert_heads(repo.as_repo_ref(), vec![&wc_id, initial.id()]);
|
||||
assert_heads(repo.as_repo_ref(), vec![&checkout_id, initial.id()]);
|
||||
// After reload, the base repo sees both rewrites.
|
||||
let repo = repo.reload();
|
||||
assert_heads(
|
||||
repo.as_repo_ref(),
|
||||
vec![&wc_id, initial.id(), rewrite1.id(), rewrite2.id()],
|
||||
vec![&checkout_id, initial.id(), rewrite1.id(), rewrite2.id()],
|
||||
);
|
||||
}
|
||||
|
|
|
@ -553,7 +553,7 @@ fn test_evaluate_expression_children(use_git: bool) {
|
|||
let mut tx = repo.start_transaction("test");
|
||||
let mut_repo = tx.mut_repo();
|
||||
|
||||
let wc_commit = repo.working_copy_locked().current_commit();
|
||||
let checkout_id = repo.view().checkout().clone();
|
||||
let commit1 = testutils::create_random_commit(&settings, &repo).write_to_repo(mut_repo);
|
||||
let commit2 = testutils::create_random_commit(&settings, &repo)
|
||||
.set_parents(vec![commit1.id().clone()])
|
||||
|
@ -571,7 +571,7 @@ fn test_evaluate_expression_children(use_git: bool) {
|
|||
// Can find children of the root commit
|
||||
assert_eq!(
|
||||
resolve_commit_ids(mut_repo.as_repo_ref(), "root:"),
|
||||
vec![commit1.id().clone(), wc_commit.id().clone()]
|
||||
vec![commit1.id().clone(), checkout_id]
|
||||
);
|
||||
|
||||
// Children of all commits in input are returned, including those already in the
|
||||
|
@ -707,7 +707,7 @@ fn test_evaluate_expression_dag_range(use_git: bool) {
|
|||
let settings = testutils::user_settings();
|
||||
let (_temp_dir, repo) = testutils::init_repo(&settings, use_git);
|
||||
|
||||
let root_commit = repo.store().root_commit();
|
||||
let root_commit_id = repo.store().root_commit_id().clone();
|
||||
let mut tx = repo.start_transaction("test");
|
||||
let mut_repo = tx.mut_repo();
|
||||
let mut graph_builder = CommitGraphBuilder::new(&settings, mut_repo);
|
||||
|
@ -720,20 +720,16 @@ fn test_evaluate_expression_dag_range(use_git: bool) {
|
|||
// Can get DAG range of just the root commit
|
||||
assert_eq!(
|
||||
resolve_commit_ids(mut_repo.as_repo_ref(), "root,,root"),
|
||||
vec![root_commit.id().clone(),]
|
||||
vec![root_commit_id.clone()]
|
||||
);
|
||||
|
||||
// Linear range
|
||||
assert_eq!(
|
||||
resolve_commit_ids(
|
||||
mut_repo.as_repo_ref(),
|
||||
&format!("{},,{}", root_commit.id().hex(), commit2.id().hex())
|
||||
&format!("{},,{}", root_commit_id.hex(), commit2.id().hex())
|
||||
),
|
||||
vec![
|
||||
commit2.id().clone(),
|
||||
commit1.id().clone(),
|
||||
root_commit.id().clone(),
|
||||
]
|
||||
vec![commit2.id().clone(), commit1.id().clone(), root_commit_id,]
|
||||
);
|
||||
|
||||
// Empty range
|
||||
|
@ -785,8 +781,8 @@ fn test_evaluate_expression_descendants(use_git: bool) {
|
|||
let mut tx = repo.start_transaction("test");
|
||||
let mut_repo = tx.mut_repo();
|
||||
|
||||
let root_commit = repo.store().root_commit();
|
||||
let wc_commit = repo.working_copy_locked().current_commit();
|
||||
let root_commit_id = repo.store().root_commit_id().clone();
|
||||
let checkout_id = repo.view().checkout().clone();
|
||||
let commit1 = testutils::create_random_commit(&settings, &repo).write_to_repo(mut_repo);
|
||||
let commit2 = testutils::create_random_commit(&settings, &repo)
|
||||
.set_parents(vec![commit1.id().clone()])
|
||||
|
@ -810,8 +806,8 @@ fn test_evaluate_expression_descendants(use_git: bool) {
|
|||
commit3.id().clone(),
|
||||
commit2.id().clone(),
|
||||
commit1.id().clone(),
|
||||
wc_commit.id().clone(),
|
||||
root_commit.id().clone(),
|
||||
checkout_id,
|
||||
root_commit_id,
|
||||
]
|
||||
);
|
||||
|
||||
|
@ -846,8 +842,8 @@ fn test_evaluate_expression_all(use_git: bool) {
|
|||
|
||||
let mut tx = repo.start_transaction("test");
|
||||
let mut_repo = tx.mut_repo();
|
||||
let root_commit = repo.store().root_commit();
|
||||
let wc_commit = repo.working_copy_locked().current_commit();
|
||||
let root_commit_id = repo.store().root_commit_id().clone();
|
||||
let checkout_id = repo.view().checkout().clone();
|
||||
let mut graph_builder = CommitGraphBuilder::new(&settings, mut_repo);
|
||||
let commit1 = graph_builder.initial_commit();
|
||||
let commit2 = graph_builder.commit_with_parents(&[&commit1]);
|
||||
|
@ -861,8 +857,8 @@ fn test_evaluate_expression_all(use_git: bool) {
|
|||
commit3.id().clone(),
|
||||
commit2.id().clone(),
|
||||
commit1.id().clone(),
|
||||
wc_commit.id().clone(),
|
||||
root_commit.id().clone(),
|
||||
checkout_id,
|
||||
root_commit_id,
|
||||
]
|
||||
);
|
||||
|
||||
|
@ -877,14 +873,14 @@ fn test_evaluate_expression_heads(use_git: bool) {
|
|||
|
||||
let mut tx = repo.start_transaction("test");
|
||||
let mut_repo = tx.mut_repo();
|
||||
let wc_commit = repo.working_copy_locked().current_commit();
|
||||
let checkout_id = repo.view().checkout().clone();
|
||||
let mut graph_builder = CommitGraphBuilder::new(&settings, mut_repo);
|
||||
let commit1 = graph_builder.initial_commit();
|
||||
let commit2 = graph_builder.commit_with_parents(&[&commit1]);
|
||||
|
||||
assert_eq!(
|
||||
resolve_commit_ids(mut_repo.as_repo_ref(), "heads()"),
|
||||
vec![commit2.id().clone(), wc_commit.id().clone()]
|
||||
vec![commit2.id().clone(), checkout_id]
|
||||
);
|
||||
|
||||
tx.discard();
|
||||
|
|
|
@ -24,8 +24,10 @@ fn test_heads_empty(use_git: bool) {
|
|||
let settings = testutils::user_settings();
|
||||
let (_temp_dir, repo) = testutils::init_repo(&settings, use_git);
|
||||
|
||||
let wc = repo.working_copy_locked();
|
||||
assert_eq!(*repo.view().heads(), hashset! {wc.current_commit_id()});
|
||||
assert_eq!(
|
||||
*repo.view().heads(),
|
||||
hashset! {repo.view().checkout().clone()}
|
||||
);
|
||||
assert_eq!(
|
||||
*repo.view().public_heads(),
|
||||
hashset! {repo.store().root_commit_id().clone()}
|
||||
|
@ -45,11 +47,10 @@ fn test_heads_fork(use_git: bool) {
|
|||
let child2 = graph_builder.commit_with_parents(&[&initial]);
|
||||
let repo = tx.commit();
|
||||
|
||||
let wc = repo.working_copy_locked();
|
||||
assert_eq!(
|
||||
*repo.view().heads(),
|
||||
hashset! {
|
||||
wc.current_commit_id(),
|
||||
repo.view().checkout().clone(),
|
||||
child1.id().clone(),
|
||||
child2.id().clone(),
|
||||
}
|
||||
|
@ -70,10 +71,9 @@ fn test_heads_merge(use_git: bool) {
|
|||
let merge = graph_builder.commit_with_parents(&[&child1, &child2]);
|
||||
let repo = tx.commit();
|
||||
|
||||
let wc = repo.working_copy_locked();
|
||||
assert_eq!(
|
||||
*repo.view().heads(),
|
||||
hashset! {wc.current_commit_id(), merge.id().clone()}
|
||||
hashset! {repo.view().checkout().clone(), merge.id().clone()}
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue