git4idea.actions.GitCurrentBranch.java Source code

Java tutorial

Introduction

Here is the source code for git4idea.actions.GitCurrentBranch.java

Source

package git4idea.actions;

/*
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at:
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for
 * the specific language governing permissions and limitations under the License.
 *
 * Copyright 2008 MQSoftware
 * Author: Mark Scott
 *
 * This code was originally derived from the MKS & Mercurial IDEA VCS plugins
 */
import org.jetbrains.annotations.NotNull;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vcs.VcsException;
import com.intellij.openapi.vcs.AbstractVcs;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.ui.Messages;
import git4idea.GitVcs;
import git4idea.GitUtil;
import git4idea.commands.GitCommand;

import java.util.List;

/**
 * Git action for showing the current branch
 */
public class GitCurrentBranch extends BasicAction {
    @Override
    protected void perform(@NotNull Project project, GitVcs vcs, @NotNull List<VcsException> exceptions,
            @NotNull VirtualFile[] files) throws VcsException {

        GitCommand cmd = new GitCommand(project, vcs.getSettings(), GitUtil.getVcsRoot(project, files[0]));
        Messages.showInfoMessage(project, "Checked out branch: " + cmd.currentBranch(), "Current Branch");
    }

    @Override
    @NotNull
    protected String getActionName(@NotNull AbstractVcs abstractvcs) {
        return "CurrentBranch";
    }

    @Override
    protected boolean isEnabled(@NotNull Project project, @NotNull GitVcs mksvcs, @NotNull VirtualFile... vFiles) {
        return true;
    }
}