Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

revset: add working_copies() function #3418

Merged
merged 1 commit into from
Apr 2, 2024

Conversation

ckoehler
Copy link
Collaborator

@ckoehler ckoehler commented Apr 1, 2024

It includes the working copy commit of every workspace of the repo.

Implements #3384

Checklist

If applicable:

  • I have updated CHANGELOG.md
  • I have updated the documentation (README.md, docs/, demos/)
  • I have updated the config schema (cli/src/config-schema.json)
  • I have added tests to cover my changes

@ckoehler ckoehler force-pushed the push-pnmlxrmnnkzv branch 2 times, most recently from 308d28d to e5b0a40 Compare April 1, 2024 19:57
@ckoehler
Copy link
Collaborator Author

ckoehler commented Apr 1, 2024

Not sure how to test this, would appreciate some pointers. Is there an easy way to create a repo with two workspaces, create some commits, and then compare those to the output of working_copies()? Sounds involved.

Nevermind, this looks straightforward: https://github.com/martinvonz/jj/blob/main/lib/tests/test_revset.rs#L332

@martinvonz
Copy link
Owner

Not sure how to test this, would appreciate some pointers. Is there an easy way to create a repo with two workspaces, create some commits, and then compare those to the output of working_copies()? Sounds involved.

Maybe it can be done similar to how we do it for @ here:

jj/lib/tests/test_revset.rs

Lines 331 to 372 in 7b3f8e8

#[test]
fn test_resolve_working_copy() {
let settings = testutils::user_settings();
let test_repo = TestRepo::init();
let repo = &test_repo.repo;
let mut tx = repo.start_transaction(&settings);
let mut_repo = tx.mut_repo();
let commit1 = write_random_commit(mut_repo, &settings);
let commit2 = write_random_commit(mut_repo, &settings);
let ws1 = WorkspaceId::new("ws1".to_string());
let ws2 = WorkspaceId::new("ws2".to_string());
// Cannot resolve a working-copy commit for an unknown workspace
assert_matches!(
RevsetExpression::working_copy(ws1.clone())
.resolve_user_expression(mut_repo, &FailingSymbolResolver),
Err(RevsetResolutionError::WorkspaceMissingWorkingCopy { name }) if name == "ws1"
);
// Add some workspaces
mut_repo
.set_wc_commit(ws1.clone(), commit1.id().clone())
.unwrap();
mut_repo
.set_wc_commit(ws2.clone(), commit2.id().clone())
.unwrap();
let resolve = |ws_id: WorkspaceId| -> Vec<CommitId> {
RevsetExpression::working_copy(ws_id)
.evaluate_programmatic(mut_repo)
.unwrap()
.iter()
.collect()
};
// Can resolve "@" shorthand with a default workspace ID
assert_eq!(resolve(ws1), vec![commit1.id().clone()]);
// Can resolve an explicit checkout
assert_eq!(resolve(ws2), vec![commit2.id().clone()]);
}

@ckoehler ckoehler force-pushed the push-pnmlxrmnnkzv branch 3 times, most recently from af22478 to ef36d55 Compare April 1, 2024 20:33
lib/src/revset.rs Outdated Show resolved Hide resolved
lib/src/revset.rs Outdated Show resolved Hide resolved
It includes the working copy commit of every workspace of the repo.

Implements martinvonz#3384
Copy link
Collaborator

@yuja yuja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks.

@ckoehler ckoehler merged commit 7bde6dd into martinvonz:main Apr 2, 2024
16 checks passed
@ckoehler ckoehler deleted the push-pnmlxrmnnkzv branch April 2, 2024 01:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants