mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Github: fetch a single branch for diff
* fix TargetBranchInfo once more
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user