use of git4idea.repo.GitRepository in project intellij-community by JetBrains.
the class GitAbortRebaseProcess method doAbort.
private void doAbort(final boolean rollback) {
new GitFreezingProcess(myProject, "rebase", new Runnable() {
public void run() {
AccessToken token = DvcsUtil.workingTreeChangeStarted(myProject);
List<GitRepository> repositoriesToRefresh = ContainerUtil.newArrayList();
try {
if (myRepositoryToAbort != null) {
myIndicator.setText2("git rebase --abort" + GitUtil.mention(myRepositoryToAbort));
GitCommandResult result = myGit.rebaseAbort(myRepositoryToAbort);
repositoriesToRefresh.add(myRepositoryToAbort);
if (!result.success()) {
myNotifier.notifyError("Rebase Abort Failed", result.getErrorOutputAsHtmlString() + mentionLocalChangesRemainingInStash(mySaver));
return;
}
}
if (rollback) {
for (GitRepository repo : myRepositoriesToRollback.keySet()) {
myIndicator.setText2("git reset --keep" + GitUtil.mention(repo));
GitCommandResult res = myGit.reset(repo, GitResetMode.KEEP, myRepositoriesToRollback.get(repo));
repositoriesToRefresh.add(repo);
if (res.success()) {
String initialBranchPosition = myInitialCurrentBranches.get(repo);
if (initialBranchPosition != null && !initialBranchPosition.equals(repo.getCurrentBranchName())) {
myIndicator.setText2("git checkout " + initialBranchPosition + GitUtil.mention(repo));
res = myGit.checkout(repo, initialBranchPosition, null, true, false);
}
}
if (!res.success()) {
String description = myRepositoryToAbort != null ? "Rebase abort was successful" + GitUtil.mention(myRepositoryToAbort) + ", but rollback failed" : "Rollback failed";
description += GitUtil.mention(repo) + ":" + res.getErrorOutputAsHtmlString() + mentionLocalChangesRemainingInStash(mySaver);
myNotifier.notifyImportantWarning("Rebase Rollback Failed", description);
return;
}
}
}
if (mySaver != null) {
mySaver.load();
}
myNotifier.notifySuccess("Rebase abort succeeded");
} finally {
refresh(repositoriesToRefresh);
token.finish();
}
}
}).execute();
}
use of git4idea.repo.GitRepository in project intellij-community by JetBrains.
the class GitRebaseDialog method loadRefs.
/**
* Load tags and branches
*/
protected void loadRefs() {
try {
myLocalBranches.clear();
myRemoteBranches.clear();
myTags.clear();
final VirtualFile root = gitRoot();
GitRepository repository = GitUtil.getRepositoryManager(myProject).getRepositoryForRoot(root);
if (repository != null) {
myLocalBranches.addAll(repository.getBranches().getLocalBranches());
myRemoteBranches.addAll(repository.getBranches().getRemoteBranches());
myCurrentBranch = repository.getCurrentBranch();
} else {
LOG.error("Repository is null for root " + root);
}
GitTag.list(myProject, root, myTags);
} catch (VcsException e) {
GitUIUtil.showOperationError(myProject, e, "git branch -a");
}
}
use of git4idea.repo.GitRepository in project intellij-community by JetBrains.
the class GitRebaseProcess method doRebase.
/**
* Given a GitRebaseSpec this method either starts, or continues the ongoing rebase in multiple repositories.
* <ul>
* <li>It does nothing with "already successfully rebased repositories" (the ones which have {@link GitRebaseStatus} == SUCCESSFUL,
* and just remembers them to use in the resulting notification.</li>
* <li>If there is a repository with rebase in progress, it calls `git rebase --continue` (or `--skip`).
* It is assumed that there is only one such repository.</li>
* <li>For all remaining repositories rebase on which didn't start yet, it calls {@code git rebase <original parameters>}</li>
* </ul>
*/
private void doRebase() {
LOG.info("Started rebase");
LOG.debug("Started rebase with the following spec: " + myRebaseSpec);
Map<GitRepository, GitRebaseStatus> statuses = newLinkedHashMap(myRebaseSpec.getStatuses());
Collection<GitRepository> toRefresh = newLinkedHashSet();
List<GitRepository> repositoriesToRebase = myRebaseSpec.getIncompleteRepositories();
AccessToken token = DvcsUtil.workingTreeChangeStarted(myProject);
try {
if (!saveDirtyRootsInitially(repositoriesToRebase))
return;
GitRepository failed = null;
for (GitRepository repository : repositoriesToRebase) {
GitRebaseResumeMode customMode = null;
if (repository == myRebaseSpec.getOngoingRebase()) {
customMode = myCustomMode == null ? GitRebaseResumeMode.CONTINUE : myCustomMode;
}
GitRebaseStatus rebaseStatus = rebaseSingleRoot(repository, customMode, getSuccessfulRepositories(statuses));
// make the repo state info actual ASAP
repository.update();
statuses.put(repository, rebaseStatus);
if (shouldBeRefreshed(rebaseStatus)) {
toRefresh.add(repository);
}
if (rebaseStatus.getType() != GitRebaseStatus.Type.SUCCESS) {
failed = repository;
break;
}
}
if (failed == null) {
LOG.debug("Rebase completed successfully.");
mySaver.load();
}
refresh(toRefresh);
if (failed == null) {
notifySuccess(getSuccessfulRepositories(statuses), getSkippedCommits(statuses));
}
saveUpdatedSpec(statuses);
} catch (ProcessCanceledException pce) {
throw pce;
} catch (Throwable e) {
myRepositoryManager.setOngoingRebaseSpec(null);
ExceptionUtil.rethrowUnchecked(e);
} finally {
token.finish();
}
}
use of git4idea.repo.GitRepository in project intellij-community by JetBrains.
the class GitRebaseSpec method forNewRebase.
@NotNull
public static GitRebaseSpec forNewRebase(@NotNull Project project, @NotNull GitRebaseParams params, @NotNull Collection<GitRepository> repositories, @NotNull ProgressIndicator indicator) {
GitUtil.updateRepositories(repositories);
Map<GitRepository, String> initialHeadPositions = findInitialHeadPositions(repositories, params.getBranch());
Map<GitRepository, String> initialBranchNames = findInitialBranchNames(repositories);
Map<GitRepository, GitRebaseStatus> initialStatusMap = new TreeMap<>(DvcsUtil.REPOSITORY_COMPARATOR);
for (GitRepository repository : repositories) {
initialStatusMap.put(repository, GitRebaseStatus.notStarted());
}
return new GitRebaseSpec(params, initialStatusMap, initialHeadPositions, initialBranchNames, newSaver(project, indicator), true);
}
use of git4idea.repo.GitRepository in project intellij-community by JetBrains.
the class GitRebaseUtils method getRebaseDir.
/**
* Get rebase directory
*
* @param root the vcs root
* @return the rebase directory or null if it does not exist.
*/
@Nullable
private static File getRebaseDir(@NotNull Project project, @NotNull VirtualFile root) {
GitRepository repository = assertNotNull(GitUtil.getRepositoryManager(project).getRepositoryForRoot(root));
File f = repository.getRepositoryFiles().getRebaseApplyDir();
if (f.exists()) {
return f;
}
f = repository.getRepositoryFiles().getRebaseMergeDir();
if (f.exists()) {
return f;
}
return null;
}
Aggregations