use of git4idea.repo.GitRemote in project intellij-community by JetBrains.
the class GitPushTarget method parse.
@NotNull
public static GitPushTarget parse(@NotNull GitRepository repository, @Nullable String remoteName, @NotNull String branchName) throws ParseException {
if (remoteName == null) {
throw new ParseException("No remotes defined", -1);
}
if (!GitRefNameValidator.getInstance().checkInput(branchName)) {
throw new ParseException("Invalid destination branch name: " + branchName, -1);
}
GitRemote remote = findRemote(repository.getRemotes(), remoteName);
if (remote == null) {
LOG.error("Remote [" + remoteName + "] is not found among " + repository.getRemotes());
throw new ParseException("Invalid remote: " + remoteName, -1);
}
GitRemoteBranch existingRemoteBranch = findRemoteBranch(repository, remote, branchName);
if (existingRemoteBranch != null) {
return new GitPushTarget(existingRemoteBranch, false);
}
GitRemoteBranch rb = new GitStandardRemoteBranch(remote, branchName);
return new GitPushTarget(rb, true);
}
use of git4idea.repo.GitRemote in project intellij-community by JetBrains.
the class GitPullDialog method updateRemotes.
private void updateRemotes() {
GitRepository repository = getRepository();
if (repository == null) {
return;
}
GitRemote currentRemote = getCurrentOrDefaultRemote(repository);
myRemote.setRenderer(getGitRemoteListCellRenderer(currentRemote != null ? currentRemote.getName() : null));
myRemote.removeAllItems();
for (GitRemote remote : repository.getRemotes()) {
myRemote.addItem(remote);
}
myRemote.setSelectedItem(currentRemote);
}
use of git4idea.repo.GitRemote in project intellij-community by JetBrains.
the class GitRebaseDialog method updateTrackedBranch.
/**
* Update tracked branch basing on the currently selected branch
*/
private void updateTrackedBranch() {
try {
final VirtualFile root = gitRoot();
String currentBranch = (String) myBranchComboBox.getSelectedItem();
GitBranch trackedBranch = null;
if (currentBranch != null) {
String remote = GitConfigUtil.getValue(myProject, root, "branch." + currentBranch + ".remote");
String mergeBranch = GitConfigUtil.getValue(myProject, root, "branch." + currentBranch + ".merge");
if (remote == null || mergeBranch == null) {
trackedBranch = null;
} else {
mergeBranch = GitBranchUtil.stripRefsPrefix(mergeBranch);
if (remote.equals(".")) {
trackedBranch = new GitSvnRemoteBranch(mergeBranch);
} else {
GitRemote r = GitBranchUtil.findRemoteByNameOrLogError(myProject, root, remote);
if (r != null) {
trackedBranch = new GitStandardRemoteBranch(r, mergeBranch);
}
}
}
}
if (trackedBranch != null) {
myOntoComboBox.setSelectedItem(trackedBranch);
} else {
GitUIUtil.getTextField(myOntoComboBox).setText("");
}
GitUIUtil.getTextField(myFromComboBox).setText("");
} catch (VcsException e) {
GitUIUtil.showOperationError(myProject, e, "git config");
}
}
use of git4idea.repo.GitRemote in project intellij-community by JetBrains.
the class GitFetcher method getFetchParams.
@NotNull
private static FetchParams getFetchParams(@NotNull GitRepository repository) {
GitLocalBranch currentBranch = repository.getCurrentBranch();
if (currentBranch == null) {
// fetching current branch is called from Update Project and Push, where branch tracking is pre-checked
String message = "Current branch can't be null here. \nRepository: " + repository;
LOG.error(message);
return new FetchParams(GitFetchResult.error(new Exception(message)));
}
GitBranchTrackInfo trackInfo = GitBranchUtil.getTrackInfoForBranch(repository, currentBranch);
if (trackInfo == null) {
String message = "Tracked info is null for branch " + currentBranch + "\n Repository: " + repository;
LOG.error(message);
return new FetchParams(GitFetchResult.error(new Exception(message)));
}
GitRemote remote = trackInfo.getRemote();
return new FetchParams(remote, trackInfo.getRemoteBranch());
}
use of git4idea.repo.GitRemote in project intellij-community by JetBrains.
the class GitFetcher method fetch.
@NotNull
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());
}
GitRemote remote = GitUtil.findRemoteByName(repository, remoteName);
if (remote == null) {
return logError("Couldn't find remote with the name " + remoteName, null);
}
return fetchRemote(repository, remote, branch);
}
Aggregations