Skip to content

Commit

Permalink
branch list: more detailed message describing deleted branches
Browse files Browse the repository at this point in the history
Fixes #1537
  • Loading branch information
ilyagr committed Jun 24, 2023
1 parent e41d672 commit d01ecc5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/commands/branch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,10 +334,14 @@ fn cmd_branch_list(
write!(formatter.labeled("branch"), "{name}")?;
print_branch_target(formatter, branch_target.local_target.as_ref())?;

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() {
Expand All @@ -361,6 +365,13 @@ fn cmd_branch_list(
}
print_branch_target(formatter, Some(remote_target))?;
}
if found_non_git_remote && branch_target.local_target.is_none() {
writeln!(
formatter,
" (this branch will be *deleted permanently* on the remote on the\n next `jj \
git push`. Use `jj branch forget` to prevent this)"
)?;
}
}

Ok(())
Expand Down
2 changes: 2 additions & 0 deletions tests/test_branch_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,8 @@ fn test_branch_forget_deleted_or_nonexistent_branch() {
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###"
feature1 (deleted)
@origin: 9f01a0e04879 message
(this branch will be *deleted permanently* on the remote on the
next `jj git push`. Use `jj branch forget` to prevent this)
"###);

// ============ End of test setup ============
Expand Down
2 changes: 2 additions & 0 deletions tests/test_git_fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -949,5 +949,7 @@ fn test_git_fetch_remote_only_branch() {
feature1: 9f01a0e04879 message
feature2 (deleted)
@origin: 9f01a0e04879 message
(this branch will be *deleted permanently* on the remote on the
next `jj git push`. Use `jj branch forget` to prevent this)
"###);
}
2 changes: 2 additions & 0 deletions tests/test_git_push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ fn test_git_push_multiple() {
insta::assert_snapshot!(stdout, @r###"
branch1 (deleted)
@origin: 45a3aa29e907 description 1
(this branch will be *deleted permanently* on the remote on the
next `jj git push`. Use `jj branch forget` to prevent this)
branch2: 15dcdaa4f12f foo
@origin (ahead by 1 commits, behind by 1 commits): 8476341eb395 description 2
my-branch: 15dcdaa4f12f foo
Expand Down

0 comments on commit d01ecc5

Please sign in to comment.