Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit91d7d70

Browse files
committed
Add missinng logic for delete a local branch
1 parent427a01f commit91d7d70

File tree

3 files changed

+60
-11
lines changed

3 files changed

+60
-11
lines changed

‎ide/git/src/org/netbeans/modules/git/ui/branch/DeleteBranchAction.java‎

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,29 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19-
2019
packageorg.netbeans.modules.git.ui.branch;
2120

2221
importorg.netbeans.libs.git.GitException.NotMergedException;
2322
importorg.netbeans.modules.git.client.GitClientExceptionHandler;
2423
importjava.io.File;
24+
importjava.util.HashMap;
25+
importjava.util.Map;
2526
importjava.util.logging.Level;
2627
importjava.util.logging.Logger;
28+
importorg.netbeans.libs.git.GitBranch;
2729
importorg.netbeans.modules.git.client.GitClient;
2830
importorg.netbeans.libs.git.GitException;
2931
importorg.netbeans.modules.git.Git;
3032
importorg.netbeans.modules.git.client.GitProgressSupport;
3133
importorg.netbeans.modules.git.ui.actions.SingleRepositoryAction;
34+
importorg.netbeans.modules.git.ui.history.BranchSelector;
35+
importorg.netbeans.modules.git.ui.repository.RepositoryInfo;
3236
importorg.netbeans.modules.versioning.spi.VCSContext;
3337
importorg.openide.DialogDisplayer;
3438
importorg.openide.NotifyDescriptor;
3539
importorg.openide.awt.ActionID;
3640
importorg.openide.awt.ActionRegistration;
41+
importorg.openide.nodes.Node;
3742
importorg.openide.util.NbBundle;
3843

