From d92be6635c9c705409366a7eb6f5ab9d888d7577 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Wed, 18 Oct 2023 15:56:02 +0900 Subject: [PATCH] cli: do not list non-tracking remote branches by default I personally don't mind if "jj branch list" showed all non-tracking branches, but I agree it would be a mess if ~500 remote branches were listed. So let's hide them by default as non-tracking branches aren't so interesting. Closes #1136 --- CHANGELOG.md | 3 +++ cli/src/commands/branch.rs | 16 +++++++++------- cli/tests/test_branch_command.rs | 4 ++-- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4306789ab..abd0cf364 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 See [automatic local branch creation](docs/config.md#automatic-local-branch-creation) for details. +* Non-tracking remote branches aren't listed by default. Use `jj branch list + --all` to show all local and remote branches. + * It's not allowed to push branches if non-tracking remote branches of the same name exist. diff --git a/cli/src/commands/branch.rs b/cli/src/commands/branch.rs index 39b6534ae..b1e5aeb3e 100644 --- a/cli/src/commands/branch.rs +++ b/cli/src/commands/branch.rs @@ -65,9 +65,10 @@ pub struct BranchDeleteArgs { /// List branches and their targets /// /// By default, a tracking remote branch will be included only if its target is -/// different from the local target. For a conflicted branch (both local and -/// remote), old target revisions are preceded by a "-" and new target revisions -/// are preceded by a "+". +/// different from the local target. A non-tracking remote branch won't be +/// listed. For a conflicted branch (both local and remote), old target +/// revisions are preceded by a "-" and new target revisions are preceded by a +/// "+". /// /// For information about branches, see /// https://github.com/martinvonz/jj/blob/main/docs/branches.md. @@ -573,10 +574,11 @@ fn cmd_branch_list( } } - // TODO: hide non-tracking remotes by default? - for &(remote, remote_ref) in &untracked_remote_refs { - write!(formatter.labeled("branch"), "{name}@{remote}")?; - print_branch_target(formatter, &remote_ref.target)?; + if args.all { + for &(remote, remote_ref) in &untracked_remote_refs { + write!(formatter.labeled("branch"), "{name}@{remote}")?; + print_branch_target(formatter, &remote_ref.target)?; + } } } diff --git a/cli/tests/test_branch_command.rs b/cli/tests/test_branch_command.rs index 289455e45..973b73eee 100644 --- a/cli/tests/test_branch_command.rs +++ b/cli/tests/test_branch_command.rs @@ -756,7 +756,8 @@ fn test_branch_list() { &["branch", "set", "--allow-backwards", "remote-unsync"], ); - // Synchronized tracking remotes aren't listed by default + // Synchronized tracking remotes and non-tracking remotes aren't listed by + // default insta::assert_snapshot!( test_env.jj_cmd_success(&local_path, &["branch", "list"]), @r###" local-only: wqnwkozp 4e887f78 (empty) local-only @@ -767,7 +768,6 @@ fn test_branch_list() { remote-sync: zwtyzrop c761c7ea (empty) remote-sync remote-unsync: wqnwkozp 4e887f78 (empty) local-only @origin (ahead by 1 commits, behind by 1 commits): qpsqxpyq 38ef8af7 (empty) remote-unsync - remote-untrack@origin: vmortlor 71a16b05 (empty) remote-untrack "###); insta::assert_snapshot!(