Skip to content

Add missinng logic for delete a local branch #8650

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Chris2011
Copy link
Contributor

@Chris2011 Chris2011 commented Jul 12, 2025

The logic was still implemented but action items are missing and the logic to select a branch to delete it. The problem was, when you do a quick search for delete, the delete was found and the UnsupportedOperationException was thrown. Now everything works as expected.


PR approval and merge checklist:

  1. Was this PR correctly labeled, did the right tests run? When did they run?
  2. Is this PR squashed?
  3. Are author name / email address correct? Are co-authors correctly listed? Do the commit messages need updates?
  4. Does the PR title and description still fit after the Nth iteration? Is the description sufficient to appear in the release notes?

If this PR targets the delivery branch: don't merge. (full wiki article)

@Chris2011 Chris2011 self-assigned this Jul 12, 2025
@Chris2011 Chris2011 added enhancement git [ci] enable versioning job ci:dev-build [ci] produce a dev-build zip artifact (7 days expiration, see link on workflow summary page) labels Jul 12, 2025
@mbien
Copy link
Member

mbien commented Jul 13, 2025

this would have to make sure that the currently checked out branch isn't offered for deletion, since this can't be done.

the repo browser does have the delete action too and does it correctly:
image

@Chris2011
Copy link
Contributor Author

Thx, everything seems to work correctly beacuse if smth is wrong here, there witll be a GitException which shows the error:

delete.checkout.branch.mp4

So I'm fine with this behaviour.

@mbien
Copy link
Member

mbien commented Jul 13, 2025

right, saw that. This isn't great. Tools should not offer actions for operations which aren't supported by the impl.

@Chris2011
Copy link
Contributor Author

So you mean just disable the ok butten when the current checked out branch is selected?

@mbien
Copy link
Member

mbien commented Jul 14, 2025

So you mean just disable the ok butten when the current checked out branch is selected?

something like that yeah, although removing the current branch from the list might be easier since it wouldn't involve having to update the branch selector UI which is probably used in many places.

not tested:

action:

        RepositoryInfo info = RepositoryInfo.getInstance(repository);
        HashMap<String, GitBranch> branches = new HashMap<>(info.getBranches());
        branches.remove(info.getActiveBranch().getName());
        
        if (branches.isEmpty()) {
            // TODO notify: "can't delete active branch"
            return;
        }
        
        BranchSelector selector = new BranchSelector(repository, branches);

new BranchSelector constructor:

    public BranchSelector(File repository, HashMap<String, GitBranch> branches) {
        this.revisionPicker = new RevisionDialogController(repository, new File[0], branches, null);
        panel = new SelectBranchPanel(revisionPicker.getPanel());
    }

would be nice to overwrite the enable() method of the action and turn it off if there is just one branch, but I am not 100% if it is a good idea to run the branch query on the EDT, I haven't looked into this deeper.

@mbien
Copy link
Member

mbien commented Jul 14, 2025

enable method:

    @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;
    }

with that method you don't need the TODO

@Chris2011
Copy link
Contributor Author

@mbien added your requested code, I tested it with quick search -> delete branch, Menu -> team -> git -> branch ->delete branch and with the popup action on the project node. Seem working now. Thx.

Copy link
Member

@mbien mbien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added a comment, there is now also a merge conflict to resolve.

please squash to one commit before integration - other than that looks good to me

@Chris2011 Chris2011 force-pushed the feature/add-delete-branch-logic branch from 7addf3e to 91d7d70 Compare July 23, 2025 11:22
# Conflicts:
#	ide/git/src/org/netbeans/modules/git/ui/menu/BranchMenu.java
@Chris2011 Chris2011 force-pushed the feature/add-delete-branch-logic branch from 91d7d70 to 22a3da8 Compare July 23, 2025 11:46
@Chris2011 Chris2011 requested a review from mbien July 23, 2025 11:51
@Chris2011 Chris2011 added this to the NB28 milestone Jul 23, 2025
@Chris2011
Copy link
Contributor Author

If there are no other concerns, I will probably merge this next week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci:dev-build [ci] produce a dev-build zip artifact (7 days expiration, see link on workflow summary page) enhancement git [ci] enable versioning job
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy