Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMathias Kinzler2012-06-06 10:47:55 +0000
committerMatthias Sohn2012-06-06 10:47:55 +0000
commitf99a355e564e0a55ed48f2e2ebd2b7437d3c06ea (patch)
treeff16b0aacd5401fb60528722d8e6b4681d635b9e
parent7e840aca8dc9f1b45c5b67e3731f45969798074d (diff)
downloadegit-f99a355e564e0a55ed48f2e2ebd2b7437d3c06ea.tar.gz
egit-f99a355e564e0a55ed48f2e2ebd2b7437d3c06ea.tar.xz
egit-f99a355e564e0a55ed48f2e2ebd2b7437d3c06ea.zip
[historyView] Handle branch deletion more user-friendly
Let's assume we have a commit which the currently checked out branch and a remote tracking branch points to. With the current implementation, right-clicking on "Delete Branch" will delete the remote tracking branch quietly. With this change, the branch selection dialog will come up offering to delete the remote tracking branch. Change-Id: Ia4096aef8f459cd3476f87fe9622b6dbefe29e03 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/DeleteBranchOnCommitHandler.java17
1 files changed, 12 insertions, 5 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/DeleteBranchOnCommitHandler.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/DeleteBranchOnCommitHandler.java
index 067fb49640..a2226b725c 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/DeleteBranchOnCommitHandler.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/DeleteBranchOnCommitHandler.java
@@ -47,9 +47,11 @@ public class DeleteBranchOnCommitHandler extends AbstractHistoryCommandHandler {
if (repository == null)
return null;
+ int totalBranchCount;
List<Ref> branchesOfCommit;
try {
- branchesOfCommit = getBranchesOfCommit(page, repository);
+ totalBranchCount = getBranchesOfCommit(page, repository, false).size();
+ branchesOfCommit = getBranchesOfCommit(page, repository, true);
} catch (IOException e) {
throw new ExecutionException("Could not obtain current Branch", e); //$NON-NLS-1$
}
@@ -61,7 +63,12 @@ public class DeleteBranchOnCommitHandler extends AbstractHistoryCommandHandler {
final Shell shell = getPart(event).getSite().getShell();
final List<Ref> branchesToDelete;
- if (branchesOfCommit.size() > 1) {
+ // we will show the dialog if there are either multiple branches that might be
+ // deleted or if one of the branches is the current head (which we can't delete);
+ // in the latter case, we may show the dialog even if there is only one branch to
+ // delete instead of quietly deleting an unexpected one, for example a remote
+ // tracking branch
+ if (totalBranchCount > 1) {
BranchSelectionDialog<Ref> dlg = new BranchSelectionDialog<Ref>(
shell,
branchesOfCommit,
@@ -127,7 +134,7 @@ public class DeleteBranchOnCommitHandler extends AbstractHistoryCommandHandler {
}
private List<Ref> getBranchesOfCommit(GitHistoryPage page,
- final Repository repo) throws IOException {
+ final Repository repo, boolean hideCurrentBranch) throws IOException {
final List<Ref> branchesOfCommit = new ArrayList<Ref>();
IStructuredSelection selection = getSelection(page);
if (selection.isEmpty())
@@ -139,7 +146,7 @@ public class DeleteBranchOnCommitHandler extends AbstractHistoryCommandHandler {
for (int i = 0; i < refCount; i++) {
Ref ref = commit.getRef(i);
String refName = ref.getName();
- if (head != null && refName.equals(head))
+ if (hideCurrentBranch && head != null && refName.equals(head))
continue;
if (refName.startsWith(Constants.R_HEADS)
|| refName.startsWith(Constants.R_REMOTES))
@@ -176,7 +183,7 @@ public class DeleteBranchOnCommitHandler extends AbstractHistoryCommandHandler {
List<Ref> branchesOfCommit;
try {
- branchesOfCommit = getBranchesOfCommit(page, repository);
+ branchesOfCommit = getBranchesOfCommit(page, repository, true);
} catch (IOException e) {
Activator.logError("Could not calculate Enablement", e); //$NON-NLS-1$
return false;

Back to the top