3944
/**
@@ -47,26 +52,54 @@ public class DeleteBranchAction extends SingleRepositoryAction {
4752
privatestaticfinalLoggerLOG =Logger.getLogger(DeleteBranchAction.class.getName());
4853

4954
@Override
50-
protectedvoidperformAction (Filerepository,File[]roots,VCSContextcontext) {
51-
thrownewUnsupportedOperationException();
55+
protectedvoidperformAction(Filerepository,File[]roots,VCSContextcontext) {
56+
RepositoryInfoinfo =RepositoryInfo.getInstance(repository);
57+
HashMap<String,GitBranch>branches =newHashMap<>(info.getBranches());
58+
branches.remove(info.getActiveBranch().getName());
59+
60+
if (branches.isEmpty()) {
61+
return;
62+
}
63+
64+
BranchSelectorselector =newBranchSelector(repository,branches);
65+
if (selector.open()) {
66+
deleteBranch(repository,selector.getSelectedBranch());
67+
}
68+
}
69+
70+
@Override
71+
protectedbooleanenable(Node[]activatedNodes) {
72+
if (!super.enable(activatedNodes)) {
73+
returnfalse;
74+
}
75+
76+
// require 2+ branches
77+
Map.Entry<File,File[]>actionRoots =getActionRoots(getCurrentContext(activatedNodes));
78+
if (actionRoots !=null) {
79+
RepositoryInfoinfo =RepositoryInfo.getInstance(actionRoots.getKey());
80+
81+
returninfo !=null &&info.getBranches().size() >1;
82+
}
83+
84+
returnfalse;
5285
}
5386

54-
publicvoiddeleteBranch(finalFilerepository,finalStringbranchName) {
87+
publicvoiddeleteBranch(finalFilerepository,finalStringbranchName) {
5588
NotifyDescriptornd =newNotifyDescriptor.Confirmation(NbBundle.getMessage(DeleteBranchAction.class,"MSG_DeleteBranchAction.confirmation",branchName),//NOI18N
56-
NbBundle.getMessage(DeleteBranchAction.class,"LBL_DeleteBranchAction.confirmation"),//NOI18N
57-
NotifyDescriptor.OK_CANCEL_OPTION,NotifyDescriptor.QUESTION_MESSAGE);
89+
NbBundle.getMessage(DeleteBranchAction.class,"LBL_DeleteBranchAction.confirmation"),//NOI18N
90+
NotifyDescriptor.OK_CANCEL_OPTION,NotifyDescriptor.QUESTION_MESSAGE);
5891

5992
if (NotifyDescriptor.OK_OPTION ==DialogDisplayer.getDefault().notify(nd)) {
6093
GitProgressSupportsupp =newGitProgressSupport() {
6194
@Override
62-
protectedvoidperform() {
95+
protectedvoidperform() {
6396
try {
6497
GitClientclient =getClient();
6598
booleanforceDelete =false;
6699
booleancont;
67100
do {
68101
try {
69-
LOG.log(Level.FINE,"Deleting a branch: {0}/{1}",newObject[] {branchName,forceDelete});//NOI18N
102+
LOG.log(Level.FINE,"Deleting a branch: {0}/{1}",newObject[]{branchName,forceDelete});//NOI18N
70103
client.deleteBranch(branchName,forceDelete,getProgressMonitor());
71104
cont =false;
72105
}catch (GitException.NotMergedExceptionex) {
@@ -78,10 +111,10 @@ protected void perform () {
78111
}
79112
}
80113

81-
privatebooleanhandleException(NotMergedExceptionex) {
114+
privatebooleanhandleException(NotMergedExceptionex) {
82115
NotifyDescriptornd =newNotifyDescriptor.Confirmation(NbBundle.getMessage(DeleteBranchAction.class,"MSG_DeleteBranchAction.notMerged",ex.getUnmergedRevision()),//NOI18N
83-
NbBundle.getMessage(DeleteBranchAction.class,"LBL_DeleteBranchAction.notMerged"),//NOI18N
84-
NotifyDescriptor.YES_NO_OPTION,NotifyDescriptor.QUESTION_MESSAGE);
116+
NbBundle.getMessage(DeleteBranchAction.class,"LBL_DeleteBranchAction.notMerged"),//NOI18N
117+
NotifyDescriptor.YES_NO_OPTION,NotifyDescriptor.QUESTION_MESSAGE);
85118
returnNotifyDescriptor.YES_OPTION ==DialogDisplayer.getDefault().notify(nd);
86119
}
87120
};

‎ide/git/src/org/netbeans/modules/git/ui/history/BranchSelector.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
importjava.beans.PropertyChangeListener;
2525
importjava.io.File;
2626
importjava.util.Collections;
27+
importjava.util.HashMap;
2728
importjavax.swing.JButton;
2829
importorg.netbeans.libs.git.GitBranch;
2930
importorg.netbeans.modules.git.ui.repository.RevisionDialogController;
@@ -47,6 +48,11 @@ public BranchSelector (File repository) {
4748
Collections.<String,GitBranch>emptyMap(),null);
4849
panel =newSelectBranchPanel(revisionPicker.getPanel());
4950
}
51+
52+
publicBranchSelector(Filerepository,HashMap<String,GitBranch>branches) {
53+
this.revisionPicker =newRevisionDialogController(repository,newFile[0],branches,null);
54+
panel =newSelectBranchPanel(revisionPicker.getPanel());
55+
}
5056

5157
publicStringgetSelectedBranch () {
5258
returnrevisionPicker.getRevision().getRevision();

‎ide/git/src/org/netbeans/modules/git/ui/menu/BranchMenu.java‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
importorg.netbeans.modules.git.Annotator;
3030
importorg.netbeans.modules.git.ui.branch.CherryPickAction;
3131
importorg.netbeans.modules.git.ui.branch.CreateBranchAction;
32+
importorg.netbeans.modules.git.ui.branch.DeleteBranchAction;
3233
importorg.netbeans.modules.git.ui.branch.SetTrackingAction;
3334
importorg.netbeans.modules.git.ui.checkout.AbstractCheckoutAction;
3435
importorg.netbeans.modules.git.ui.checkout.SwitchBranchAction;
@@ -98,6 +99,7 @@ protected JMenu createMenu () {
9899
Utils.setAcceleratorBindings(Annotator.ACTIONS_PATH_PREFIX,action);
99100
Actions.connect(item,action,false);
100101
menu.add(item);
102+
101103
item =newJMenuItem();
102104
action = (Action)SystemAction.get(ManageTagsAction.class);
103105
Utils.setAcceleratorBindings(Annotator.ACTIONS_PATH_PREFIX,action);
@@ -122,6 +124,12 @@ protected JMenu createMenu () {
122124
Utils.setAcceleratorBindings(Annotator.ACTIONS_PATH_PREFIX,action);
123125
Actions.connect(item,action,false);
124126
menu.add(item);
127+
128+
item =newJMenuItem();
129+
action = (Action)SystemAction.get(DeleteBranchAction.class);
130+
Utils.setAcceleratorBindings(Annotator.ACTIONS_PATH_PREFIX,action);
131+
Actions.connect(item,action,false);
132+
menu.add(item);
125133
}else {
126134
item =menu.add(SystemActionBridge.createAction(SystemAction.get(CreateBranchAction.class),NbBundle.getMessage(CreateBranchAction.class,"LBL_CreateBranchAction_PopupName"),lkp));//NOI18N
127135
org.openide.awt.Mnemonics.setLocalizedText(item,item.getText());
@@ -165,6 +173,8 @@ protected JMenu createMenu () {
165173
org.openide.awt.Mnemonics.setLocalizedText(item,item.getText());
166174
item =menu.add(SystemActionBridge.createAction(SystemAction.get(CherryPickAction.class),NbBundle.getMessage(CherryPickAction.class,"LBL_CherryPickAction_PopupName"),lkp));//NOI18N
167175
org.openide.awt.Mnemonics.setLocalizedText(item,item.getText());
176+
item =menu.add(SystemActionBridge.createAction(SystemAction.get(DeleteBranchAction.class),NbBundle.getMessage(DeleteBranchAction.class,"LBL_DeleteBranchAction_PopupName"),lkp));//NOI18N
177+
org.openide.awt.Mnemonics.setLocalizedText(item,item.getText());
168178
}
169179
returnmenu;
170180
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp