mirror of
https://github.com/martinvonz/jj.git
synced 2024-11-10 05:44:29 +03:00
repo: respect workspace ID for old checkout (#13)
When checking out a new commit, we look at the old checkout to see if it's empty so we should abandon it. We current use the default workspace's checkout. We need to respect the workspace ID we're given in `MutableRepo::check_out()`, and we need to be able to deal with that workspace not existing yet (i.e. this being the first checkout in that workspace).
This commit is contained in:
parent
ac0d040bb5
commit
a41fcb39eb
@ -557,12 +557,14 @@ impl MutableRepo {
|
||||
settings: &UserSettings,
|
||||
commit: &Commit,
|
||||
) -> Commit {
|
||||
let current_checkout_id = self.view.borrow().checkout().clone();
|
||||
let current_checkout = self.store().get_commit(¤t_checkout_id).unwrap();
|
||||
assert!(current_checkout.is_open(), "current checkout is closed");
|
||||
if current_checkout.is_empty() {
|
||||
// Abandon the checkout we're leaving if it's empty.
|
||||
self.record_abandoned_commit(current_checkout_id);
|
||||
let maybe_current_checkout_id = self.view.borrow().get_checkout(&workspace_id).cloned();
|
||||
if let Some(current_checkout_id) = maybe_current_checkout_id {
|
||||
let current_checkout = self.store().get_commit(¤t_checkout_id).unwrap();
|
||||
assert!(current_checkout.is_open(), "current checkout is closed");
|
||||
if current_checkout.is_empty() {
|
||||
// Abandon the checkout we're leaving if it's empty.
|
||||
self.record_abandoned_commit(current_checkout_id);
|
||||
}
|
||||
}
|
||||
let open_commit = if !commit.is_open() {
|
||||
// If the commit is closed, create a new open commit on top
|
||||
|
@ -129,6 +129,34 @@ fn test_checkout_previous_empty(use_git: bool) {
|
||||
assert!(!mut_repo.view().heads().contains(old_checkout.id()));
|
||||
}
|
||||
|
||||
#[test_case(false ; "local backend")]
|
||||
// #[test_case(true ; "git backend")]
|
||||
fn test_checkout_initial(use_git: bool) {
|
||||
// Test that MutableRepo::check_out() can be used on the initial checkout in a
|
||||
// workspace
|
||||
let settings = testutils::user_settings();
|
||||
let test_workspace = testutils::init_repo(&settings, use_git);
|
||||
let repo = &test_workspace.repo;
|
||||
|
||||
let mut tx = repo.start_transaction("test");
|
||||
let requested_checkout = testutils::create_random_commit(&settings, repo)
|
||||
.set_open(true)
|
||||
.write_to_repo(tx.mut_repo());
|
||||
let repo = tx.commit();
|
||||
|
||||
let mut tx = repo.start_transaction("test");
|
||||
let workspace_id = WorkspaceId::new("new-workspace".to_string());
|
||||
let actual_checkout =
|
||||
tx.mut_repo()
|
||||
.check_out(workspace_id.clone(), &settings, &requested_checkout);
|
||||
assert_eq!(actual_checkout.id(), requested_checkout.id());
|
||||
let repo = tx.commit();
|
||||
assert_eq!(
|
||||
repo.view().get_checkout(&workspace_id),
|
||||
Some(actual_checkout.id())
|
||||
);
|
||||
}
|
||||
|
||||
#[test_case(false ; "local backend")]
|
||||
// #[test_case(true ; "git backend")]
|
||||
fn test_add_head_success(use_git: bool) {
|
||||
|
Loading…
Reference in New Issue
Block a user