2 * Copyright 2000-2011 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package git4idea.push;
18 import com.intellij.openapi.util.Pair;
19 import com.intellij.openapi.vcs.VcsException;
20 import git4idea.GitBranch;
21 import git4idea.GitUtil;
22 import git4idea.branch.GitBranchPair;
23 import git4idea.repo.GitRemote;
24 import git4idea.repo.GitRepository;
25 import org.jetbrains.annotations.NotNull;
26 import org.jetbrains.annotations.Nullable;
29 * @author Kirill Likhodedov
31 public class GitPushSpec {
33 @NotNull private final GitRemote myRemote;
34 @NotNull private final GitBranch mySource;
35 @NotNull private final GitBranch myDest;
37 GitPushSpec(@NotNull GitRemote remote, @NotNull GitBranch source, @NotNull GitBranch dest) {
44 public GitRemote getRemote() {
49 public GitBranch getSource() {
54 public GitBranch getDest() {
59 private static GitBranchPair findSourceDestForBranch(GitRepository repository, GitBranch branch) throws VcsException {
60 GitBranch trackedBranch = branch.tracked(repository.getProject(), repository.getRoot());
61 if (trackedBranch != null) {
62 return new GitBranchPair(branch, trackedBranch);
64 Pair<GitRemote,GitBranch> remoteAndBranch = GitUtil.findMatchingRemoteBranch(repository, branch);
65 if (remoteAndBranch == null) {
68 GitBranch matchingRemoteBranch = remoteAndBranch.getSecond();
69 if (matchingRemoteBranch != null) {
70 return new GitBranchPair(branch, matchingRemoteBranch);
76 public String toString() {
77 return myRemote + " " + mySource + "->" + myDest;