From 2ac9865ce75451974aa127c30e7d6e659df2ee99 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Tue, 7 Nov 2023 17:47:13 +0900 Subject: [PATCH] revset: exclude @git branches from remote_branches() As discussed in Discord, it's less useful if remote_branches() included Git-tracking branches. Users wouldn't consider the backing Git repo as a remote. We could allow explicit 'remote_branches(remote=exact:"git")' query by changing the default remote pattern to something like 'remote=~exact:"git"'. I don't know which will be better overall, but we don't have support for negative patterns anyway. --- CHANGELOG.md | 7 +++++-- cli/tests/test_git_import_export.rs | 5 ++--- docs/revsets.md | 3 +++ lib/src/revset.rs | 2 ++ lib/tests/test_revset.rs | 7 +++++++ 5 files changed, 19 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ed154d00..731575284 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Breaking changes +* The `remote_branches()` revset no longer includes branches exported to the Git + repository (so called Git-tracking branches.) + ### New features * `jj workspace add` can now take _multiple_ `--revision` arguments, which will @@ -33,8 +36,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 clone to see the full speedup. * The `remote_branches()` revset now includes branches exported to the Git - repository (so called Git-tracking branches.) Use - `remote_branches(remote=exact:"origin")` to query branches of certain remote. + repository (so called Git-tracking branches.) *This change will be reverted + in 0.12.0.* * Status messages are now printed to stderr. diff --git a/cli/tests/test_git_import_export.rs b/cli/tests/test_git_import_export.rs index b545552b2..c17de22a9 100644 --- a/cli/tests/test_git_import_export.rs +++ b/cli/tests/test_git_import_export.rs @@ -53,9 +53,8 @@ fn test_resolution_of_git_tracking_branches() { insta::assert_snapshot!(query("main@git"), @r###" 16d541ca40f42baf2dea41aa61a0b5f1cbf1f91b old_message "###); - insta::assert_snapshot!(query(r#"remote_branches(exact:"main", exact:"git")"#), @r###" - 16d541ca40f42baf2dea41aa61a0b5f1cbf1f91b old_message - "###); + // Can't be selected by remote_branches() + insta::assert_snapshot!(query(r#"remote_branches(exact:"main", exact:"git")"#), @""); } #[test] diff --git a/docs/revsets.md b/docs/revsets.md index e94650a79..d3f829128 100644 --- a/docs/revsets.md +++ b/docs/revsets.md @@ -112,6 +112,9 @@ revsets (expressions) as arguments. `main@origin` or `main@upstream`. If a branch is in a conflicted state, all its possible targets are included. + While Git-tracking branches can be selected by `@git`, these branches + aren't included in `remote_branches()`. + * `tags()`: All tag targets. If a tag is in a conflicted state, all its possible targets are included. diff --git a/lib/src/revset.rs b/lib/src/revset.rs index 401b8f882..9f959fcab 100644 --- a/lib/src/revset.rs +++ b/lib/src/revset.rs @@ -2147,9 +2147,11 @@ fn resolve_commit_ref( branch_pattern, remote_pattern, } => { + // TODO: should we allow to select @git branches explicitly? let commit_ids = repo .view() .remote_branches_matching(branch_pattern, remote_pattern) + .filter(|&((_, remote_name), _)| remote_name != git::REMOTE_NAME_FOR_LOCAL_GIT_REPO) .flat_map(|(_, remote_ref)| remote_ref.target.added_ids()) .cloned() .collect(); diff --git a/lib/tests/test_revset.rs b/lib/tests/test_revset.rs index 53360bab7..3d54a89e0 100644 --- a/lib/tests/test_revset.rs +++ b/lib/tests/test_revset.rs @@ -1836,12 +1836,19 @@ fn test_evaluate_expression_remote_branches() { let commit2 = write_random_commit(mut_repo, &settings); let commit3 = write_random_commit(mut_repo, &settings); let commit4 = write_random_commit(mut_repo, &settings); + let commit_git_remote = write_random_commit(mut_repo, &settings); // Can get branches when there are none assert_eq!(resolve_commit_ids(mut_repo, "remote_branches()"), vec![]); // Can get a few branches mut_repo.set_remote_branch("branch1", "origin", normal_remote_ref(commit1.id())); mut_repo.set_remote_branch("branch2", "private", normal_remote_ref(commit2.id())); + // Git-tracking branches aren't included + mut_repo.set_remote_branch( + "branch", + git::REMOTE_NAME_FOR_LOCAL_GIT_REPO, + normal_remote_ref(commit_git_remote.id()), + ); assert_eq!( resolve_commit_ids(mut_repo, "remote_branches()"), vec![commit2.id().clone(), commit1.id().clone()]