From 69edc7f2df298c94c27e2dc392c25e732bf5b5be Mon Sep 17 00:00:00 2001 From: Kevin Liao Date: Mon, 9 Sep 2024 12:14:48 -0700 Subject: [PATCH] Update `jj edit ` to add commit into view heads if not already `jj new ` automatically adds the checked out commits into the view head ids. However, `jj edit` does not. To reproduce: ``` jj git init test cd test jj commit -m "my commit" jj log -r @- -T commit_id # Save the id jj abandon -r @- jj edit jj log -r :: # Does not show the currently editing commit ``` --- CHANGELOG.md | 2 ++ lib/src/repo.rs | 1 + lib/tests/test_mut_repo.rs | 22 ++++++++++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 87e3b778f..5fb2f58e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,8 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). * Fixed panic when parsing invalid conflict markers of a particular form. ([#2611](https://github.com/martinvonz/jj/pull/2611)) + * Editing a hidden commit now makes it visible. + ## [0.21.0] - 2024-09-04 ### Breaking changes diff --git a/lib/src/repo.rs b/lib/src/repo.rs index 185ac8ff5..a262c87f7 100644 --- a/lib/src/repo.rs +++ b/lib/src/repo.rs @@ -1375,6 +1375,7 @@ impl MutableRepo { commit: &Commit, ) -> Result<(), EditCommitError> { self.maybe_abandon_wc_commit(&workspace_id)?; + self.add_head(commit)?; self.set_wc_commit(workspace_id, commit.id().clone()) .map_err(|RewriteRootCommit| EditCommitError::RewriteRootCommit) } diff --git a/lib/tests/test_mut_repo.rs b/lib/tests/test_mut_repo.rs index 601212edc..925c2ff17 100644 --- a/lib/tests/test_mut_repo.rs +++ b/lib/tests/test_mut_repo.rs @@ -318,6 +318,28 @@ fn test_edit_initial() { ); } +#[test] +fn test_edit_hidden_commit() { + // Test that MutableRepo::edit() edits a hidden commit and updates + // the view head ids. + let settings = testutils::user_settings(); + let test_repo = TestRepo::init(); + let repo = &test_repo.repo; + + let mut tx = repo.start_transaction(&settings); + let wc_commit = write_random_commit(tx.repo_mut(), &settings); + + // Intentionally not doing tx.commit, so the commit id is not tracked + // in the view head ids. + + let mut tx = repo.start_transaction(&settings); + let ws_id = WorkspaceId::default(); + tx.repo_mut().edit(ws_id.clone(), &wc_commit).unwrap(); + let repo = tx.commit("test"); + assert_eq!(repo.view().get_wc_commit_id(&ws_id), Some(wc_commit.id())); + assert_eq!(*repo.view().heads(), hashset! {wc_commit.id().clone()}); +} + #[test] fn test_add_head_success() { // Test that MutableRepo::add_head() adds the head, and that it's still there