Search in sources :

Example 6 with GitBranch

use of git4idea.GitBranch in project intellij-community by JetBrains.

the class GitMerger method mergeCommit.

public void mergeCommit(@NotNull VirtualFile root) throws VcsException {
    GitSimpleHandler handler = new GitSimpleHandler(myProject, root, GitCommand.COMMIT);
    handler.setStdoutSuppressed(false);
    File messageFile = assertNotNull(myRepositoryManager.getRepositoryForRoot(root)).getRepositoryFiles().getMergeMessageFile();
    if (!messageFile.exists()) {
        final GitBranch branch = GitBranchUtil.getCurrentBranch(myProject, root);
        final String branchName = branch != null ? branch.getName() : "";
        handler.addParameters("-m", "Merge branch '" + branchName + "' of " + root.getPresentableUrl() + " with conflicts.");
    } else {
        handler.addParameters("-F", messageFile.getAbsolutePath());
    }
    handler.endOptions();
    handler.run();
}
Also used : GitSimpleHandler(git4idea.commands.GitSimpleHandler) GitBranch(git4idea.GitBranch) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 7 with GitBranch

use of git4idea.GitBranch in project intellij-community by JetBrains.

the class GitUIUtil method setupRootChooser.

/**
   * Setup root chooser with specified elements and link selection to the current branch label.
   *
   * @param project            a context project
   * @param roots              git roots for the project
   * @param defaultRoot        a default root
   * @param gitRootChooser     git root selector
   * @param currentBranchLabel current branch label (might be null)
   */
public static void setupRootChooser(@NotNull final Project project, @NotNull final List<VirtualFile> roots, @Nullable final VirtualFile defaultRoot, @NotNull final JComboBox gitRootChooser, @Nullable final JLabel currentBranchLabel) {
    for (VirtualFile root : roots) {
        gitRootChooser.addItem(root);
    }
    gitRootChooser.setRenderer(getVirtualFileListCellRenderer());
    gitRootChooser.setSelectedItem(defaultRoot != null ? defaultRoot : roots.get(0));
    if (currentBranchLabel != null) {
        final ActionListener listener = new ActionListener() {

            public void actionPerformed(final ActionEvent e) {
                VirtualFile root = (VirtualFile) gitRootChooser.getSelectedItem();
                assert root != null : "The root must not be null";
                GitRepository repo = GitUtil.getRepositoryManager(project).getRepositoryForRoot(root);
                assert repo != null : "The repository must not be null";
                GitBranch current = repo.getCurrentBranch();
                if (current == null) {
                    currentBranchLabel.setText(NO_CURRENT_BRANCH);
                } else {
                    currentBranchLabel.setText(current.getName());
                }
            }
        };
        listener.actionPerformed(null);
        gitRootChooser.addActionListener(listener);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GitRepository(git4idea.repo.GitRepository) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) GitBranch(git4idea.GitBranch)

Aggregations

GitBranch (git4idea.GitBranch)7 GitRepository (git4idea.repo.GitRepository)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 NotNull (org.jetbrains.annotations.NotNull)3 GitBranchPair (git4idea.branch.GitBranchPair)1 GitBranchesCollection (git4idea.branch.GitBranchesCollection)1 GitSimpleHandler (git4idea.commands.GitSimpleHandler)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1