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.)
This commit is contained in:
Yuya Nishihara 2023-06-25 20:02:33 +09:00
parent 9d6020fab0
commit 72792a8dbe
2 changed files with 9 additions and 6 deletions

View file

@ -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() {

View file

@ -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"]);