use of git4idea.repo.GitRepository in project intellij-community by JetBrains.
the class GitCheckoutOperation method rollback.
@Override
protected void rollback() {
GitCompoundResult checkoutResult = new GitCompoundResult(myProject);
GitCompoundResult deleteResult = new GitCompoundResult(myProject);
for (GitRepository repository : getSuccessfulRepositories()) {
GitCommandResult result = myGit.checkout(repository, myCurrentHeads.get(repository), null, true, false);
checkoutResult.append(repository, result);
if (result.success() && myNewBranch != null) {
/*
force delete is needed, because we create new branch from branch other that the current one
e.g. being on master create newBranch from feature,
then rollback => newBranch is not fully merged to master (although it is obviously fully merged to feature).
*/
deleteResult.append(repository, myGit.branchDelete(repository, myNewBranch, true));
}
refresh(repository);
}
if (!checkoutResult.totalSuccess() || !deleteResult.totalSuccess()) {
StringBuilder message = new StringBuilder();
if (!checkoutResult.totalSuccess()) {
message.append("Errors during checkout: ");
message.append(checkoutResult.getErrorOutputWithReposIndication());
}
if (!deleteResult.totalSuccess()) {
message.append("Errors during deleting ").append(code(myNewBranch)).append(": ");
message.append(deleteResult.getErrorOutputWithReposIndication());
}
VcsNotifier.getInstance(myProject).notifyError("Error during rollback", message.toString());
}
}
use of git4idea.repo.GitRepository in project intellij-community by JetBrains.
the class GitDeleteBranchOperation method showNotFullyMergedDialog.
/**
* Shows a dialog "the branch is not fully merged" with the list of unmerged commits.
* User may still want to force delete the branch.
* In multi-repository setup collects unmerged commits for all given repositories.
* @return true if the branch should be restored.
*/
private boolean showNotFullyMergedDialog(@NotNull Map<GitRepository, UnmergedBranchInfo> unmergedBranches) {
Map<GitRepository, List<GitCommit>> history = new HashMap<>();
// we display no commits for them
for (GitRepository repository : getRepositories()) {
if (unmergedBranches.containsKey(repository)) {
UnmergedBranchInfo unmergedInfo = unmergedBranches.get(repository);
history.put(repository, getUnmergedCommits(repository, unmergedInfo.myTipOfDeletedUnmergedBranch, unmergedInfo.myBaseBranch));
} else {
history.put(repository, Collections.<GitCommit>emptyList());
}
}
Map<GitRepository, String> baseBranches = Maps.asMap(unmergedBranches.keySet(), it -> unmergedBranches.get(it).myBaseBranch);
return myUiHandler.showBranchIsNotFullyMergedDialog(myProject, history, baseBranches, myBranchName);
}
use of git4idea.repo.GitRepository in project intellij-community by JetBrains.
the class GitDeleteBranchOperation method execute.
@Override
public void execute() {
boolean fatalErrorHappened = false;
while (hasMoreRepositories() && !fatalErrorHappened) {
final GitRepository repository = next();
GitSimpleEventDetector notFullyMergedDetector = new GitSimpleEventDetector(GitSimpleEventDetector.Event.BRANCH_NOT_FULLY_MERGED);
GitBranchNotMergedToUpstreamDetector notMergedToUpstreamDetector = new GitBranchNotMergedToUpstreamDetector();
GitCommandResult result = myGit.branchDelete(repository, myBranchName, false, notFullyMergedDetector, notMergedToUpstreamDetector);
if (result.success()) {
refresh(repository);
markSuccessful(repository);
} else if (notFullyMergedDetector.hasHappened()) {
String baseBranch = notMergedToUpstreamDetector.getBaseBranch();
if (baseBranch == null) {
// GitBranchNotMergedToUpstreamDetector didn't happen
baseBranch = myCurrentHeads.get(repository);
}
myUnmergedToBranches.put(repository, new UnmergedBranchInfo(myDeletedBranchTips.get(repository), GitBranchUtil.stripRefsPrefix(baseBranch)));
GitCommandResult forceDeleteResult = myGit.branchDelete(repository, myBranchName, true);
if (forceDeleteResult.success()) {
refresh(repository);
markSuccessful(repository);
} else {
fatalError(getErrorTitle(), forceDeleteResult.getErrorOutputAsHtmlString());
fatalErrorHappened = true;
}
} else {
fatalError(getErrorTitle(), result.getErrorOutputAsJoinedString());
fatalErrorHappened = true;
}
}
if (!fatalErrorHappened) {
notifySuccess();
}
}
use of git4idea.repo.GitRepository in project intellij-community by JetBrains.
the class GitDeleteBranchOperation method doRollback.
@NotNull
private GitCompoundResult doRollback() {
GitCompoundResult result = new GitCompoundResult(myProject);
for (GitRepository repository : getSuccessfulRepositories()) {
GitCommandResult res = myGit.branchCreate(repository, myBranchName, myDeletedBranchTips.get(repository));
result.append(repository, res);
for (String trackedBranch : myTrackedBranches.keySet()) {
if (myTrackedBranches.get(trackedBranch).contains(repository)) {
GitCommandResult setTrackResult = setUpTracking(repository, myBranchName, trackedBranch);
if (!setTrackResult.success()) {
LOG.warn("Couldn't set " + myBranchName + " to track " + trackedBranch + " in " + repository.getRoot().getName() + ": " + setTrackResult.getErrorOutputAsJoinedString());
}
}
}
refresh(repository);
}
return result;
}
use of git4idea.repo.GitRepository in project intellij-community by JetBrains.
the class GitDeleteRemoteBranchOperation method doDeleteRemote.
private boolean doDeleteRemote(@NotNull String branchName, @NotNull Collection<GitRepository> repositories) {
Couple<String> pair = splitNameOfRemoteBranch(branchName);
String remoteName = pair.getFirst();
String branch = pair.getSecond();
GitCompoundResult result = new GitCompoundResult(myProject);
for (GitRepository repository : repositories) {
GitCommandResult res;
GitRemote remote = getRemoteByName(repository, remoteName);
if (remote == null) {
String error = "Couldn't find remote by name: " + remoteName;
LOG.error(error);
res = GitCommandResult.error(error);
} else {
res = pushDeletion(repository, remote, branch);
if (!res.success() && isAlreadyDeletedError(res.getErrorOutputAsJoinedString())) {
res = myGit.remotePrune(repository, remote);
}
}
result.append(repository, res);
repository.update();
}
if (!result.totalSuccess()) {
VcsNotifier.getInstance(myProject).notifyError("Failed to delete remote branch " + branchName, result.getErrorOutputWithReposIndication());
}
return result.totalSuccess();
}
Aggregations