Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plugin/src/main/java/git4idea/GitBranch.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
* </p>
* <p>
* <p>GitBranches are equal, if their full names are equal. That means that if two GitBranch objects have different hashes, they
* are considered equal. But in this case an error if logged, becase it means that one of this GitBranch instances is out-of-date, and
* are considered equal. But in this case an error if logged, because it means that one of this GitBranch instances is out-of-date, and
* it is required to use an {@link GitRepository#update(TrackedTopic...) updated} version.</p>
*/
public abstract class GitBranch extends GitReference
Expand Down
9 changes: 5 additions & 4 deletions plugin/src/main/java/git4idea/GitUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import consulo.application.progress.ProgressIndicator;
import consulo.application.progress.Task;
import consulo.git.localize.GitLocalize;
import consulo.localize.LocalizeValue;
import consulo.logging.Logger;
import consulo.project.Project;
import consulo.ui.annotation.RequiredUIAccess;
Expand Down Expand Up @@ -1013,13 +1014,13 @@ public static List<Change> findLocalChangesForPaths(
public static void showPathsInDialog(
@Nonnull Project project,
@Nonnull Collection<String> absolutePaths,
@Nonnull String title,
@Nullable String description
@Nonnull LocalizeValue title,
@Nonnull LocalizeValue description
) {
DialogBuilder builder = new DialogBuilder(project);
builder.setCenterPanel(new GitSimplePathsBrowser(project, absolutePaths));
if (description != null) {
builder.setNorthPanel(new MultiLineLabel(description));
if (description != LocalizeValue.empty()) {
builder.setNorthPanel(new MultiLineLabel(description.get()));
}
builder.addOkAction();
builder.setTitle(title);
Expand Down
2 changes: 1 addition & 1 deletion plugin/src/main/java/git4idea/GitVcs.java
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ public void checkVersion() {
myNotificationService.newError(VcsNotifier.IMPORTANT_ERROR_NOTIFICATION)
.title(LocalizeValue.localizeTODO("Unsupported Git version"))
.content(LocalizeValue.localizeTODO(message))
.optionalHyperlinkListener(new NotificationListener.Adapter() {
.hyperlinkListener(new NotificationListener.Adapter() {
@Override
protected void hyperlinkActivated(@Nonnull Notification notification, @Nonnull HyperlinkEvent e) {
if (SETTINGS_LINK.equals(e.getDescription())) {
Expand Down
6 changes: 3 additions & 3 deletions plugin/src/main/java/git4idea/branch/GitBranchOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,15 @@ protected GitBranchOperation(
public abstract LocalizeValue getSuccessMessage();

@Nonnull
protected abstract String getRollbackProposal();
protected abstract LocalizeValue getRollbackProposal();

/**
* Returns a short downcased name of the operation.
* It is used by some dialogs or notifications which are common to several operations.
* Some operations (like checkout new branch) can be not mentioned in these dialogs, so their operation names would be not used.
*/
@Nonnull
protected abstract String getOperationName();
protected abstract LocalizeValue getOperationName();

/**
* @return next repository that wasn't handled (e.g. checked out) yet.
Expand Down Expand Up @@ -224,7 +224,7 @@ protected void fatalError(@Nonnull LocalizeValue title, @Nonnull LocalizeValue m
}

protected void showFatalErrorDialogWithRollback(@Nonnull LocalizeValue title, @Nonnull LocalizeValue message) {
boolean rollback = myUiHandler.notifyErrorWithRollbackProposal(title.get(), message.get(), getRollbackProposal());
boolean rollback = myUiHandler.notifyErrorWithRollbackProposal(title, message, getRollbackProposal());
if (rollback) {
rollback();
}
Expand Down
109 changes: 62 additions & 47 deletions plugin/src/main/java/git4idea/branch/GitBranchUiHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Map;

import consulo.application.progress.ProgressIndicator;
import consulo.localize.LocalizeValue;
import org.intellij.lang.annotations.MagicConstant;
import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;
Expand All @@ -35,59 +36,73 @@
* Some methods return the choice selected by user to the calling code, if it is needed.</p>
* <p>The purpose of this class is to separate UI interaction from the main code, which would in particular simplify testing.</p>
*/
public interface GitBranchUiHandler
{

@Nonnull
public interface GitBranchUiHandler {
@Nonnull
ProgressIndicator getProgressIndicator();

boolean notifyErrorWithRollbackProposal(@Nonnull String title, @Nonnull String message, @Nonnull String rollbackProposal);

/**
* Shows notification about unmerged files preventing checkout, merge, etc.
*
* @param operationName
* @param repositories
*/
void showUnmergedFilesNotification(@Nonnull String operationName, @Nonnull Collection<GitRepository> repositories);
boolean notifyErrorWithRollbackProposal(@Nonnull LocalizeValue title, @Nonnull LocalizeValue message, @Nonnull LocalizeValue rollbackProposal);

/**
* Shows a modal notification about unmerged files preventing an operation, with "Rollback" button.
* Pressing "Rollback" would should the operation which has already successfully executed on other repositories.
*
* @param operationName
* @param rollbackProposal
* @return true if user has agreed to rollback, false if user denied the rollback proposal.
*/
boolean showUnmergedFilesMessageWithRollback(@Nonnull String operationName, @Nonnull String rollbackProposal);
/**
* Shows notification about unmerged files preventing checkout, merge, etc.
*
* @param operationName
* @param repositories
*/
void showUnmergedFilesNotification(@Nonnull LocalizeValue operationName, @Nonnull Collection<GitRepository> repositories);

/**
* Show notification about "untracked files would be overwritten by merge/checkout".
*/
void showUntrackedFilesNotification(@Nonnull String operationName, @Nonnull VirtualFile root, @Nonnull Collection<String> relativePaths);
/**
* Shows a modal notification about unmerged files preventing an operation, with "Rollback" button.
* Pressing "Rollback" would should the operation which has already successfully executed on other repositories.
*
* @param operationName
* @param rollbackProposal
* @return true if user has agreed to rollback, false if user denied the rollback proposal.
*/
boolean showUnmergedFilesMessageWithRollback(@Nonnull LocalizeValue operationName, @Nonnull LocalizeValue rollbackProposal);

boolean showUntrackedFilesDialogWithRollback(@Nonnull String operationName, @Nonnull String rollbackProposal, @Nonnull VirtualFile root, @Nonnull Collection<String> relativePaths);
/**
* Show notification about "untracked files would be overwritten by merge/checkout".
*/
void showUntrackedFilesNotification(
@Nonnull LocalizeValue operationName,
@Nonnull VirtualFile root,
@Nonnull Collection<String> relativePaths
);

/**
* Shows the dialog proposing to execute the operation (checkout or merge) smartly, i.e. stash-execute-unstash.
*
* @param project
* @param changes local changes that would be overwritten by checkout or merge.
* @param paths paths reported by Git (in most cases this is covered by {@code changes}.
* @param operation operation name: checkout or merge
* @param forceButtonTitle if the operation can be executed force (force checkout is possible),
* specify the title of the force button; otherwise (force merge is not possible) pass null.
* @return the code of the decision.
*/
@MagicConstant(valuesFromClass = GitSmartOperationDialog.class)
int showSmartOperationDialog(@Nonnull Project project, @Nonnull List<Change> changes, @Nonnull Collection<String> paths, @Nonnull String operation, @Nullable String forceButtonTitle);
boolean showUntrackedFilesDialogWithRollback(
@Nonnull LocalizeValue operationName,
@Nonnull LocalizeValue rollbackProposal,
@Nonnull VirtualFile root,
@Nonnull Collection<String> relativePaths
);

/**
* @return true if user decided to restore the branch.
*/
boolean showBranchIsNotFullyMergedDialog(@Nonnull Project project,
@Nonnull Map<GitRepository, List<GitCommit>> history,
@Nonnull Map<GitRepository, String> baseBranches,
@Nonnull String removedBranch);
/**
* Shows the dialog proposing to execute the operation (checkout or merge) smartly, i.e. stash-execute-unstash.
*
* @param project
* @param changes local changes that would be overwritten by checkout or merge.
* @param paths paths reported by Git (in most cases this is covered by {@code changes}.
* @param operation operation name: checkout or merge
* @param forceButtonTitle if the operation can be executed force (force checkout is possible),
* specify the title of the force button; otherwise (force merge is not possible) pass null.
* @return the code of the decision.
*/
@MagicConstant(valuesFromClass = GitSmartOperationDialog.class)
int showSmartOperationDialog(
@Nonnull Project project,
@Nonnull List<Change> changes,
@Nonnull Collection<String> paths,
@Nonnull String operation,
@Nullable String forceButtonTitle
);

/**
* @return true if user decided to restore the branch.
*/
boolean showBranchIsNotFullyMergedDialog(
@Nonnull Project project,
@Nonnull Map<GitRepository, List<GitCommit>> history,
@Nonnull Map<GitRepository, String> baseBranches,
@Nonnull String removedBranch
);
}
35 changes: 17 additions & 18 deletions plugin/src/main/java/git4idea/branch/GitBranchUiHandlerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import consulo.ui.annotation.RequiredUIAccess;
import consulo.ui.ex.awt.Messages;
import consulo.ui.ex.awt.UIUtil;
import consulo.util.lang.StringUtil;
import consulo.util.lang.xml.XmlStringUtil;
import consulo.versionControlSystem.VcsNotifier;
import consulo.versionControlSystem.change.Change;
Expand Down Expand Up @@ -66,21 +65,21 @@ public GitBranchUiHandlerImpl(@Nonnull Project project, @Nonnull Git git, @Nonnu

@Override
public boolean notifyErrorWithRollbackProposal(
@Nonnull String title,
@Nonnull String message,
@Nonnull String rollbackProposal
@Nonnull LocalizeValue title,
@Nonnull LocalizeValue message,
@Nonnull LocalizeValue rollbackProposal
) {
AtomicBoolean ok = new AtomicBoolean();
UIUtil.invokeAndWaitIfNeeded((Runnable) () -> {
StringBuilder description = new StringBuilder();
if (!StringUtil.isEmptyOrSpaces(message)) {
if (message != LocalizeValue.empty()) {
description.append(message).append("<br/>");
}
description.append(rollbackProposal);
ok.set(Messages.YES == DialogManager.showOkCancelDialog(
myProject,
XmlStringUtil.wrapInHtml(description),
title,
title.get(),
"Rollback",
"Don't rollback",
UIUtil.getErrorIcon()
Expand All @@ -90,26 +89,26 @@ public boolean notifyErrorWithRollbackProposal(
}

@Override
public void showUnmergedFilesNotification(@Nonnull String operationName, @Nonnull Collection<GitRepository> repositories) {
public void showUnmergedFilesNotification(@Nonnull LocalizeValue operationName, @Nonnull Collection<GitRepository> repositories) {
myNotificationService.newError(VcsNotifier.IMPORTANT_ERROR_NOTIFICATION)
.title(unmergedFilesErrorTitle(operationName))
.content(unmergedFilesErrorNotificationDescription(operationName))
.optionalHyperlinkListener((notification, event) -> {
.hyperlinkListener((notification, event) -> {
if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED && event.getDescription().equals("resolve")) {
GitConflictResolver.Params params = new GitConflictResolver.Params()
.setMergeDescription(String.format(
.setMergeDescription(LocalizeValue.localizeTODO(String.format(
"The following files have unresolved conflicts. You need to resolve them before %s.",
operationName
))
.setErrorNotificationTitle("Unresolved files remain.");
)))
.setErrorNotificationTitle(LocalizeValue.localizeTODO("Unresolved files remain."));
new GitConflictResolver(myProject, myGit, GitUtil.getRootsFromRepositories(repositories), params).merge();
}
})
.notify(myProject);
}

@Override
public boolean showUnmergedFilesMessageWithRollback(@Nonnull String operationName, @Nonnull String rollbackProposal) {
public boolean showUnmergedFilesMessageWithRollback(@Nonnull LocalizeValue operationName, @Nonnull LocalizeValue rollbackProposal) {
AtomicBoolean ok = new AtomicBoolean();
UIUtil.invokeAndWaitIfNeeded((Runnable) () -> {
String description = String.format(
Expand All @@ -133,18 +132,18 @@ public boolean showUnmergedFilesMessageWithRollback(@Nonnull String operationNam

@Override
public void showUntrackedFilesNotification(
@Nonnull String operationName,
@Nonnull LocalizeValue operationName,
@Nonnull VirtualFile root,
@Nonnull Collection<String> relativePaths
) {
GitUntrackedFilesHelper.notifyUntrackedFilesOverwrittenBy(myProject, root, relativePaths, operationName, null);
GitUntrackedFilesHelper.notifyUntrackedFilesOverwrittenBy(myProject, root, relativePaths, operationName, LocalizeValue.empty());
}

@Override
@RequiredUIAccess
public boolean showUntrackedFilesDialogWithRollback(
@Nonnull String operationName,
@Nonnull String rollbackProposal,
@Nonnull LocalizeValue operationName,
@Nonnull LocalizeValue rollbackProposal,
@Nonnull VirtualFile root,
@Nonnull Collection<String> relativePaths
) {
Expand Down Expand Up @@ -205,12 +204,12 @@ public boolean showBranchIsNotFullyMergedDialog(
}

@Nonnull
private static LocalizeValue unmergedFilesErrorTitle(@Nonnull String operationName) {
private static LocalizeValue unmergedFilesErrorTitle(@Nonnull LocalizeValue operationName) {
return LocalizeValue.localizeTODO("Can't " + operationName + " because of unmerged files");
}

@Nonnull
private static LocalizeValue unmergedFilesErrorNotificationDescription(String operationName) {
private static LocalizeValue unmergedFilesErrorNotificationDescription(@Nonnull LocalizeValue operationName) {
return LocalizeValue.localizeTODO(
"You have to <a href='resolve'>resolve</a> all merge conflicts before " + operationName + ".<br/>" +
"After resolving conflicts you also probably would want to commit your files to the current branch."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,18 @@ public LocalizeValue getSuccessMessage() {

@Nonnull
@Override
protected String getRollbackProposal() {
return "However checkout has succeeded for the following " + repositories() + ":<br/>" +
protected LocalizeValue getRollbackProposal() {
return LocalizeValue.localizeTODO(
"However checkout has succeeded for the following " + repositories() + ":<br/>" +
successfulRepositoriesJoined() +
"<br/>You may rollback (checkout previous branch back, and delete " + myNewBranchName + ") not to let branches diverge.";
"<br/>You may rollback (checkout previous branch back, and delete " + myNewBranchName + ") not to let branches diverge."
);
}

@Nonnull
@Override
protected String getOperationName() {
return "checkout";
protected LocalizeValue getOperationName() {
return LocalizeValue.localizeTODO("checkout");
}

@Override
Expand Down
16 changes: 9 additions & 7 deletions plugin/src/main/java/git4idea/branch/GitCheckoutOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class GitCheckoutOperation extends GitBranchOperation {
protected void execute() {
saveAllDocuments();
boolean fatalErrorHappened = false;
try (AccessToken token = DvcsUtil.workingTreeChangeStarted(myProject, getOperationName())) {
try (AccessToken token = DvcsUtil.workingTreeChangeStarted(myProject, getOperationName().get())) {
while (hasMoreRepositories() && !fatalErrorHappened) {
GitRepository repository = next();

Expand Down Expand Up @@ -150,7 +150,7 @@ else if (!myRefShouldBeValid && unknownPathspec.hasHappened()) {

myNotificationService.newInfo(VcsNotifier.NOTIFICATION_GROUP_ID)
.content(LocalizeValue.localizeTODO(mentionSuccess + mentionSkipped + "<br><a href='rollback'>Rollback</a>"))
.optionalHyperlinkListener(new RollbackOperationNotificationListener())
.hyperlinkListener(new RollbackOperationNotificationListener())
.notify(myProject);
updateRecentBranch();
}
Expand Down Expand Up @@ -211,15 +211,17 @@ else if (smartCheckoutDecision == GitSmartOperationDialog.FORCE_EXIT_CODE) {

@Nonnull
@Override
protected String getRollbackProposal() {
return "However checkout has succeeded for the following " + repositories() + ":<br/>" +
successfulRepositoriesJoined() + "<br/>" + ROLLBACK_PROPOSAL_FORMAT;
protected LocalizeValue getRollbackProposal() {
return LocalizeValue.localizeTODO(
"However checkout has succeeded for the following " + repositories() + ":<br/>" +
successfulRepositoriesJoined() + "<br/>" + ROLLBACK_PROPOSAL_FORMAT
);
}

@Nonnull
@Override
protected String getOperationName() {
return "checkout";
protected LocalizeValue getOperationName() {
return LocalizeValue.localizeTODO("checkout");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,16 +254,18 @@ public LocalizeValue getSuccessMessage() {

@Nonnull
@Override
protected String getRollbackProposal() {
return "However branch deletion has succeeded for the following " + repositories() + ":<br/>" +
protected LocalizeValue getRollbackProposal() {
return LocalizeValue.localizeTODO(
"However branch deletion has succeeded for the following " + repositories() + ":<br/>" +
successfulRepositoriesJoined() +
"<br/>You may rollback (recreate " + myBranchName + " in these roots) not to let branches diverge.";
"<br/>You may rollback (recreate " + myBranchName + " in these roots) not to let branches diverge."
);
}

@Nonnull
@Override
protected String getOperationName() {
return "branch deletion";
protected LocalizeValue getOperationName() {
return LocalizeValue.localizeTODO("branch deletion");
}

@Nonnull
Expand Down
Loading
Loading