From d01ecc5c46043351ea0a3ab982bb2fd606d81ea3 Mon Sep 17 00:00:00 2001 From: Ilya Grigoriev Date: Fri, 23 Jun 2023 23:35:33 -0700 Subject: [PATCH] `branch list`: more detailed message describing deleted branches Fixes #1537 --- src/commands/branch.rs | 11 +++++++++++ tests/test_branch_command.rs | 2 ++ tests/test_git_fetch.rs | 2 ++ tests/test_git_push.rs | 2 ++ 4 files changed, 17 insertions(+) diff --git a/src/commands/branch.rs b/src/commands/branch.rs index 0e8fac9de..efd7f55c7 100644 --- a/src/commands/branch.rs +++ b/src/commands/branch.rs @@ -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() { @@ -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(()) diff --git a/tests/test_branch_command.rs b/tests/test_branch_command.rs index ff7306aa0..0d653450f 100644 --- a/tests/test_branch_command.rs +++ b/tests/test_branch_command.rs @@ -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 ============ diff --git a/tests/test_git_fetch.rs b/tests/test_git_fetch.rs index 083d8bbb2..cdcf39f3a 100644 --- a/tests/test_git_fetch.rs +++ b/tests/test_git_fetch.rs @@ -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) "###); } diff --git a/tests/test_git_push.rs b/tests/test_git_push.rs index 441b5b8b7..4d27d305d 100644 --- a/tests/test_git_push.rs +++ b/tests/test_git_push.rs @@ -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