2022-11-27 02:57:50 +03:00
|
|
|
// Copyright 2021 The Jujutsu Authors
|
2021-01-04 10:11:22 +03:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// https://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2023-06-28 17:12:40 +03:00
|
|
|
use jj_lib::repo::{RepoLoader, StoreFactories};
|
2021-01-04 20:40:46 +03:00
|
|
|
use test_case::test_case;
|
2022-12-24 18:38:20 +03:00
|
|
|
use testutils::{write_random_commit, TestRepo};
|
2021-01-04 10:11:22 +03:00
|
|
|
|
2021-09-12 09:52:38 +03:00
|
|
|
#[test_case(false ; "local backend")]
|
|
|
|
#[test_case(true ; "git backend")]
|
2021-01-04 20:40:46 +03:00
|
|
|
fn test_load_at_operation(use_git: bool) {
|
|
|
|
let settings = testutils::user_settings();
|
2022-05-21 21:20:51 +03:00
|
|
|
let test_repo = TestRepo::init(use_git);
|
2022-02-06 00:41:28 +03:00
|
|
|
let repo = &test_repo.repo;
|
2021-01-04 20:40:46 +03:00
|
|
|
|
2022-11-13 09:29:06 +03:00
|
|
|
let mut tx = repo.start_transaction(&settings, "add commit");
|
2022-12-24 18:38:20 +03:00
|
|
|
let commit = write_random_commit(tx.mut_repo(), &settings);
|
2021-05-19 23:39:03 +03:00
|
|
|
let repo = tx.commit();
|
2021-01-04 20:40:46 +03:00
|
|
|
|
2022-11-13 09:29:06 +03:00
|
|
|
let mut tx = repo.start_transaction(&settings, "remove commit");
|
2021-09-25 19:25:42 +03:00
|
|
|
tx.mut_repo().remove_head(commit.id());
|
2021-01-04 20:40:46 +03:00
|
|
|
tx.commit();
|
|
|
|
|
|
|
|
// If we load the repo at head, we should not see the commit since it was
|
|
|
|
// removed
|
2023-02-27 00:50:11 +03:00
|
|
|
let loader = RepoLoader::init(&settings, repo.repo_path(), &StoreFactories::default()).unwrap();
|
2023-01-12 00:12:17 +03:00
|
|
|
let head_repo = loader.load_at_head(&settings).unwrap();
|
2021-01-04 20:40:46 +03:00
|
|
|
assert!(!head_repo.view().heads().contains(commit.id()));
|
|
|
|
|
|
|
|
// If we load the repo at the previous operation, we should see the commit since
|
|
|
|
// it has not been removed yet
|
2023-02-27 00:50:11 +03:00
|
|
|
let loader = RepoLoader::init(&settings, repo.repo_path(), &StoreFactories::default()).unwrap();
|
2021-06-14 10:18:38 +03:00
|
|
|
let old_repo = loader.load_at(repo.operation());
|
2021-01-04 20:40:46 +03:00
|
|
|
assert!(old_repo.view().heads().contains(commit.id()));
|
|
|
|
}
|