From 72792a8dbe23df8dc9e33c91912f0f2dba0c24ba Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Sun, 25 Jun 2023 20:02:33 +0900 Subject: [PATCH] cli: say "(forgotten)" if branch is listed just because it's in git_refs I thought we would need additional bookkeeping to detect forgotten branches, but I was wrong. If a branch exists only in git_refs, it is forgotten (but not yet exported.) --- src/commands/branch.rs | 13 ++++++++----- tests/test_branch_command.rs | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/commands/branch.rs b/src/commands/branch.rs index 5c4cf1c8e..afec33e08 100644 --- a/src/commands/branch.rs +++ b/src/commands/branch.rs @@ -328,21 +328,24 @@ fn cmd_branch_list( let formatter = formatter.as_mut(); for (name, branch_target) in all_branches { + let found_non_git_remote = { + let pseudo_remote_count = branch_target.remote_targets.contains_key("git") as usize; + branch_target.remote_targets.len() - pseudo_remote_count > 0 + }; + write!(formatter.labeled("branch"), "{name}")?; if let Some(target) = branch_target.local_target.as_ref() { print_branch_target(formatter, target)?; - } else { + } else if found_non_git_remote { writeln!(formatter, " (deleted)")?; + } else { + writeln!(formatter, " (forgotten)")?; } - let mut found_non_git_remote = false; for (remote, remote_target) in branch_target.remote_targets.iter() { if Some(remote_target) == branch_target.local_target.as_ref() { continue; } - if remote != "git" { - found_non_git_remote = true; - } write!(formatter, " ")?; write!(formatter.labeled("branch"), "@{remote}")?; if let Some(local_target) = branch_target.local_target.as_ref() { diff --git a/tests/test_branch_command.rs b/tests/test_branch_command.rs index 0d653450f..b76793270 100644 --- a/tests/test_branch_command.rs +++ b/tests/test_branch_command.rs @@ -137,7 +137,7 @@ fn test_branch_forget_export() { // TODO: Consider allowing forgetting local-git tracking branches as an option let stdout = test_env.jj_cmd_success(&repo_path, &["branch", "list"]); insta::assert_snapshot!(stdout, @r###" - foo (deleted) + foo (forgotten) @git: 65b6b74e0897 (no description set) "###); let stderr = test_env.jj_cmd_failure(&repo_path, &["log", "-r=foo", "--no-graph"]);