use of git4idea.GitLocalBranch in project intellij-community by JetBrains.
the class GitConfig method convertBranchConfig.
@Nullable
private static GitBranchTrackInfo convertBranchConfig(@Nullable BranchConfig branchConfig, @NotNull Collection<GitLocalBranch> localBranches, @NotNull Collection<GitRemoteBranch> remoteBranches) {
if (branchConfig == null) {
return null;
}
final String branchName = branchConfig.getName();
String remoteName = branchConfig.getBean().getRemote();
String mergeName = branchConfig.getBean().getMerge();
String rebaseName = branchConfig.getBean().getRebase();
if (StringUtil.isEmptyOrSpaces(mergeName) && StringUtil.isEmptyOrSpaces(rebaseName)) {
LOG.info("No branch." + branchName + ".merge/rebase item in the .git/config");
return null;
}
if (StringUtil.isEmptyOrSpaces(remoteName)) {
LOG.info("No branch." + branchName + ".remote item in the .git/config");
return null;
}
boolean merge = mergeName != null;
final String remoteBranchName = StringUtil.unquoteString(merge ? mergeName : rebaseName);
GitLocalBranch localBranch = findLocalBranch(branchName, localBranches);
GitRemoteBranch remoteBranch = findRemoteBranch(remoteBranchName, remoteName, remoteBranches);
if (localBranch == null || remoteBranch == null) {
// obsolete record in .git/config: local or remote branch doesn't exist, but the tracking information wasn't removed
LOG.debug("localBranch: " + localBranch + ", remoteBranch: " + remoteBranch);
return null;
}
return new GitBranchTrackInfo(localBranch, remoteBranch, merge);
}
use of git4idea.GitLocalBranch in project intellij-community by JetBrains.
the class GitBranchWorker method checkoutNewBranch.
public void checkoutNewBranch(@NotNull final String name, @NotNull List<GitRepository> repositories) {
updateInfo(repositories);
repositories = ContainerUtil.filter(repositories, new Condition<GitRepository>() {
@Override
public boolean value(GitRepository repository) {
GitLocalBranch currentBranch = repository.getCurrentBranch();
return currentBranch == null || !currentBranch.getName().equals(name);
}
});
if (!repositories.isEmpty()) {
new GitCheckoutNewBranchOperation(myProject, myGit, myUiHandler, repositories, name).execute();
} else {
LOG.error("Creating new branch the same as current in all repositories: " + name);
}
}
use of git4idea.GitLocalBranch in project intellij-community by JetBrains.
the class GithubCreatePullRequestWorker method create.
@Nullable
public static GithubCreatePullRequestWorker create(@NotNull final Project project, @Nullable final VirtualFile file) {
return GithubUtil.computeValueInModal(project, "Loading data...", indicator -> {
Git git = ServiceManager.getService(Git.class);
GitRepository gitRepository = GithubUtil.getGitRepository(project, file);
if (gitRepository == null) {
GithubNotifications.showError(project, CANNOT_CREATE_PULL_REQUEST, "Can't find git repository");
return null;
}
gitRepository.update();
Pair<GitRemote, String> remote = GithubUtil.findGithubRemote(gitRepository);
if (remote == null) {
GithubNotifications.showError(project, CANNOT_CREATE_PULL_REQUEST, "Can't find GitHub remote");
return null;
}
String remoteName = remote.getFirst().getName();
String remoteUrl = remote.getSecond();
GithubFullPath path = GithubUrlUtil.getUserAndRepositoryFromRemoteUrl(remoteUrl);
if (path == null) {
GithubNotifications.showError(project, CANNOT_CREATE_PULL_REQUEST, "Can't process remote: " + remoteUrl);
return null;
}
GitLocalBranch currentBranch = gitRepository.getCurrentBranch();
if (currentBranch == null) {
GithubNotifications.showError(project, CANNOT_CREATE_PULL_REQUEST, "No current branch");
return null;
}
GithubAuthDataHolder authHolder;
try {
authHolder = GithubUtil.getValidAuthDataHolderFromConfig(project, AuthLevel.LOGGED, indicator);
} catch (IOException e) {
GithubNotifications.showError(project, CANNOT_CREATE_PULL_REQUEST, e);
return null;
}
GithubCreatePullRequestWorker worker = new GithubCreatePullRequestWorker(project, git, gitRepository, authHolder, path, remoteName, remoteUrl, currentBranch.getName());
try {
worker.initForks(indicator);
} catch (IOException e) {
GithubNotifications.showError(project, CANNOT_CREATE_PULL_REQUEST, e);
return null;
}
return worker;
});
}
use of git4idea.GitLocalBranch in project intellij-community by JetBrains.
the class GitPushOperation method push.
@NotNull
private Map<GitRepository, GitPushRepoResult> push(@NotNull Collection<GitRepository> repositories) {
Map<GitRepository, GitPushRepoResult> results = ContainerUtil.newLinkedHashMap();
for (GitRepository repository : repositories) {
PushSpec<GitPushSource, GitPushTarget> spec = myPushSpecs.get(repository);
ResultWithOutput resultWithOutput = doPush(repository, spec);
LOG.debug("Pushed to " + DvcsUtil.getShortRepositoryName(repository) + ": " + resultWithOutput);
GitLocalBranch source = spec.getSource().getBranch();
GitPushTarget target = spec.getTarget();
GitPushRepoResult repoResult;
if (resultWithOutput.isError()) {
repoResult = GitPushRepoResult.error(source, target.getBranch(), resultWithOutput.getErrorAsString());
} else {
List<GitPushNativeResult> result = resultWithOutput.parsedResults;
final GitPushNativeResult branchResult = getBranchResult(result);
if (branchResult == null) {
LOG.error("No result for branch among: [" + result + "]\n" + "Full result: " + resultWithOutput);
continue;
}
List<GitPushNativeResult> tagResults = ContainerUtil.filter(result, new Condition<GitPushNativeResult>() {
@Override
public boolean value(GitPushNativeResult result) {
return !result.equals(branchResult) && (result.getType() == GitPushNativeResult.Type.NEW_REF || result.getType() == GitPushNativeResult.Type.FORCED_UPDATE);
}
});
int commits = collectNumberOfPushedCommits(repository.getRoot(), branchResult);
repoResult = GitPushRepoResult.convertFromNative(branchResult, tagResults, commits, source, target.getBranch());
}
LOG.debug("Converted result: " + repoResult);
results.put(repository, repoResult);
}
// fill other not-processed repositories as not-pushed
for (GitRepository repository : repositories) {
if (!results.containsKey(repository)) {
PushSpec<GitPushSource, GitPushTarget> spec = myPushSpecs.get(repository);
results.put(repository, GitPushRepoResult.notPushed(spec.getSource().getBranch(), spec.getTarget().getBranch()));
}
}
return results;
}
use of git4idea.GitLocalBranch in project intellij-community by JetBrains.
the class GitPushOperation method doPush.
@NotNull
private ResultWithOutput doPush(@NotNull GitRepository repository, @NotNull PushSpec<GitPushSource, GitPushTarget> pushSpec) {
GitPushTarget target = pushSpec.getTarget();
GitLocalBranch sourceBranch = pushSpec.getSource().getBranch();
GitRemoteBranch targetBranch = target.getBranch();
GitLineHandlerListener progressListener = GitStandardProgressAnalyzer.createListener(myProgressIndicator);
boolean setUpstream = pushSpec.getTarget().isNewBranchCreated() && !branchTrackingInfoIsSet(repository, sourceBranch);
String tagMode = myTagMode == null ? null : myTagMode.getArgument();
String spec = sourceBranch.getFullName() + ":" + targetBranch.getNameForRemoteOperations();
GitCommandResult res = myGit.push(repository, targetBranch.getRemote(), spec, myForce, setUpstream, tagMode, progressListener);
return new ResultWithOutput(res);
}
Aggregations