GitSimpleEventDetector unmergedFiles = new GitSimpleEventDetector(GitSimpleEventDetector.Event.UNMERGED);
GitMessageWithFilesDetector untrackedOverwrittenByCheckout = new GitMessageWithFilesDetector(UNTRACKED_FILES_OVERWRITTEN_BY, root);
- GitCommandResult result = Git.checkout(repository, myStartPointReference, myNewBranch,
+ GitCommandResult result = Git.checkout(repository, myStartPointReference, myNewBranch, false,
localChangesOverwrittenByCheckout, unmergedFiles, untrackedOverwrittenByCheckout);
if (result.success()) {
refresh(repository);
// get all other conflicting changes
Map<GitRepository, List<Change>> conflictingChangesInRepositories = collectLocalChangesOnAllOtherRepositories(repository);
Set<GitRepository> otherProblematicRepositories = conflictingChangesInRepositories.keySet();
- Collection<GitRepository> allConflictingRepositories = new ArrayList<GitRepository>(otherProblematicRepositories);
+ List<GitRepository> allConflictingRepositories = new ArrayList<GitRepository>(otherProblematicRepositories);
allConflictingRepositories.add(repository);
for (List<Change> changes : conflictingChangesInRepositories.values()) {
affectedChanges.addAll(changes);
}
- if (GitWouldBeOverwrittenByCheckoutDialog.showAndGetAnswer(myProject, affectedChanges)) {
+ int smartCheckoutDecision = GitWouldBeOverwrittenByCheckoutDialog.showAndGetAnswer(myProject, affectedChanges);
+ if (smartCheckoutDecision == GitWouldBeOverwrittenByCheckoutDialog.SMART_CHECKOUT) {
boolean smartCheckedOutSuccessfully = smartCheckout(allConflictingRepositories, myStartPointReference, myNewBranch, getIndicator());
if (smartCheckedOutSuccessfully) {
GitRepository[] otherRepositories = ArrayUtil.toObjectArray(otherProblematicRepositories, GitRepository.class);
return false;
}
}
+ else if (smartCheckoutDecision == GitWouldBeOverwrittenByCheckoutDialog.FORCE_CHECKOUT_EXIT_CODE) {
+ return checkoutOrNotify(allConflictingRepositories, myStartPointReference, myNewBranch, true);
+ }
else {
fatalLocalChangesError();
return false;
GitCompoundResult checkoutResult = new GitCompoundResult(myProject);
GitCompoundResult deleteResult = new GitCompoundResult(myProject);
for (GitRepository repository : getSuccessfulRepositories()) {
- GitCommandResult result = Git.checkout(repository, myPreviousBranch, null);
+ GitCommandResult result = Git.checkout(repository, myPreviousBranch, null, true);
checkoutResult.append(repository, result);
if (result.success() && myNewBranch != null) {
/*
}
// stash - checkout - unstash
- private boolean smartCheckout(@NotNull final Collection<GitRepository> repositories, @NotNull final String reference, @Nullable final String newBranch, @NotNull ProgressIndicator indicator) {
+ private boolean smartCheckout(@NotNull final List<GitRepository> repositories, @NotNull final String reference, @Nullable final String newBranch, @NotNull ProgressIndicator indicator) {
final GitChangesSaver saver = configureSaver(reference, indicator);
final AtomicBoolean result = new AtomicBoolean();
boolean savedSuccessfully = save(repositories, saver);
if (savedSuccessfully) {
try {
- result.set(checkoutOrNotify(repositories, reference, newBranch));
+ result.set(checkoutOrNotify(repositories, reference, newBranch, false));
} finally {
saver.restoreLocalChanges(context);
}
/**
* Checks out or shows an error message.
*/
- private boolean checkoutOrNotify(@NotNull Collection<GitRepository> repositories,
- @NotNull String reference,
- @Nullable String newBranch) {
+ private boolean checkoutOrNotify(@NotNull List<GitRepository> repositories,
+ @NotNull String reference, @Nullable String newBranch, boolean force) {
GitCompoundResult compoundResult = new GitCompoundResult(myProject);
for (GitRepository repository : repositories) {
- compoundResult.append(repository, Git.checkout(repository, reference, newBranch));
+ compoundResult.append(repository, Git.checkout(repository, reference, newBranch, force));
}
if (compoundResult.totalSuccess()) {
return true;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
+import java.awt.event.ActionEvent;
import java.util.List;
-import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
/**
* The dialog that is shown when the error "The following files would be overwritten by checkout" happens.
// TODO "don't ask again" option
class GitWouldBeOverwrittenByCheckoutDialog extends DialogWrapper {
+ public static final int SMART_CHECKOUT = OK_EXIT_CODE;
+ public static final int FORCE_CHECKOUT_EXIT_CODE = NEXT_USER_EXIT_CODE;
+
private final Project myProject;
private final List<Change> myChanges;
/**
* @return true if smart checkout has to be performed, false if user doesn't want to checkout.
*/
- static boolean showAndGetAnswer(@NotNull final Project project, @NotNull final List<Change> changes) {
- final AtomicBoolean ok = new AtomicBoolean();
+ static int showAndGetAnswer(@NotNull final Project project, @NotNull final List<Change> changes) {
+ final AtomicInteger exitCode = new AtomicInteger();
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
@Override
public void run() {
GitWouldBeOverwrittenByCheckoutDialog dialog = new GitWouldBeOverwrittenByCheckoutDialog(project, changes);
DialogManager.getInstance(project).showDialog(dialog);
- ok.set(dialog.isOK());
+ exitCode.set(dialog.getExitCode());
}
});
- return ok.get();
+ return exitCode.get();
}
private GitWouldBeOverwrittenByCheckoutDialog(@NotNull Project project, @NotNull List<Change> changes) {
}
@Override
- protected Action getOKAction() {
- return super.getOKAction();
+ protected Action[] createLeftSideActions() {
+ return new Action[] {new ForceCheckoutAction() };
}
@Override
return GitWouldBeOverwrittenByCheckoutDialog.class.getName();
}
+
+ private class ForceCheckoutAction extends AbstractAction {
+
+ ForceCheckoutAction() {
+ super("Force checkout");
+ }
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ close(FORCE_CHECKOUT_EXIT_CODE);
+ }
+ }
+
}