Skip to content

Add missinng logic for delete a local branch - #8650

Merged
Chris2011 merged 1 commit into
apache:masterfrom
Chris2011:feature/add-delete-branch-logic
Jul 29, 2025
Merged

Chris2011 merged 1 commit into
apache:masterfrom
Chris2011:feature/add-delete-branch-logic

Conversation

@Chris2011

@Chris2011 Chris2011 commented Jul 12, 2025 •

Copy link
Copy Markdown
Contributor

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

mbien commented Jul 13, 2025

Copy link
Copy Markdown
Member

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
Copy Markdown
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

mbien commented Jul 13, 2025

Copy link
Copy Markdown
Member

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

@Chris2011

Copy link
Copy Markdown
Contributor Author

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

@mbien

mbien commented Jul 14, 2025

Copy link
Copy Markdown
Member

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

mbien commented Jul 14, 2025 •

Copy link
Copy Markdown
Member

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
Copy Markdown
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.

@mbien mbien left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
Contributor Author

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

@Chris2011
Chris2011 merged commit 1cd73c7 into apache:master Jul 29, 2025
@Chris2011
Chris2011 deleted the feature/add-delete-branch-logic branch July 29, 2025 11:27
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