mbien commented on code in PR #8650:
URL: https://github.com/apache/netbeans/pull/8650#discussion_r2220994100


##########
ide/git/src/org/netbeans/modules/git/ui/branch/DeleteBranchAction.java:
##########
@@ -47,26 +52,47 @@ public class DeleteBranchAction extends 
SingleRepositoryAction {
     private static final Logger LOG = 
Logger.getLogger(DeleteBranchAction.class.getName());
 
     @Override
-    protected void performAction (File repository, File[] roots, VCSContext 
context) {
-        throw new UnsupportedOperationException();
+    protected void performAction(File repository, File[] roots, VCSContext 
context) {
+        RepositoryInfo info = RepositoryInfo.getInstance(repository);
+        HashMap<String, GitBranch> branches = new 
HashMap<>(info.getBranches());
+        branches.remove(info.getActiveBranch().getName());
+
+        if (branches.isEmpty()) {
+            return;
+        }
+
+        BranchSelector selector = new BranchSelector(repository, branches);
+        if (selector.open()) {
+            deleteBranch(repository, selector.getSelectedBranch());
+        }
+    }
+
+    @Override
+    protected boolean enable(Node[] activatedNodes) {
+        Map.Entry<File, File[]> actionRoots = 
getActionRoots(getCurrentContext(activatedNodes));
+        if (actionRoots != null) {
+            RepositoryInfo info = 
RepositoryInfo.getInstance(actionRoots.getKey());
+            return info.getBranches().size() > 1 && 
super.enable(activatedNodes);
+        }
+        return false;
     }

Review Comment:
   it seems like `info` is allowed to be null, so we would have to add a check.
   
   consider this snippet (I simplified it a little, added comment):
   ```java
       @Override
       protected boolean enable(Node[] activatedNodes) {
           if (!super.enable(activatedNodes)) {
               return false;
           }
           // require 2+ branches
           Map.Entry<File, File[]> actionRoots = 
getActionRoots(getCurrentContext(activatedNodes));
           if (actionRoots != null) {
               RepositoryInfo info = 
RepositoryInfo.getInstance(actionRoots.getKey());
               return info != null && info.getBranches().size() > 1;
           }
           return false;
       }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@netbeans.apache.org
For additional commands, e-mail: notifications-h...@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to