forked from mirrors/jj
checkout: don't abandon old commit if it has non-empty description
If the user entered a description, we shouldn't abandon it even if it has no changes to the content.
This commit is contained in:
parent
eedc315821
commit
6c6e6cb423
4 changed files with 41 additions and 1 deletions
|
@ -137,6 +137,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
checkout will be checked out. That was always the intent, but the root commit
|
checkout will be checked out. That was always the intent, but the root commit
|
||||||
was accidentally checked out instead.
|
was accidentally checked out instead.
|
||||||
|
|
||||||
|
* When checking out a commit, the previous commit is no longer abandoned if it
|
||||||
|
has a non-empty description.
|
||||||
|
|
||||||
## [0.4.0] - 2022-04-02
|
## [0.4.0] - 2022-04-02
|
||||||
|
|
||||||
### Breaking changes
|
### Breaking changes
|
||||||
|
|
|
@ -588,7 +588,10 @@ impl MutableRepo {
|
||||||
if let Some(current_checkout_id) = maybe_current_checkout_id {
|
if let Some(current_checkout_id) = maybe_current_checkout_id {
|
||||||
let current_checkout = self.store().get_commit(¤t_checkout_id).unwrap();
|
let current_checkout = self.store().get_commit(¤t_checkout_id).unwrap();
|
||||||
assert!(current_checkout.is_open(), "current checkout is closed");
|
assert!(current_checkout.is_open(), "current checkout is closed");
|
||||||
if current_checkout.is_empty() && self.view().heads().contains(current_checkout.id()) {
|
if current_checkout.is_empty()
|
||||||
|
&& current_checkout.description().is_empty()
|
||||||
|
&& self.view().heads().contains(current_checkout.id())
|
||||||
|
{
|
||||||
// Abandon the checkout we're leaving if it's empty and a head commit
|
// Abandon the checkout we're leaving if it's empty and a head commit
|
||||||
self.record_abandoned_commit(current_checkout_id);
|
self.record_abandoned_commit(current_checkout_id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -133,6 +133,39 @@ fn test_checkout_previous_empty(use_git: bool) {
|
||||||
assert!(!mut_repo.view().heads().contains(old_checkout.id()));
|
assert!(!mut_repo.view().heads().contains(old_checkout.id()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test_case(false ; "local backend")]
|
||||||
|
// #[test_case(true ; "git backend")]
|
||||||
|
fn test_checkout_previous_empty_with_description(use_git: bool) {
|
||||||
|
// Test that MutableRepo::check_out() does not abandon the previous commit if it
|
||||||
|
// has a non-empty description.
|
||||||
|
let settings = testutils::user_settings();
|
||||||
|
let test_repo = testutils::init_repo(&settings, use_git);
|
||||||
|
let repo = &test_repo.repo;
|
||||||
|
|
||||||
|
let mut tx = repo.start_transaction("test");
|
||||||
|
let mut_repo = tx.mut_repo();
|
||||||
|
let old_checkout = CommitBuilder::for_open_commit(
|
||||||
|
&settings,
|
||||||
|
repo.store(),
|
||||||
|
repo.store().root_commit_id().clone(),
|
||||||
|
repo.store().empty_tree_id().clone(),
|
||||||
|
)
|
||||||
|
.set_description("not empty".to_string())
|
||||||
|
.write_to_repo(mut_repo);
|
||||||
|
let ws_id = WorkspaceId::default();
|
||||||
|
mut_repo.check_out(ws_id.clone(), &settings, &old_checkout);
|
||||||
|
let repo = tx.commit();
|
||||||
|
|
||||||
|
let mut tx = repo.start_transaction("test");
|
||||||
|
let mut_repo = tx.mut_repo();
|
||||||
|
let new_checkout = testutils::create_random_commit(&settings, &repo)
|
||||||
|
.set_open(true)
|
||||||
|
.write_to_repo(mut_repo);
|
||||||
|
mut_repo.check_out(ws_id, &settings, &new_checkout);
|
||||||
|
mut_repo.rebase_descendants(&settings).unwrap();
|
||||||
|
assert!(mut_repo.view().heads().contains(old_checkout.id()));
|
||||||
|
}
|
||||||
|
|
||||||
#[test_case(false ; "local backend")]
|
#[test_case(false ; "local backend")]
|
||||||
// #[test_case(true ; "git backend")]
|
// #[test_case(true ; "git backend")]
|
||||||
fn test_checkout_previous_empty_non_head(use_git: bool) {
|
fn test_checkout_previous_empty_non_head(use_git: bool) {
|
||||||
|
|
|
@ -37,6 +37,7 @@ fn test_new() {
|
||||||
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", "commit_id \" \" description"]);
|
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", "commit_id \" \" description"]);
|
||||||
insta::assert_snapshot!(stdout, @r###"
|
insta::assert_snapshot!(stdout, @r###"
|
||||||
@ d8c0a3e1570f1f5b08113a3427b3160900c3d48e off of root
|
@ d8c0a3e1570f1f5b08113a3427b3160900c3d48e off of root
|
||||||
|
| o 88436dbcdbedc2b8a6ebd0687981906d09ccc68f a new commit
|
||||||
| o 51e9c5819117991e4a6dc5a4a744283fc74f0746 add a file
|
| o 51e9c5819117991e4a6dc5a4a744283fc74f0746 add a file
|
||||||
|/
|
|/
|
||||||
o 0000000000000000000000000000000000000000 (no description set)
|
o 0000000000000000000000000000000000000000 (no description set)
|
||||||
|
|
Loading…
Reference in a new issue