2022-11-26 23:57:50 +00:00
|
|
|
// Copyright 2020 The Jujutsu Authors
|
2020-12-12 08:00:42 +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-07-08 09:23:32 +00:00
|
|
|
use std::fs::{self, OpenOptions};
|
2021-10-21 05:09:09 +00:00
|
|
|
use std::io::{Read, Write};
|
2022-03-30 05:14:39 +00:00
|
|
|
use std::path::{Path, PathBuf};
|
2022-11-01 01:29:45 +00:00
|
|
|
use std::sync::{Arc, Once};
|
2020-12-12 08:00:42 +00:00
|
|
|
|
2021-06-09 20:57:48 +00:00
|
|
|
use itertools::Itertools;
|
2023-06-28 14:12:40 +00:00
|
|
|
use jj_lib::backend::{Backend, BackendInitError, FileId, ObjectId, TreeId, TreeValue};
|
|
|
|
use jj_lib::commit::Commit;
|
|
|
|
use jj_lib::commit_builder::CommitBuilder;
|
|
|
|
use jj_lib::git_backend::GitBackend;
|
|
|
|
use jj_lib::local_backend::LocalBackend;
|
|
|
|
use jj_lib::repo::{MutableRepo, ReadonlyRepo, Repo, RepoLoader, StoreFactories};
|
|
|
|
use jj_lib::repo_path::RepoPath;
|
|
|
|
use jj_lib::rewrite::RebasedDescendant;
|
|
|
|
use jj_lib::settings::UserSettings;
|
|
|
|
use jj_lib::store::Store;
|
2023-08-09 08:14:10 +00:00
|
|
|
use jj_lib::transaction::Transaction;
|
2023-06-28 14:12:40 +00:00
|
|
|
use jj_lib::tree::Tree;
|
|
|
|
use jj_lib::tree_builder::TreeBuilder;
|
2023-08-14 23:34:46 +00:00
|
|
|
use jj_lib::working_copy::{SnapshotError, SnapshotOptions};
|
2023-06-28 14:12:40 +00:00
|
|
|
use jj_lib::workspace::Workspace;
|
2020-12-12 08:00:42 +00:00
|
|
|
use tempfile::TempDir;
|
|
|
|
|
2022-11-01 01:29:45 +00:00
|
|
|
pub fn hermetic_libgit2() {
|
2022-10-23 17:16:14 +00:00
|
|
|
// libgit2 respects init.defaultBranch (and possibly other config
|
|
|
|
// variables) in the user's config files. Disable access to them to make
|
|
|
|
// our tests hermetic.
|
|
|
|
//
|
|
|
|
// set_search_path is unsafe because it cannot guarantee thread safety (as
|
|
|
|
// its documentation states). For the same reason, we wrap these invocations
|
2022-11-01 01:29:45 +00:00
|
|
|
// in `call_once`.
|
|
|
|
static CONFIGURE_GIT2: Once = Once::new();
|
|
|
|
CONFIGURE_GIT2.call_once(|| unsafe {
|
|
|
|
git2::opts::set_search_path(git2::ConfigLevel::System, "").unwrap();
|
|
|
|
git2::opts::set_search_path(git2::ConfigLevel::Global, "").unwrap();
|
|
|
|
git2::opts::set_search_path(git2::ConfigLevel::XDG, "").unwrap();
|
|
|
|
git2::opts::set_search_path(git2::ConfigLevel::ProgramData, "").unwrap();
|
|
|
|
});
|
2022-10-23 17:16:14 +00:00
|
|
|
}
|
|
|
|
|
2022-09-07 03:25:03 +00:00
|
|
|
pub fn new_temp_dir() -> TempDir {
|
2022-10-23 17:47:27 +00:00
|
|
|
hermetic_libgit2();
|
2022-09-07 03:25:03 +00:00
|
|
|
tempfile::Builder::new()
|
|
|
|
.prefix("jj-test-")
|
|
|
|
.tempdir()
|
|
|
|
.unwrap()
|
|
|
|
}
|
|
|
|
|
2023-08-14 23:34:46 +00:00
|
|
|
pub fn base_config() -> config::ConfigBuilder<config::builder::DefaultState> {
|
|
|
|
config::Config::builder().add_source(config::File::from_str(
|
|
|
|
r#"
|
|
|
|
user.name = "Test User"
|
|
|
|
user.email = "test.user@example.com"
|
|
|
|
operation.username = "test-username"
|
|
|
|
operation.hostname = "host.example.com"
|
|
|
|
debug.randomness-seed = "42"
|
|
|
|
"#,
|
|
|
|
config::FileFormat::Toml,
|
|
|
|
))
|
|
|
|
}
|
|
|
|
|
2020-12-12 08:00:42 +00:00
|
|
|
pub fn user_settings() -> UserSettings {
|
2023-08-14 23:34:46 +00:00
|
|
|
let config = base_config().build().unwrap();
|
2020-12-12 08:00:42 +00:00
|
|
|
UserSettings::from_config(config)
|
|
|
|
}
|
|
|
|
|
2022-02-05 21:04:30 +00:00
|
|
|
pub struct TestRepo {
|
2022-03-30 05:14:39 +00:00
|
|
|
_temp_dir: TempDir,
|
2022-02-05 21:04:30 +00:00
|
|
|
pub repo: Arc<ReadonlyRepo>,
|
|
|
|
}
|
|
|
|
|
2022-05-21 17:55:51 +00:00
|
|
|
impl TestRepo {
|
2022-05-21 18:20:51 +00:00
|
|
|
pub fn init(use_git: bool) -> Self {
|
|
|
|
let settings = user_settings();
|
2022-09-07 03:25:03 +00:00
|
|
|
let temp_dir = new_temp_dir();
|
2022-05-21 17:55:51 +00:00
|
|
|
|
|
|
|
let repo_dir = temp_dir.path().join("repo");
|
|
|
|
fs::create_dir(&repo_dir).unwrap();
|
|
|
|
|
|
|
|
let repo = if use_git {
|
|
|
|
let git_path = temp_dir.path().join("git-repo");
|
|
|
|
git2::Repository::init(&git_path).unwrap();
|
2022-12-14 18:22:12 +00:00
|
|
|
ReadonlyRepo::init(
|
|
|
|
&settings,
|
|
|
|
&repo_dir,
|
2023-07-06 04:20:24 +00:00
|
|
|
|store_path| -> Result<Box<dyn Backend>, BackendInitError> {
|
2023-06-10 03:31:37 +00:00
|
|
|
Ok(Box::new(GitBackend::init_external(store_path, &git_path)?))
|
|
|
|
},
|
2022-12-14 18:22:12 +00:00
|
|
|
ReadonlyRepo::default_op_store_factory(),
|
2022-12-15 23:47:31 +00:00
|
|
|
ReadonlyRepo::default_op_heads_store_factory(),
|
2023-02-26 20:38:53 +00:00
|
|
|
ReadonlyRepo::default_index_store_factory(),
|
2023-05-15 22:28:55 +00:00
|
|
|
ReadonlyRepo::default_submodule_store_factory(),
|
2022-12-14 18:22:12 +00:00
|
|
|
)
|
2022-10-28 04:27:53 +00:00
|
|
|
.unwrap()
|
2022-05-21 17:55:51 +00:00
|
|
|
} else {
|
2022-12-14 18:22:12 +00:00
|
|
|
ReadonlyRepo::init(
|
|
|
|
&settings,
|
|
|
|
&repo_dir,
|
2023-07-06 04:20:24 +00:00
|
|
|
|store_path| -> Result<Box<dyn Backend>, BackendInitError> {
|
2023-06-10 03:31:37 +00:00
|
|
|
Ok(Box::new(LocalBackend::init(store_path)))
|
|
|
|
},
|
2022-12-14 18:22:12 +00:00
|
|
|
ReadonlyRepo::default_op_store_factory(),
|
2022-12-15 23:47:31 +00:00
|
|
|
ReadonlyRepo::default_op_heads_store_factory(),
|
2023-02-26 20:38:53 +00:00
|
|
|
ReadonlyRepo::default_index_store_factory(),
|
2023-05-15 22:28:55 +00:00
|
|
|
ReadonlyRepo::default_submodule_store_factory(),
|
2022-12-14 18:22:12 +00:00
|
|
|
)
|
2022-10-28 04:27:53 +00:00
|
|
|
.unwrap()
|
2022-05-21 17:55:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Self {
|
|
|
|
_temp_dir: temp_dir,
|
|
|
|
repo,
|
|
|
|
}
|
2022-03-30 05:14:39 +00:00
|
|
|
}
|
2022-02-05 21:04:30 +00:00
|
|
|
}
|
|
|
|
|
2021-11-21 07:46:54 +00:00
|
|
|
pub struct TestWorkspace {
|
2022-03-30 05:14:39 +00:00
|
|
|
temp_dir: TempDir,
|
2021-11-21 07:46:54 +00:00
|
|
|
pub workspace: Workspace,
|
|
|
|
pub repo: Arc<ReadonlyRepo>,
|
2023-08-14 23:34:46 +00:00
|
|
|
settings: UserSettings,
|
2021-11-21 07:46:54 +00:00
|
|
|
}
|
|
|
|
|
2022-05-21 17:55:51 +00:00
|
|
|
impl TestWorkspace {
|
|
|
|
pub fn init(settings: &UserSettings, use_git: bool) -> Self {
|
2022-09-07 03:25:03 +00:00
|
|
|
let temp_dir = new_temp_dir();
|
2022-05-21 17:55:51 +00:00
|
|
|
|
|
|
|
let workspace_root = temp_dir.path().join("repo");
|
|
|
|
fs::create_dir(&workspace_root).unwrap();
|
|
|
|
|
|
|
|
let (workspace, repo) = if use_git {
|
|
|
|
let git_path = temp_dir.path().join("git-repo");
|
|
|
|
git2::Repository::init(&git_path).unwrap();
|
2022-09-23 21:03:43 +00:00
|
|
|
Workspace::init_external_git(settings, &workspace_root, &git_path).unwrap()
|
2022-05-21 17:55:51 +00:00
|
|
|
} else {
|
2022-09-23 21:03:43 +00:00
|
|
|
Workspace::init_local(settings, &workspace_root).unwrap()
|
2022-05-21 17:55:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Self {
|
|
|
|
temp_dir,
|
|
|
|
workspace,
|
|
|
|
repo,
|
2023-08-14 23:34:46 +00:00
|
|
|
settings: settings.clone(),
|
2022-05-21 17:55:51 +00:00
|
|
|
}
|
2021-11-21 07:46:54 +00:00
|
|
|
}
|
2020-12-12 08:00:42 +00:00
|
|
|
|
2022-03-30 05:14:39 +00:00
|
|
|
pub fn root_dir(&self) -> PathBuf {
|
|
|
|
self.temp_dir.path().join("repo").join("..")
|
|
|
|
}
|
2023-07-27 16:52:36 +00:00
|
|
|
|
|
|
|
/// Snapshots the working copy and returns the tree. Updates the working
|
|
|
|
/// copy state on disk, but does not update the working-copy commit (no
|
|
|
|
/// new operation).
|
2023-08-14 23:34:46 +00:00
|
|
|
pub fn snapshot(&mut self) -> Result<Tree, SnapshotError> {
|
2023-07-27 16:52:36 +00:00
|
|
|
let mut locked_wc = self.workspace.working_copy_mut().start_mutation().unwrap();
|
2023-08-14 23:34:46 +00:00
|
|
|
let tree_id = locked_wc.snapshot(SnapshotOptions {
|
|
|
|
max_new_file_size: self.settings.max_new_file_size().unwrap(),
|
|
|
|
..SnapshotOptions::empty_for_test()
|
2023-08-26 00:24:56 +00:00
|
|
|
})?;
|
2023-07-27 16:52:36 +00:00
|
|
|
// arbitrary operation id
|
|
|
|
locked_wc.finish(self.repo.op_id().clone()).unwrap();
|
2023-08-14 23:34:46 +00:00
|
|
|
Ok(self
|
2023-07-27 16:52:36 +00:00
|
|
|
.repo
|
|
|
|
.store()
|
2023-08-26 00:24:56 +00:00
|
|
|
.get_tree(&RepoPath::root(), &tree_id.to_legacy_tree_id())
|
2023-08-14 23:34:46 +00:00
|
|
|
.unwrap())
|
2023-07-27 16:52:36 +00:00
|
|
|
}
|
2022-03-30 05:14:39 +00:00
|
|
|
}
|
|
|
|
|
2023-02-26 23:27:59 +00:00
|
|
|
pub fn load_repo_at_head(settings: &UserSettings, repo_path: &Path) -> Arc<ReadonlyRepo> {
|
|
|
|
RepoLoader::init(settings, repo_path, &StoreFactories::default())
|
2023-02-26 21:50:11 +00:00
|
|
|
.unwrap()
|
2023-02-26 23:27:59 +00:00
|
|
|
.load_at_head(settings)
|
|
|
|
.unwrap()
|
|
|
|
}
|
|
|
|
|
2023-08-09 08:14:10 +00:00
|
|
|
pub fn commit_transactions(settings: &UserSettings, txs: Vec<Transaction>) -> Arc<ReadonlyRepo> {
|
|
|
|
let repo_loader = txs[0].base_repo().loader();
|
|
|
|
let mut op_ids = vec![];
|
|
|
|
for tx in txs {
|
|
|
|
op_ids.push(tx.commit().op_id().clone());
|
|
|
|
std::thread::sleep(std::time::Duration::from_millis(1));
|
|
|
|
}
|
|
|
|
let repo = repo_loader.load_at_head(settings).unwrap();
|
|
|
|
// Test the setup. The assumption here is that the parent order matches the
|
|
|
|
// order in which they were merged (which currently matches the transaction
|
|
|
|
// commit order), so we want to know make sure they appear in a certain
|
|
|
|
// order, so the caller can decide the order by passing them to this
|
|
|
|
// function in a certain order.
|
|
|
|
assert_eq!(*repo.operation().parent_ids(), op_ids);
|
|
|
|
repo
|
|
|
|
}
|
|
|
|
|
2021-10-21 05:09:09 +00:00
|
|
|
pub fn read_file(store: &Store, path: &RepoPath, id: &FileId) -> Vec<u8> {
|
|
|
|
let mut reader = store.read_file(path, id).unwrap();
|
|
|
|
let mut content = vec![];
|
|
|
|
reader.read_to_end(&mut content).unwrap();
|
|
|
|
content
|
|
|
|
}
|
|
|
|
|
2021-09-12 06:52:38 +00:00
|
|
|
pub fn write_file(store: &Store, path: &RepoPath, contents: &str) -> FileId {
|
2020-12-12 08:00:42 +00:00
|
|
|
store.write_file(path, &mut contents.as_bytes()).unwrap()
|
|
|
|
}
|
|
|
|
|
2023-06-20 14:37:31 +00:00
|
|
|
pub fn write_normal_file(
|
|
|
|
tree_builder: &mut TreeBuilder,
|
|
|
|
path: &RepoPath,
|
|
|
|
contents: &str,
|
|
|
|
) -> FileId {
|
2021-10-30 05:13:35 +00:00
|
|
|
let id = write_file(tree_builder.store(), path, contents);
|
2020-12-12 08:00:42 +00:00
|
|
|
tree_builder.set(
|
2021-05-17 04:55:51 +00:00
|
|
|
path.clone(),
|
2022-11-14 21:27:18 +00:00
|
|
|
TreeValue::File {
|
2023-06-20 14:37:31 +00:00
|
|
|
id: id.clone(),
|
2020-12-12 08:00:42 +00:00
|
|
|
executable: false,
|
|
|
|
},
|
|
|
|
);
|
2023-06-20 14:37:31 +00:00
|
|
|
id
|
2020-12-12 08:00:42 +00:00
|
|
|
}
|
|
|
|
|
2021-05-17 04:55:51 +00:00
|
|
|
pub fn write_executable_file(tree_builder: &mut TreeBuilder, path: &RepoPath, contents: &str) {
|
2021-10-30 05:13:35 +00:00
|
|
|
let id = write_file(tree_builder.store(), path, contents);
|
2020-12-12 08:00:42 +00:00
|
|
|
tree_builder.set(
|
2021-05-17 04:55:51 +00:00
|
|
|
path.clone(),
|
2022-11-14 21:27:18 +00:00
|
|
|
TreeValue::File {
|
2020-12-12 08:00:42 +00:00
|
|
|
id,
|
|
|
|
executable: true,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-05-17 04:55:51 +00:00
|
|
|
pub fn write_symlink(tree_builder: &mut TreeBuilder, path: &RepoPath, target: &str) {
|
2021-10-30 05:13:35 +00:00
|
|
|
let id = tree_builder.store().write_symlink(path, target).unwrap();
|
2021-05-17 04:55:51 +00:00
|
|
|
tree_builder.set(path.clone(), TreeValue::Symlink(id));
|
2020-12-12 08:00:42 +00:00
|
|
|
}
|
|
|
|
|
2023-02-14 21:51:55 +00:00
|
|
|
pub fn create_tree(repo: &Arc<ReadonlyRepo>, path_contents: &[(&RepoPath, &str)]) -> Tree {
|
2020-12-12 08:00:42 +00:00
|
|
|
let store = repo.store();
|
|
|
|
let mut tree_builder = store.tree_builder(store.empty_tree_id().clone());
|
|
|
|
for (path, contents) in path_contents {
|
|
|
|
write_normal_file(&mut tree_builder, path, contents);
|
|
|
|
}
|
|
|
|
let id = tree_builder.write_tree();
|
2021-05-19 16:41:25 +00:00
|
|
|
store.get_tree(&RepoPath::root(), &id).unwrap()
|
2020-12-12 08:00:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[must_use]
|
2023-02-14 21:51:55 +00:00
|
|
|
pub fn create_random_tree(repo: &Arc<ReadonlyRepo>) -> TreeId {
|
2020-12-12 08:00:42 +00:00
|
|
|
let mut tree_builder = repo
|
|
|
|
.store()
|
|
|
|
.tree_builder(repo.store().empty_tree_id().clone());
|
|
|
|
let number = rand::random::<u32>();
|
2022-12-15 02:30:06 +00:00
|
|
|
let path = RepoPath::from_internal_string(format!("file{number}").as_str());
|
2020-12-12 08:00:42 +00:00
|
|
|
write_normal_file(&mut tree_builder, &path, "contents");
|
|
|
|
tree_builder.write_tree()
|
|
|
|
}
|
|
|
|
|
2022-12-24 17:01:11 +00:00
|
|
|
pub fn create_random_commit<'repo>(
|
|
|
|
mut_repo: &'repo mut MutableRepo,
|
|
|
|
settings: &UserSettings,
|
|
|
|
) -> CommitBuilder<'repo> {
|
|
|
|
let tree_id = create_random_tree(mut_repo.base_repo());
|
2020-12-12 08:00:42 +00:00
|
|
|
let number = rand::random::<u32>();
|
2022-12-25 16:36:13 +00:00
|
|
|
mut_repo
|
|
|
|
.new_commit(
|
|
|
|
settings,
|
|
|
|
vec![mut_repo.store().root_commit_id().clone()],
|
|
|
|
tree_id,
|
|
|
|
)
|
|
|
|
.set_description(format!("random commit {number}"))
|
2020-12-12 08:00:42 +00:00
|
|
|
}
|
|
|
|
|
2023-07-08 09:23:32 +00:00
|
|
|
pub fn dump_tree(store: &Arc<Store>, tree_id: &TreeId) -> String {
|
|
|
|
use std::fmt::Write;
|
|
|
|
let mut buf = String::new();
|
|
|
|
writeln!(&mut buf, "tree {}", tree_id.hex()).unwrap();
|
|
|
|
let tree = store.get_tree(&RepoPath::root(), tree_id).unwrap();
|
|
|
|
for (path, value) in tree.entries() {
|
|
|
|
match value {
|
|
|
|
TreeValue::File { id, executable: _ } => {
|
|
|
|
let file_buf = read_file(store, &path, &id);
|
|
|
|
let file_contents = String::from_utf8_lossy(&file_buf);
|
|
|
|
writeln!(
|
|
|
|
&mut buf,
|
|
|
|
" file {path:?} ({}): {file_contents:?}",
|
|
|
|
id.hex()
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
}
|
|
|
|
TreeValue::Symlink(id) => {
|
|
|
|
writeln!(&mut buf, " symlink {path:?} ({})", id.hex()).unwrap();
|
|
|
|
}
|
|
|
|
TreeValue::Conflict(id) => {
|
|
|
|
writeln!(&mut buf, " conflict {path:?} ({})", id.hex()).unwrap();
|
|
|
|
}
|
|
|
|
TreeValue::GitSubmodule(id) => {
|
|
|
|
writeln!(&mut buf, " submodule {path:?} ({})", id.hex()).unwrap();
|
|
|
|
}
|
|
|
|
entry => {
|
|
|
|
unimplemented!("dumping tree entry {entry:?}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
buf
|
|
|
|
}
|
|
|
|
|
2022-12-24 15:38:20 +00:00
|
|
|
pub fn write_random_commit(mut_repo: &mut MutableRepo, settings: &UserSettings) -> Commit {
|
2022-12-24 05:09:19 +00:00
|
|
|
create_random_commit(mut_repo, settings).write().unwrap()
|
2022-12-24 15:38:20 +00:00
|
|
|
}
|
|
|
|
|
2021-11-21 22:31:44 +00:00
|
|
|
pub fn write_working_copy_file(workspace_root: &Path, path: &RepoPath, contents: &str) {
|
2023-07-08 09:23:32 +00:00
|
|
|
let path = path.to_fs_path(workspace_root);
|
|
|
|
if let Some(parent) = path.parent() {
|
|
|
|
fs::create_dir_all(parent).unwrap();
|
|
|
|
}
|
2020-12-12 08:00:42 +00:00
|
|
|
let mut file = OpenOptions::new()
|
|
|
|
.write(true)
|
|
|
|
.create(true)
|
|
|
|
.truncate(true)
|
2023-07-08 09:23:32 +00:00
|
|
|
.open(path)
|
2020-12-12 08:00:42 +00:00
|
|
|
.unwrap();
|
|
|
|
file.write_all(contents.as_bytes()).unwrap();
|
|
|
|
}
|
2021-05-01 04:41:27 +00:00
|
|
|
|
|
|
|
pub struct CommitGraphBuilder<'settings, 'repo> {
|
|
|
|
settings: &'settings UserSettings,
|
|
|
|
mut_repo: &'repo mut MutableRepo,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'settings, 'repo> CommitGraphBuilder<'settings, 'repo> {
|
|
|
|
pub fn new(
|
|
|
|
settings: &'settings UserSettings,
|
|
|
|
mut_repo: &'repo mut MutableRepo,
|
|
|
|
) -> CommitGraphBuilder<'settings, 'repo> {
|
|
|
|
CommitGraphBuilder { settings, mut_repo }
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn initial_commit(&mut self) -> Commit {
|
2022-12-24 15:38:20 +00:00
|
|
|
write_random_commit(self.mut_repo, self.settings)
|
2021-05-01 04:41:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn commit_with_parents(&mut self, parents: &[&Commit]) -> Commit {
|
2021-06-09 20:57:48 +00:00
|
|
|
let parent_ids = parents
|
|
|
|
.iter()
|
|
|
|
.map(|commit| commit.id().clone())
|
|
|
|
.collect_vec();
|
2022-12-24 17:01:11 +00:00
|
|
|
create_random_commit(self.mut_repo, self.settings)
|
2021-05-01 04:41:27 +00:00
|
|
|
.set_parents(parent_ids)
|
2022-12-24 17:01:11 +00:00
|
|
|
.write()
|
2022-12-24 05:09:19 +00:00
|
|
|
.unwrap()
|
2021-05-01 04:41:27 +00:00
|
|
|
}
|
|
|
|
}
|
2021-09-29 18:27:58 +00:00
|
|
|
|
|
|
|
pub fn assert_rebased(
|
|
|
|
rebased: Option<RebasedDescendant>,
|
|
|
|
expected_old_commit: &Commit,
|
|
|
|
expected_new_parents: &[&Commit],
|
|
|
|
) -> Commit {
|
|
|
|
if let Some(RebasedDescendant {
|
|
|
|
old_commit,
|
|
|
|
new_commit,
|
|
|
|
}) = rebased
|
|
|
|
{
|
|
|
|
assert_eq!(old_commit, *expected_old_commit);
|
|
|
|
assert_eq!(new_commit.change_id(), expected_old_commit.change_id());
|
|
|
|
assert_eq!(
|
|
|
|
new_commit.parent_ids(),
|
|
|
|
expected_new_parents
|
|
|
|
.iter()
|
|
|
|
.map(|commit| commit.id().clone())
|
|
|
|
.collect_vec()
|
|
|
|
);
|
|
|
|
new_commit
|
|
|
|
} else {
|
2022-12-15 02:30:06 +00:00
|
|
|
panic!("expected rebased commit: {rebased:?}");
|
2021-09-29 18:27:58 +00:00
|
|
|
}
|
|
|
|
}
|