<commit_before>package gitflow.ui;

import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.ValidationInfo;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.List;

import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;

import git4idea.branch.GitBranchUtil;
import git4idea.repo.GitRepository;
import gitflow.Gitflow;
import gitflow.GitflowBranchUtil;

/**
 * Base class for a "start" dialog. Such a dialog prompts the user to enter a name for a new branch
 * and select a base branch. See {@link GitflowStartFeatureDialog} for an example implementation.
 */
public abstract class AbstractBranchStartDialog extends DialogWrapper {

    private JPanel contentPane;
    private JTextField branchNameTextField;
    private JComboBox branchFromCombo;
    private JLabel branchNameLabel;
    private JLabel spacesLabel;

    private Project project;
    private GitflowBranchUtil gitflowBranchUtil;

    public AbstractBranchStartDialog(Project project) {
        super(project, false);
        this.project = project;
        this.gitflowBranchUtil = new GitflowBranchUtil(project);

        init();
        final String label = getLabel();
        setTitle("New " + label + "...");
        branchNameLabel.setText(String.format("Enter a name for the new %s...", label));
        setModal(true);

        //set the base branch combo
        branchFromCombo.setModel(gitflowBranchUtil.createBranchComboModel(getDefaultBranch()));

        branchNameTextField.getDocument().addDocumentListener(new DocumentListener() {
            public void changedUpdate(DocumentEvent e) {
                checkSpaces();
            }
            public void removeUpdate(DocumentEvent e) {
                checkSpaces();
            }
            public void insertUpdate(DocumentEvent e) {
                checkSpaces();
            }

            public void checkSpaces() {
                if (branchNameTextField.getText().contains(" ")){
                    spacesLabel.setVisible(true);
                }
                else{
                    spacesLabel.setVisible(false);
                }
            }
        });
    }
<commit_msg>Fix for #130: Do not allow branch names with ampersands<commit_after>package gitflow.ui;

import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.ValidationInfo;

import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;

import gitflow.GitflowBranchUtil;

/**
 * Base class for a "start" dialog. Such a dialog prompts the user to enter a name for a new branch
 * and select a base branch. See {@link GitflowStartFeatureDialog} for an example implementation.
 */
public abstract class AbstractBranchStartDialog extends DialogWrapper {

    private JPanel contentPane;
    private JTextField branchNameTextField;
    private JComboBox branchFromCombo;
    private JLabel branchNameLabel;
    private JLabel spacesLabel;

    private Project project;
    private GitflowBranchUtil gitflowBranchUtil;

    public AbstractBranchStartDialog(Project project) {
        super(project, false);
        this.project = project;
        this.gitflowBranchUtil = new GitflowBranchUtil(project);

        init();
        final String label = getLabel();
        setTitle("New " + label + "...");
        branchNameLabel.setText(String.format("Enter a name for the new %s...", label));
        setModal(true);

        //set the base branch combo
        branchFromCombo.setModel(gitflowBranchUtil.createBranchComboModel(getDefaultBranch()));

        branchNameTextField.getDocument().addDocumentListener(new DocumentListener() {
            public void changedUpdate(DocumentEvent e) {
                validateBranchName();
            }
            public void removeUpdate(DocumentEvent e) {
                validateBranchName();
            }
            public void insertUpdate(DocumentEvent e) {
                validateBranchName();
            }

            public void validateBranchName() {
                if (branchNameTextField.getText().contains(" ")){
                    spacesLabel.setVisible(true);
                }
                else{
                    spacesLabel.setVisible(false);
                }

                if (branchNameTextField.getText().contains("&")){
                    AbstractBranchStartDialog.this.setOKActionEnabled(false);
                }
                else{
                    AbstractBranchStartDialog.this.setOKActionEnabled(true);
                }
            }
        });
    }

{'fraction_non_alphanumeric': 0.08451299387280795, 'fraction_numerical': 0.0010564124234100994, 'mean_word_length': 2.5014792899408285, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2264930', 'n_tokens_mistral': 1189, 'n_tokens_neox': 1173, 'n_words': 290}