From 1d09e47880ea1cec189e005e16903946b755ce25 Mon Sep 17 00:00:00 2001 From: Aleksey Pivovarov Date: Tue, 10 Sep 2013 14:14:33 +0400 Subject: [PATCH] Github: fetch a single branch for diff * fix TargetBranchInfo once more --- .../src/git4idea/update/GitFetcher.java | 15 ++++++----- .../github/GithubCreatePullRequestAction.java | 27 ++++++++++++------- .../plugins/github/GithubRebaseAction.java | 2 +- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/plugins/git4idea/src/git4idea/update/GitFetcher.java b/plugins/git4idea/src/git4idea/update/GitFetcher.java index 758797404008..edac044604a7 100644 --- a/plugins/git4idea/src/git4idea/update/GitFetcher.java +++ b/plugins/git4idea/src/git4idea/update/GitFetcher.java @@ -94,7 +94,7 @@ public class GitFetcher { } @NotNull - public GitFetchResult fetch(@NotNull VirtualFile root, @NotNull String remoteName) { + public GitFetchResult fetch(@NotNull VirtualFile root, @NotNull String remoteName, @Nullable String branch) { GitRepository repository = myRepositoryManager.getRepositoryForRoot(root); if (repository == null) { return logError("Repository can't be null for " + root, myRepositoryManager.toString()); @@ -107,7 +107,7 @@ public class GitFetcher { if (url == null) { return logError("URL is null for remote " + remote.getName(), null); } - return fetchRemote(repository, remote, url); + return fetchRemote(repository, remote, url, branch); } private static GitFetchResult logError(@NotNull String message, @Nullable String additionalInfo) { @@ -125,15 +125,18 @@ public class GitFetcher { GitRemote remote = fetchParams.getRemote(); String url = fetchParams.getUrl(); - return fetchRemote(repository, remote, url); + return fetchRemote(repository, remote, url, null); } @NotNull - private GitFetchResult fetchRemote(@NotNull GitRepository repository, @NotNull GitRemote remote, @NotNull String url) { + private GitFetchResult fetchRemote(@NotNull GitRepository repository, + @NotNull GitRemote remote, + @NotNull String url, + @Nullable String branch) { if (GitHttpAdapter.shouldUseJGit(url)) { - return GitHttpAdapter.fetch(repository, remote, url, null); + return GitHttpAdapter.fetch(repository, remote, url, branch); } - return fetchNatively(repository.getRoot(), remote, url, null); + return fetchNatively(repository.getRoot(), remote, url, branch); } // leaving this unused method, because the wanted behavior can change again diff --git a/plugins/github/src/org/jetbrains/plugins/github/GithubCreatePullRequestAction.java b/plugins/github/src/org/jetbrains/plugins/github/GithubCreatePullRequestAction.java index ed80ab80e09c..4147d9cc8beb 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/GithubCreatePullRequestAction.java +++ b/plugins/github/src/org/jetbrains/plugins/github/GithubCreatePullRequestAction.java @@ -43,6 +43,7 @@ import git4idea.DialogManager; import git4idea.GitCommit; import git4idea.GitLocalBranch; import git4idea.GitRemoteBranch; +import git4idea.branch.GitBranchUtil; import git4idea.changes.GitChangeUtils; import git4idea.commands.Git; import git4idea.commands.GitCommand; @@ -439,13 +440,14 @@ public class GithubCreatePullRequestAction extends DumbAwareAction { return null; } - GitFetchResult result = new GitFetcher(project, indicator, false).fetch(gitRepository.getRoot(), targetBranchInfo.getRemote()); + GitFetchResult result = new GitFetcher(project, indicator, false) + .fetch(gitRepository.getRoot(), targetBranchInfo.getRemote(), targetBranchInfo.getBranchNameForRemoteOperations()); if (!result.isSuccess()) { GitFetcher.displayFetchResult(project, result, null, result.getErrors()); return null; } - DiffInfo info = getDiffInfo(project, gitRepository, currentBranch, targetBranchInfo.getBranch()); + DiffInfo info = getDiffInfo(project, gitRepository, currentBranch, targetBranchInfo.getBranchNameForLocalOperations()); if (info == null) { ApplicationManager.getApplication().invokeLater(new Runnable() { @Override @@ -467,7 +469,7 @@ public class GithubCreatePullRequestAction extends DumbAwareAction { } private static TargetBranchInfo getTargetBranchInfo(@NotNull GitRemoteBranch remoteBranch) { - return new TargetBranchInfo(remoteBranch.getRemote().getName(), remoteBranch.getNameForLocalOperations()); + return new TargetBranchInfo(remoteBranch.getRemote().getName(), remoteBranch.getNameForRemoteOperations()); } @Nullable @@ -477,7 +479,7 @@ public class GithubCreatePullRequestAction extends DumbAwareAction { for (GitRemote remote : gitRepository.getRemotes()) { for (String url : remote.getUrls()) { if (forkPath.equals(GithubUrlUtil.getUserAndRepositoryFromRemoteUrl(url))) { - return new TargetBranchInfo(remote.getName(), remote.getName() + "/" + branch); + return new TargetBranchInfo(remote.getName(), branch); } } } @@ -648,11 +650,13 @@ public class GithubCreatePullRequestAction extends DumbAwareAction { private static class TargetBranchInfo { @NotNull private final String myRemote; - @NotNull private final String myBranch; + @NotNull private final String myName; + @NotNull private final String myNameAtRemote; - private TargetBranchInfo(@NotNull String remote, @NotNull String branch) { + private TargetBranchInfo(@NotNull String remote, @NotNull String nameAtRemote) { myRemote = remote; - myBranch = branch; + myNameAtRemote = GitBranchUtil.stripRefsPrefix(nameAtRemote); + myName = myRemote + "/" + myNameAtRemote; } @NotNull @@ -661,8 +665,13 @@ public class GithubCreatePullRequestAction extends DumbAwareAction { } @NotNull - public String getBranch() { - return myBranch; + public String getBranchNameForLocalOperations() { + return myName; + } + + @NotNull + public String getBranchNameForRemoteOperations() { + return myNameAtRemote; } } } diff --git a/plugins/github/src/org/jetbrains/plugins/github/GithubRebaseAction.java b/plugins/github/src/org/jetbrains/plugins/github/GithubRebaseAction.java index 1db546b1c0bd..2bdd8c2cbb60 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/GithubRebaseAction.java +++ b/plugins/github/src/org/jetbrains/plugins/github/GithubRebaseAction.java @@ -241,7 +241,7 @@ public class GithubRebaseAction extends DumbAwareAction { private static boolean fetchParent(@NotNull final Project project, @NotNull final GitRepository repository, @NotNull final ProgressIndicator indicator) { - GitFetchResult result = new GitFetcher(project, indicator, false).fetch(repository.getRoot(), "upstream"); + GitFetchResult result = new GitFetcher(project, indicator, false).fetch(repository.getRoot(), "upstream", null); if (!result.isSuccess()) { GitFetcher.displayFetchResult(project, result, null, result.getErrors()); return false;