diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d2b41c3e9..7e0d7ba58c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 Check [revsets.toml](cli/src/config/revsets.toml) and [revsets.md](docs/revset.md) to understand how the function can be adapted. +* `jj git push` will now push all branches in the range `(trunk()..@):: & branches()` + instead of only branches pointing to `remote_branches()..@`. + ### New features * The `ancestors()` revset function now takes an optional `depth` argument diff --git a/cli/src/commands/git.rs b/cli/src/commands/git.rs index 5700d8d389..daaeda4a33 100644 --- a/cli/src/commands/git.rs +++ b/cli/src/commands/git.rs @@ -126,7 +126,7 @@ pub struct GitCloneArgs { /// Push to a Git remote /// /// By default, pushes any branches pointing to -/// `remote_branches(remote=)..@`. Use `--branch` to push specific +/// `(trunk()..@):: & branches()`. Use `--branch` to push specific /// branches. Use `--all` to push all branches. Use `--change` to generate /// branch names based on the change IDs of specific commits. #[derive(clap::Args, Clone, Debug)] @@ -791,15 +791,19 @@ fn cmd_git_push( let Some(wc_commit_id) = wc_commit_id else { return Err(user_error("Nothing checked out in this workspace")); }; - let current_branches_expression = RevsetExpression::remote_branches( - StringPattern::everything(), - StringPattern::Exact(remote.to_owned()), - ) - .range(&RevsetExpression::commit(wc_commit_id)) - .intersection(&RevsetExpression::branches(StringPattern::everything())); + + let trunk_expression = tx + .base_workspace_helper() + .parse_revset("trunk()", Some(ui))?; + let stack_expression = trunk_expression + .range(&RevsetExpression::commit(wc_commit_id.clone())) + .descendants(); + let current_branches_expression = stack_expression + .intersection(&RevsetExpression::branches(StringPattern::everything())); let current_branches_revset = tx .base_workspace_helper() .evaluate_revset(current_branches_expression)?; + current_branches_revset.iter().collect() } else { // TODO: Narrow search space to local target commits. diff --git a/cli/tests/test_git_push.rs b/cli/tests/test_git_push.rs index d6e8c317c4..3c4949c6ac 100644 --- a/cli/tests/test_git_push.rs +++ b/cli/tests/test_git_push.rs @@ -140,9 +140,7 @@ fn test_git_push_matching_branch_unchanged() { insta::assert_snapshot!(stdout, @r###" Nothing changed. "###); - insta::assert_snapshot!(stderr, @r###" - No branches point to the specified revisions. - "###); + insta::assert_snapshot!(stderr, @""); } /// Test that `jj git push` without arguments pushes a branch to the specified @@ -183,9 +181,7 @@ fn test_git_push_other_remote_has_branch() { insta::assert_snapshot!(stdout, @r###" Nothing changed. "###); - insta::assert_snapshot!(stderr, @r###" - No branches point to the specified revisions. - "###); + insta::assert_snapshot!(stderr, @""); // But it will still get pushed to another remote let (stdout, stderr) = test_env.jj_cmd_ok(&workspace_root, &["git", "push", "--remote=other"]); insta::assert_snapshot!(stdout, @r###"