mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-19 19:08:08 +00:00
repo: consider empty and undescribed merge commits as discardable
This commit is contained in:
parent
5d2c0347a2
commit
3090adfd5c
4 changed files with 9 additions and 13 deletions
|
@ -24,6 +24,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
key](https://toml.io/en/v1.0.0#keys). Quote meta characters as needed.
|
key](https://toml.io/en/v1.0.0#keys). Quote meta characters as needed.
|
||||||
Example: `jj config get "revset-aliases.'trunk()'"`
|
Example: `jj config get "revset-aliases.'trunk()'"`
|
||||||
|
|
||||||
|
* When updating the working copy away from an empty and undescribed commit, it
|
||||||
|
is now abandoned even if it is a merge commit.
|
||||||
|
|
||||||
* If a new working-copy commit is created because the old one was abandoned, and
|
* If a new working-copy commit is created because the old one was abandoned, and
|
||||||
the old commit was merge, then the new commit will now also be.
|
the old commit was merge, then the new commit will now also be.
|
||||||
[#2859](https://github.com/martinvonz/jj/issues/2859)
|
[#2859](https://github.com/martinvonz/jj/issues/2859)
|
||||||
|
|
|
@ -153,16 +153,10 @@ impl Commit {
|
||||||
&self.data.committer
|
&self.data.committer
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A commit is discardable if it has one parent, no change from its
|
/// A commit is discardable if it has no change from its parent, and an
|
||||||
/// parent, and an empty description.
|
/// empty description.
|
||||||
pub fn is_discardable(&self) -> BackendResult<bool> {
|
pub fn is_discardable(&self, repo: &dyn Repo) -> BackendResult<bool> {
|
||||||
if self.description().is_empty() {
|
Ok(self.description().is_empty() && self.is_empty(repo)?)
|
||||||
let parents: Vec<_> = self.parents().try_collect()?;
|
|
||||||
if let [parent_commit] = &*parents {
|
|
||||||
return Ok(self.tree_id() == parent_commit.tree_id());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(false)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A quick way to just check if a signature is present.
|
/// A quick way to just check if a signature is present.
|
||||||
|
|
|
@ -1355,7 +1355,7 @@ impl MutableRepo {
|
||||||
.store()
|
.store()
|
||||||
.get_commit(&wc_commit_id)
|
.get_commit(&wc_commit_id)
|
||||||
.map_err(EditCommitError::WorkingCopyCommitNotFound)?;
|
.map_err(EditCommitError::WorkingCopyCommitNotFound)?;
|
||||||
if wc_commit.is_discardable()?
|
if wc_commit.is_discardable(self)?
|
||||||
&& self
|
&& self
|
||||||
.view
|
.view
|
||||||
.with_ref(|v| local_branch_target_ids(v).all(|id| id != wc_commit.id()))
|
.with_ref(|v| local_branch_target_ids(v).all(|id| id != wc_commit.id()))
|
||||||
|
|
|
@ -151,8 +151,7 @@ fn test_edit_previous_empty_merge() {
|
||||||
let new_wc_commit = write_random_commit(mut_repo, &settings);
|
let new_wc_commit = write_random_commit(mut_repo, &settings);
|
||||||
mut_repo.edit(ws_id, &new_wc_commit).unwrap();
|
mut_repo.edit(ws_id, &new_wc_commit).unwrap();
|
||||||
mut_repo.rebase_descendants(&settings).unwrap();
|
mut_repo.rebase_descendants(&settings).unwrap();
|
||||||
// TODO: The old commit should no longer be visible
|
assert!(!mut_repo.view().heads().contains(old_wc_commit.id()));
|
||||||
assert!(mut_repo.view().heads().contains(old_wc_commit.id()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Reference in a new issue