Debian Codegraph @

lib/tests/test_load_repo.rs

raw
1 // Copyright 2021 The Jujutsu Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 use jj_lib::repo::RepoLoader;
16 use pollster::FutureExt as _;
17 use testutils::TestRepo;
18 use testutils::TestResult;
19 use testutils::write_random_commit;
20
21 #[test]
22 fn test_load_at_operation() -> TestResult {
23 let settings = testutils::user_settings();
24 let test_repo = TestRepo::init();
25 let repo = &test_repo.repo;
26
27 let mut tx = repo.start_transaction();
28 let commit = write_random_commit(tx.repo_mut());
29 let repo = tx.commit("add commit").block_on()?;
30
31 let mut tx = repo.start_transaction();
32 tx.repo_mut().remove_head(commit.id());
33 tx.commit("remove commit").block_on()?;
34
35 // If we load the repo at head, we should not see the commit since it was
36 // removed
37 let loader = RepoLoader::init_from_file_system(
38 &settings,
39 test_repo.repo_path(),
40 &test_repo.env.default_backend_factories(),
41 )?;
42 let head_repo = loader.load_at_head().block_on()?;
43 assert!(!head_repo.view().heads().contains(commit.id()));
44
45 // If we load the repo at the previous operation, we should see the commit since
46 // it has not been removed yet
47 let loader = RepoLoader::init_from_file_system(
48 &settings,
49 test_repo.repo_path(),
50 &test_repo.env.default_backend_factories(),
51 )?;
52 let old_repo = loader.load_at(repo.operation()).block_on()?;
53 assert!(old_repo.view().heads().contains(commit.id()));
54 Ok(())
55 }