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: add option to list only conflicted branches #3347

Merged
merged 1 commit into from
Mar 23, 2024
Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

* `jj git push` now prints messages from the remote.

* `jj branch list` now supports a `--conflicted/-c` option to show only conflicted branches.

### Fixed bugs

## [0.15.1] - 2024-03-06
Expand Down
7 changes: 6 additions & 1 deletion cli/src/commands/branch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ pub struct BranchListArgs {
#[arg(long, short, conflicts_with_all = ["all"])]
tracked: bool,

/// Show conflicted branches only.
#[arg(long, short, conflicts_with_all = ["all"])]
conflicted: bool,

/// Show branches whose local name matches
///
/// By default, the specified name matches exactly. Use `glob:` prefix to
Expand Down Expand Up @@ -673,10 +677,11 @@ fn cmd_branch_list(
let mut formatter = ui.stdout_formatter();
let formatter = formatter.as_mut();

let branches_to_list = view.branches().filter(|&(name, _)| {
let branches_to_list = view.branches().filter(|(name, target)| {
branch_names_to_list
.as_ref()
.map_or(true, |branch_names| branch_names.contains(name))
&& (!args.conflicted || target.local_target.has_conflict())
});
for (name, branch_target) in branches_to_list {
let (mut tracking_remote_refs, untracked_remote_refs) = branch_target
Expand Down
4 changes: 4 additions & 0 deletions cli/tests/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,10 @@ For information about branches, see https://github.com/martinvonz/jj/blob/main/d

Possible values: `true`, `false`

* `-c`, `--conflicted` — Show conflicted branches only

Possible values: `true`, `false`

* `-r`, `--revisions <REVISIONS>` — Show branches whose local targets are in the given revisions


Expand Down
39 changes: 39 additions & 0 deletions cli/tests/test_branch_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1348,6 +1348,45 @@ fn test_branch_list_tracked() {
"###);
}

#[test]
fn test_branch_list_conflicted() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");

// Track existing branch. Local branch should result in conflict.
test_env.jj_cmd_ok(&repo_path, &["new", "root()", "-m", "a"]);
test_env.jj_cmd_ok(&repo_path, &["new", "root()", "-m", "b"]);
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "bar"]);
test_env.jj_cmd_ok(
&repo_path,
&["branch", "create", "foo", "-r", "description(a)"],
);
test_env.jj_cmd_ok(
&repo_path,
&[
"branch",
"create",
"foo",
"-r",
"description(b)",
"--at-op=@-",
],
);
test_env.jj_cmd_ok(&repo_path, &["status"]);
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###"
bar: kkmpptxz 06a973bc (empty) b
foo (conflicted):
+ rlvkpnrz d8d5f980 (empty) a
+ kkmpptxz 06a973bc (empty) b
"###);
insta::assert_snapshot!(test_env.jj_cmd_success(&repo_path, &["branch", "list", "--conflicted"]), @r###"
foo (conflicted):
+ rlvkpnrz d8d5f980 (empty) a
+ kkmpptxz 06a973bc (empty) b
"###);
}

fn get_log_output(test_env: &TestEnvironment, cwd: &Path) -> String {
let template = r#"branches ++ " " ++ commit_id.short()"#;
test_env.jj_cmd_success(cwd, &["log", "-T", template])
Expand Down