Skip to content

Commit c7a4aee

Browse files
author
elchananarb
committed
Prevent creation of new branches by validating branch selection
1 parent 5565395 commit c7a4aee

1 file changed

Lines changed: 27 additions & 7 deletions

File tree

checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/CheckmarxView.java

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -869,38 +869,58 @@ public void selectionChanged(SelectionChangedEvent event) {
869869
if (selection.size() > 0) {
870870
String selectedBranch = ((String) selection.getFirstElement());
871871

872+
// Check if selected branch exists in currentBranches
873+
if (!currentBranches.contains(selectedBranch)) {
874+
// Invalid branch - reset to default text and disable scan button
875+
PluginUtils.setTextForComboViewer(branchComboViewer, BRANCH_COMBO_VIEWER_TEXT);
876+
updateStartScanButton(false);
877+
return;
878+
}
879+
872880
// Avoid non-sense trigger changed when opening the combo
873881
if (selectedBranch.equals(currentBranch) && !scansCleanedByProject) {
874882
CxLogger.info(PluginConstants.INFO_CHANGE_BRANCH_EVENT_NOT_TRIGGERED);
875-
876883
return;
877884
}
878885

879886
onBranchChangePluginLoading(selectedBranch);
880887

881888
List<Scan> scanList = DataProvider.getInstance().getScansForProject(selectedBranch);
882-
if(!scanList.isEmpty()) {
889+
if (!scanList.isEmpty()) {
883890
latestScanId = getLatestScanFromScanList(scanList).getId();
884891
}
885-
scanIdComboViewer.setInput(scanList);
892+
scanIdComboViewer.setInput(scanList);
886893
loadLatestScanByDefault(scanList);
887-
894+
888895
sync.asyncExec(new Runnable() {
889896
public void run() {
890897
PluginUtils.enableComboViewer(projectComboViewer, true);
891898
PluginUtils.enableComboViewer(scanIdComboViewer, true);
892899
PluginUtils.updateFiltersEnabledAndCheckedState(toolBarActions.getFilterActions());
893900
toolBarActions.getStateFilterAction().setEnabled(true);
894901
updateStartScanButton(true);
895-
}
902+
}
896903
});
897-
904+
898905
PluginUtils.updateFiltersEnabledAndCheckedState(toolBarActions.getFilterActions());
899906
}
900907
}
901908
});
909+
910+
// Add ModifyListener to handle manual text input
911+
branchComboViewer.getCombo().addModifyListener(e -> {
912+
String enteredBranch = branchComboViewer.getCombo().getText();
913+
914+
// If text was modified and branch doesn't exist
915+
if (!currentBranches.contains(enteredBranch)) {
916+
updateStartScanButton(false); // Disable scan button
917+
} else {
918+
updateStartScanButton(true); // Enable scan button if branch is valid
919+
}
920+
});
902921
}
903-
922+
923+
904924
private void loadLatestScanByDefault(List<Scan> scanList) {
905925
if(scanList.isEmpty()) {
906926
PluginUtils.setTextForComboViewer(scanIdComboViewer, PluginConstants.COMBOBOX_SCAND_ID_NO_SCANS_AVAILABLE);

0 commit comments

Comments
 (0)