2022-11-26 23:57:50 +00:00
|
|
|
// Copyright 2021 The Jujutsu Authors
|
2021-01-04 07:11:22 +00: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 14:12:40 +00:00
|
|
|
use jj_lib::repo::{RepoLoader, StoreFactories};
|
2021-01-04 17:40:46 +00:00
|
|
|
use test_case::test_case;
|
2022-12-24 15:38:20 +00:00
|
|
|
use testutils::{write_random_commit, TestRepo};
|
2021-01-04 07:11:22 +00:00
|
|
|
|
2021-09-12 06:52:38 +00:00
|
|
|
#[test_case(false ; "local backend")]
|
|
|
|
#[test_case(true ; "git backend")]
|
2021-01-04 17:40:46 +00:00
|
|
|
fn test_load_at_operation(use_git: bool) {
|
|
|
|
let settings = testutils::user_settings();
|
2022-05-21 18:20:51 +00:00
|
|
|
let test_repo = TestRepo::init(use_git);
|
2022-02-05 21:41:28 +00:00
|
|
|
let repo = &test_repo.repo;
|
2021-01-04 17:40:46 +00:00
|
|
|
|
2022-11-13 06:29:06 +00:00
|
|
|
let mut tx = repo.start_transaction(&settings, "add commit");
|
2022-12-24 15:38:20 +00:00
|
|
|
let commit = write_random_commit(tx.mut_repo(), &settings);
|
2021-05-19 20:39:03 +00:00
|
|
|
let repo = tx.commit();
|
2021-01-04 17:40:46 +00:00
|
|
|
|
2022-11-13 06:29:06 +00:00
|
|
|
let mut tx = repo.start_transaction(&settings, "remove commit");
|
2021-09-25 16:25:42 +00:00
|
|
|
tx.mut_repo().remove_head(commit.id());
|
2021-01-04 17:40:46 +00:00
|
|
|
tx.commit();
|
|
|
|
|
|
|
|
// If we load the repo at head, we should not see the commit since it was
|
|
|
|
// removed
|
2023-02-26 21:50:11 +00:00
|
|
|
let loader = RepoLoader::init(&settings, repo.repo_path(), &StoreFactories::default()).unwrap();
|
2023-01-11 21:12:17 +00:00
|
|
|
let head_repo = loader.load_at_head(&settings).unwrap();
|
2021-01-04 17:40:46 +00: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-26 21:50:11 +00:00
|
|
|
let loader = RepoLoader::init(&settings, repo.repo_path(), &StoreFactories::default()).unwrap();
|
2023-07-25 14:40:12 +00:00
|
|
|
let old_repo = loader.load_at(repo.operation()).unwrap();
|
2021-01-04 17:40:46 +00:00
|
|
|
assert!(old_repo.view().heads().contains(commit.id()));
|
|
|
|
}
|