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

cli: change the default revsets for push to be based on trunk() #2263

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 11 additions & 7 deletions cli/src/commands/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ pub struct GitCloneArgs {
/// Push to a Git remote
///
/// By default, pushes any branches pointing to
/// `remote_branches(remote=<remote>)..@`. Use `--branch` to push specific
/// `(trunk()..@):: & branches()`. Use `--branch` to push specific
Copy link
Collaborator

Choose a reason for hiding this comment

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

The & branches() seems to be unnecessary because of how jj git push -r is defined.

/// 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)]
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 2 additions & 6 deletions cli/tests/test_git_push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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###"
Expand Down