Skip to content

Commit

Permalink
Update jj edit <commit> to add commit into view heads if not already
Browse files Browse the repository at this point in the history
`jj new <commit>` 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 <saved_id>

jj log -r :: # Does not show the currently editing commit 
```
  • Loading branch information
kevincliao committed Sep 10, 2024
1 parent d04ff12 commit 69edc7f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
22 changes: 22 additions & 0 deletions lib/tests/test_mut_repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 69edc7f

Please sign in to comment.