summaryrefslogtreecommitdiff
path: root/plugins/git4idea/src
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/git4idea/src')
-rw-r--r--plugins/git4idea/src/git4idea/GitContentRevision.java5
-rw-r--r--plugins/git4idea/src/git4idea/GitRevisionNumber.java3
-rw-r--r--plugins/git4idea/src/git4idea/GitUtil.java12
-rw-r--r--plugins/git4idea/src/git4idea/actions/GitCompareWithBranchAction.java3
-rw-r--r--plugins/git4idea/src/git4idea/annotate/GitAnnotationProvider.java46
-rw-r--r--plugins/git4idea/src/git4idea/annotate/GitFileAnnotation.java143
-rw-r--r--plugins/git4idea/src/git4idea/history/GitDiffFromHistoryHandler.java5
-rw-r--r--plugins/git4idea/src/git4idea/i18n/GitBundle.properties14
-rw-r--r--plugins/git4idea/src/git4idea/push/GitPushDialog.java3
-rw-r--r--plugins/git4idea/src/git4idea/push/GitPushLog.java5
-rw-r--r--plugins/git4idea/src/git4idea/rebase/GitRebaser.java23
-rw-r--r--plugins/git4idea/src/git4idea/repo/GitRepositoryImpl.java8
-rw-r--r--plugins/git4idea/src/git4idea/reset/GitNewResetDialog.java6
-rw-r--r--plugins/git4idea/src/git4idea/ui/GitCommitListPanel.java4
-rw-r--r--plugins/git4idea/src/git4idea/ui/GitUnstashDialog.java7
-rw-r--r--plugins/git4idea/src/git4idea/ui/branch/GitBranchPopup.java45
-rw-r--r--plugins/git4idea/src/git4idea/ui/branch/GitBranchPopupActions.java6
-rw-r--r--plugins/git4idea/src/git4idea/update/GitRebaseUpdater.java32
-rw-r--r--plugins/git4idea/src/git4idea/update/GitUpdateLocallyModifiedDialog.form71
-rw-r--r--plugins/git4idea/src/git4idea/update/GitUpdateLocallyModifiedDialog.java211
-rw-r--r--plugins/git4idea/src/git4idea/util/LocalChangesWouldBeOverwrittenHelper.java45
21 files changed, 139 insertions, 558 deletions
diff --git a/plugins/git4idea/src/git4idea/GitContentRevision.java b/plugins/git4idea/src/git4idea/GitContentRevision.java
index 68fcb59febf2..8dd85b167980 100644
--- a/plugins/git4idea/src/git4idea/GitContentRevision.java
+++ b/plugins/git4idea/src/git4idea/GitContentRevision.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2009 JetBrains s.r.o.
+ * Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,6 +27,7 @@ import com.intellij.openapi.vcs.history.VcsRevisionNumber;
import com.intellij.openapi.vcs.impl.ContentRevisionCache;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.vcsUtil.VcsFilePathUtil;
import com.intellij.vcsUtil.VcsFileUtil;
import com.intellij.vcsUtil.VcsUtil;
import git4idea.util.GitFileUtils;
@@ -168,7 +169,7 @@ public class GitContentRevision implements ContentRevision {
boolean isDeleted, boolean canBeDeleted, boolean unescapePath) throws VcsException {
final String absolutePath = makeAbsolutePath(vcsRoot, path, unescapePath);
FilePath file = isDeleted ? VcsUtil.getFilePathForDeletedFile(absolutePath, false) : VcsUtil.getFilePath(absolutePath, false);
- if (canBeDeleted && (! SystemInfo.isFileSystemCaseSensitive) && VcsUtil.caseDiffers(file.getPath(), absolutePath)) {
+ if (canBeDeleted && (! SystemInfo.isFileSystemCaseSensitive) && VcsFilePathUtil.caseDiffers(file.getPath(), absolutePath)) {
// as for deleted file
file = FilePathImpl.createForDeletedFile(new File(absolutePath), false);
}
diff --git a/plugins/git4idea/src/git4idea/GitRevisionNumber.java b/plugins/git4idea/src/git4idea/GitRevisionNumber.java
index cd6387a4e629..06fba24f015a 100644
--- a/plugins/git4idea/src/git4idea/GitRevisionNumber.java
+++ b/plugins/git4idea/src/git4idea/GitRevisionNumber.java
@@ -15,6 +15,7 @@
*/
package git4idea;
+import com.intellij.dvcs.DvcsUtil;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.text.StringUtil;
@@ -103,7 +104,7 @@ public class GitRevisionNumber implements ShortVcsRevisionNumber {
*/
@NotNull
public String getShortRev() {
- return GitUtil.getShortHash(myRevisionHash);
+ return DvcsUtil.getShortHash(myRevisionHash);
}
/**
diff --git a/plugins/git4idea/src/git4idea/GitUtil.java b/plugins/git4idea/src/git4idea/GitUtil.java
index 4ff61fb4a68b..e96d52de8ea0 100644
--- a/plugins/git4idea/src/git4idea/GitUtil.java
+++ b/plugins/git4idea/src/git4idea/GitUtil.java
@@ -102,7 +102,6 @@ public class GitUtil {
public static final String DOT_GIT = ".git";
private final static Logger LOG = Logger.getInstance(GitUtil.class);
- private static final int SHORT_HASH_LENGTH = 8;
public static final Predicate<GitBranchTrackInfo> NOT_NULL_PREDICATE = new Predicate<GitBranchTrackInfo>() {
@Override
@@ -829,17 +828,6 @@ public class GitUtil {
}
@NotNull
- public static String getShortHash(@NotNull String hash) {
- if (hash.length() == 0) return "";
- if (hash.length() == 40) return hash.substring(0, SHORT_HASH_LENGTH);
- if (hash.length() > 40) // revision string encoded with date too
- {
- return hash.substring(hash.indexOf("[") + 1, SHORT_HASH_LENGTH);
- }
- return hash;
- }
-
- @NotNull
public static String fileOrFolder(@NotNull VirtualFile file) {
if (file.isDirectory()) {
return "Folder";
diff --git a/plugins/git4idea/src/git4idea/actions/GitCompareWithBranchAction.java b/plugins/git4idea/src/git4idea/actions/GitCompareWithBranchAction.java
index f0ad3b7a5e31..8799c0e69651 100644
--- a/plugins/git4idea/src/git4idea/actions/GitCompareWithBranchAction.java
+++ b/plugins/git4idea/src/git4idea/actions/GitCompareWithBranchAction.java
@@ -15,6 +15,7 @@
*/
package git4idea.actions;
+import com.intellij.dvcs.DvcsUtil;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.Presentation;
@@ -70,7 +71,7 @@ public class GitCompareWithBranchAction extends DumbAwareAction {
String currentRevision = repository.getCurrentRevision();
LOG.assertTrue(currentRevision != null,
"Current revision is null for " + repository + ". Compare with branch shouldn't be available for fresh repository");
- head = GitUtil.getShortHash(currentRevision);
+ head = DvcsUtil.getShortHash(currentRevision);
}
else {
head = currentBranch.getName();
diff --git a/plugins/git4idea/src/git4idea/annotate/GitAnnotationProvider.java b/plugins/git4idea/src/git4idea/annotate/GitAnnotationProvider.java
index 46875b9d8c23..5ebdefd74b3a 100644
--- a/plugins/git4idea/src/git4idea/annotate/GitAnnotationProvider.java
+++ b/plugins/git4idea/src/git4idea/annotate/GitAnnotationProvider.java
@@ -46,45 +46,20 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-/**
- * Git annotation provider implementation.
- * <p/>
- * Based on the JetBrains SVNAnnotationProvider.
- */
public class GitAnnotationProvider implements AnnotationProvider, VcsCacheableAnnotationProvider {
- /**
- * the context project
- */
private final Project myProject;
- /**
- * The author key for annotations
- */
@NonNls private static final String AUTHOR_KEY = "author";
- /**
- * The committer time key for annotations
- */
@NonNls private static final String COMMITTER_TIME_KEY = "committer-time";
private static final Logger LOG = Logger.getInstance(GitAnnotationProvider.class);
- /**
- * A constructor
- *
- * @param project a context project
- */
public GitAnnotationProvider(@NotNull Project project) {
myProject = project;
}
- /**
- * {@inheritDoc}
- */
public FileAnnotation annotate(@NotNull VirtualFile file) throws VcsException {
return annotate(file, null);
}
- /**
- * {@inheritDoc}
- */
public FileAnnotation annotate(@NotNull final VirtualFile file, final VcsFileRevision revision) throws VcsException {
if (file.isDirectory()) {
throw new VcsException("Cannot annotate a directory");
@@ -119,8 +94,8 @@ public class GitAnnotationProvider implements AnnotationProvider, VcsCacheableAn
}
};
if (ApplicationManager.getApplication().isDispatchThread()) {
- ProgressManager.getInstance()
- .runProcessWithProgressSynchronously(command, GitBundle.getString("annotate.action.name"), false, myProject);
+ ProgressManager.getInstance().runProcessWithProgressSynchronously(command, GitBundle.getString("annotate.action.name"), false,
+ myProject);
}
else {
command.run();
@@ -132,16 +107,6 @@ public class GitAnnotationProvider implements AnnotationProvider, VcsCacheableAn
return annotation[0];
}
- /**
- * Calculate annotations
- *
- * @param repositoryFilePath the file path in the repository
- * @param revision the revision to checkout
- * @param revisions the revision list from history
- * @param file a virtual file for the action
- * @return a file annotation object
- * @throws VcsException if there is a problem with running git
- */
private GitFileAnnotation annotate(final FilePath repositoryFilePath,
final VcsFileRevision revision,
final List<VcsFileRevision> revisions,
@@ -159,7 +124,7 @@ public class GitAnnotationProvider implements AnnotationProvider, VcsCacheableAn
h.endOptions();
h.addRelativePaths(repositoryFilePath);
String output = h.run();
- GitFileAnnotation annotation = new GitFileAnnotation(myProject, file, revision == null, revision == null ? null : revision.getRevisionNumber());
+ GitFileAnnotation annotation = new GitFileAnnotation(myProject, file, revision == null ? null : revision.getRevisionNumber());
class CommitInfo {
Date date;
String author;
@@ -229,7 +194,7 @@ public class GitAnnotationProvider implements AnnotationProvider, VcsCacheableAn
String annotatedContent,
boolean forCurrentRevision, VcsRevisionNumber revisionNumber) {
final GitFileAnnotation gitFileAnnotation =
- new GitFileAnnotation(myProject, vcsAnnotation.getFilePath().getVirtualFile(), forCurrentRevision, revisionNumber);
+ new GitFileAnnotation(myProject, vcsAnnotation.getFilePath().getVirtualFile(), revisionNumber);
gitFileAnnotation.addLogEntries(session.getRevisionList());
final VcsLineAnnotationData basicAnnotation = vcsAnnotation.getBasicAnnotation();
final int size = basicAnnotation.getNumLines();
@@ -252,9 +217,6 @@ public class GitAnnotationProvider implements AnnotationProvider, VcsCacheableAn
return gitFileAnnotation;
}
- /**
- * {@inheritDoc}
- */
public boolean isAnnotationValid(VcsFileRevision rev) {
return true;
}
diff --git a/plugins/git4idea/src/git4idea/annotate/GitFileAnnotation.java b/plugins/git4idea/src/git4idea/annotate/GitFileAnnotation.java
index 4dfe4da19de0..0c1df6a50a5b 100644
--- a/plugins/git4idea/src/git4idea/annotate/GitFileAnnotation.java
+++ b/plugins/git4idea/src/git4idea/annotate/GitFileAnnotation.java
@@ -15,7 +15,6 @@
*/
package git4idea.annotate;
-import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vcs.VcsException;
import com.intellij.openapi.vcs.VcsKey;
@@ -23,6 +22,7 @@ import com.intellij.openapi.vcs.annotate.*;
import com.intellij.openapi.vcs.history.VcsFileRevision;
import com.intellij.openapi.vcs.history.VcsRevisionNumber;
import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.util.ObjectUtils;
import com.intellij.util.text.DateFormatUtil;
import git4idea.GitRevisionNumber;
import git4idea.GitVcs;
@@ -32,45 +32,24 @@ import org.jetbrains.annotations.Nullable;
import java.util.*;
-/**
- * Git file annotation implementation
- * <p/>
- * Based on the JetBrains SVNAnnotationProvider.
- */
public class GitFileAnnotation extends FileAnnotation {
- private final static Logger LOG = Logger.getInstance("#git4idea.annotate.GitFileAnnotation");
-
- /**
- * annotated content
- */
- private final StringBuffer myContentBuffer = new StringBuffer();
- /**
- * The currently annotated lines
- */
- private final ArrayList<LineInfo> myLines = new ArrayList<LineInfo>();
- /**
- * The project reference
- */
+ private final StringBuffer myContentBuffer = new StringBuffer(); // annotated content
+ private final ArrayList<LineInfo> myLines = new ArrayList<LineInfo>(); // The currently annotated lines
private final Project myProject;
private final VcsRevisionNumber myBaseRevision;
- /**
- * Map from revision numbers to revisions
- */
- private final Map<VcsRevisionNumber, VcsFileRevision> myRevisionMap = new HashMap<VcsRevisionNumber, VcsFileRevision>();
+ @NotNull private final Map<VcsRevisionNumber, VcsFileRevision> myRevisionMap = new HashMap<VcsRevisionNumber, VcsFileRevision>();
+ @NotNull private final VirtualFile myFile;
+ @NotNull private final GitVcs myVcs;
- /**
- * the virtual file for which annotations are generated
- */
- private final VirtualFile myFile;
-
- private final LineAnnotationAspect DATE_ASPECT = new GitAnnotationAspect(GitAnnotationAspect.DATE, true) {
+ private final LineAnnotationAspect DATE_ASPECT = new GitAnnotationAspect(LineAnnotationAspect.DATE, true) {
+ @Override
public String doGetValue(LineInfo info) {
final Date date = info.getDate();
return date == null ? "" : DateFormatUtil.formatPrettyDate(date);
}
};
- private final LineAnnotationAspect REVISION_ASPECT = new GitAnnotationAspect(GitAnnotationAspect.REVISION, false) {
+ private final LineAnnotationAspect REVISION_ASPECT = new GitAnnotationAspect(LineAnnotationAspect.REVISION, false) {
@Override
protected String doGetValue(LineInfo lineInfo) {
final GitRevisionNumber revision = lineInfo.getRevision();
@@ -78,101 +57,78 @@ public class GitFileAnnotation extends FileAnnotation {
}
};
- private final LineAnnotationAspect AUTHOR_ASPECT = new GitAnnotationAspect(GitAnnotationAspect.AUTHOR, true) {
+ private final LineAnnotationAspect AUTHOR_ASPECT = new GitAnnotationAspect(LineAnnotationAspect.AUTHOR, true) {
@Override
protected String doGetValue(LineInfo lineInfo) {
final String author = lineInfo.getAuthor();
return author == null ? "" : author;
}
};
- private final GitVcs myVcs;
- /**
- * A constructor
- *
- * @param project the project of annotation provider
- * @param file the git root
- * @param monitorFlag if false the file system will not be listened for changes (used for annotated files from the repository).
- * @param revision
- */
- public GitFileAnnotation(@NotNull final Project project, @NotNull VirtualFile file, final boolean monitorFlag, final VcsRevisionNumber revision) {
+ public GitFileAnnotation(@NotNull final Project project,
+ @NotNull VirtualFile file,
+ final VcsRevisionNumber revision) {
super(project);
myProject = project;
- myVcs = GitVcs.getInstance(myProject);
+ myVcs = ObjectUtils.assertNotNull(GitVcs.getInstance(myProject));
myFile = file;
myBaseRevision = revision == null ? (myVcs.getDiffProvider().getCurrentRevision(file)) : revision;
}
- /**
- * Add revisions to the list (from log)
- *
- * @param revisions revisions to add
- */
public void addLogEntries(List<VcsFileRevision> revisions) {
for (VcsFileRevision vcsFileRevision : revisions) {
myRevisionMap.put(vcsFileRevision.getRevisionNumber(), vcsFileRevision);
}
}
- /**
- * {@inheritDoc}
- */
+ @Override
public void dispose() {
}
- /**
- * {@inheritDoc}
- */
+ @Override
public LineAnnotationAspect[] getAspects() {
return new LineAnnotationAspect[]{REVISION_ASPECT, DATE_ASPECT, AUTHOR_ASPECT};
}
- /**
- * {@inheritDoc}
- */
+ @Override
public String getToolTip(final int lineNumber) {
if (myLines.size() <= lineNumber || lineNumber < 0) {
return "";
}
final LineInfo info = myLines.get(lineNumber);
- if (info == null) {
- return "";
- }
VcsFileRevision fileRevision = myRevisionMap.get(info.getRevision());
if (fileRevision != null) {
- return GitBundle
- .message("annotation.tool.tip", info.getRevision().asString(), info.getAuthor(), info.getDate(),
- fileRevision.getCommitMessage());
+ return GitBundle.message("annotation.tool.tip", info.getRevision().asString(), info.getAuthor(), info.getDate(),
+ fileRevision.getCommitMessage());
}
else {
return "";
}
}
- /**
- * {@inheritDoc}
- */
+ @Override
public String getAnnotatedContent() {
return myContentBuffer.toString();
}
- /**
- * {@inheritDoc}
- */
+ @Override
public List<VcsFileRevision> getRevisions() {
final List<VcsFileRevision> result = new ArrayList<VcsFileRevision>(myRevisionMap.values());
Collections.sort(result, new Comparator<VcsFileRevision>() {
- public int compare(final VcsFileRevision o1, final VcsFileRevision o2) {
+ @Override
+ public int compare(@NotNull VcsFileRevision o1, @NotNull VcsFileRevision o2) {
return -1 * o1.getRevisionNumber().compareTo(o2.getRevisionNumber());
}
});
return result;
}
+ @Override
public boolean revisionsNotEmpty() {
return ! myRevisionMap.isEmpty();
}
+ @Override
public AnnotationSourceSwitcher getAnnotationSourceSwitcher() {
return null;
}
@@ -182,19 +138,16 @@ public class GitFileAnnotation extends FileAnnotation {
return myLines.size();
}
- /**
- * {@inheritDoc}
- */
+ @Override
public VcsRevisionNumber getLineRevisionNumber(final int lineNumber) {
if (lineNumberCheck(lineNumber)) {
return null;
}
- final LineInfo lineInfo = myLines.get(lineNumber);
- return lineInfo == null ? null : lineInfo.getRevision();
+ return myLines.get(lineNumber).getRevision();
}
private boolean lineNumberCheck(int lineNumber) {
- return myLines.size() <= lineNumber || lineNumber < 0 || myLines.get(lineNumber) == null;
+ return myLines.size() <= lineNumber || lineNumber < 0;
}
@Override
@@ -202,13 +155,13 @@ public class GitFileAnnotation extends FileAnnotation {
if (lineNumberCheck(lineNumber)) {
return null;
}
- final LineInfo lineInfo = myLines.get(lineNumber);
- return lineInfo == null ? null : lineInfo.getDate();
+ return myLines.get(lineNumber).getDate();
}
/**
* Get revision number for the line.
*/
+ @Override
public VcsRevisionNumber originalRevision(int lineNumber) {
return getLineRevisionNumber(lineNumber);
}
@@ -248,6 +201,7 @@ public class GitFileAnnotation extends FileAnnotation {
super(id, showByDefault);
}
+ @Override
public String getValue(int lineNumber) {
if (lineNumberCheck(lineNumber)) {
return "";
@@ -262,10 +216,8 @@ public class GitFileAnnotation extends FileAnnotation {
@Override
protected void showAffectedPaths(int lineNum) {
if (lineNum >= 0 && lineNum < myLines.size()) {
- final LineInfo info = myLines.get(lineNum);
- if (info != null) {
- ShowAllAffectedGenericAction.showSubmittedFiles(myProject, info.getRevision(), myFile, GitVcs.getKey());
- }
+ LineInfo info = myLines.get(lineNum);
+ ShowAllAffectedGenericAction.showSubmittedFiles(myProject, info.getRevision(), myFile, GitVcs.getKey());
}
}
}
@@ -274,54 +226,31 @@ public class GitFileAnnotation extends FileAnnotation {
* Line information
*/
static class LineInfo {
- /**
- * date of the change
- */
private final Date myDate;
- /**
- * revision number
- */
private final GitRevisionNumber myRevision;
- /**
- * the author of the change
- */
private final String myAuthor;
- /**
- * A constructor
- *
- * @param date date of the change
- * @param revision revision number
- * @param author the author of the change
- */
- public LineInfo(final Date date, final GitRevisionNumber revision, final String author) {
+ public LineInfo(Date date, GitRevisionNumber revision, String author) {
myDate = date;
myRevision = revision;
myAuthor = author;
}
- /**
- * @return the revision date
- */
public Date getDate() {
return myDate;
}
- /**
- * @return the revision number
- */
public GitRevisionNumber getRevision() {
return myRevision;
}
- /**
- * @return the author of the change
- */
public String getAuthor() {
return myAuthor;
}
}
+ @NotNull
+ @Override
public VirtualFile getFile() {
return myFile;
}
diff --git a/plugins/git4idea/src/git4idea/history/GitDiffFromHistoryHandler.java b/plugins/git4idea/src/git4idea/history/GitDiffFromHistoryHandler.java
index a6488d4ce3d0..d0f051c50475 100644
--- a/plugins/git4idea/src/git4idea/history/GitDiffFromHistoryHandler.java
+++ b/plugins/git4idea/src/git4idea/history/GitDiffFromHistoryHandler.java
@@ -15,6 +15,7 @@
*/
package git4idea.history;
+import com.intellij.dvcs.DvcsUtil;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.actionSystem.impl.SimpleDataContext;
import com.intellij.openapi.components.ServiceManager;
@@ -116,7 +117,7 @@ public class GitDiffFromHistoryHandler extends BaseDiffFromHistoryHandler<GitFil
@NotNull
@Override
protected String getPresentableName(@NotNull GitFileRevision revision) {
- return GitUtil.getShortHash(revision.getHash());
+ return DvcsUtil.getShortHash(revision.getHash());
}
@NotNull
@@ -301,7 +302,7 @@ public class GitDiffFromHistoryHandler extends BaseDiffFromHistoryHandler<GitFil
@NotNull private final GitFileRevision myParentRevision;
public ShowDiffWithParentAction(@NotNull FilePath filePath, @NotNull GitFileRevision rev, @NotNull GitFileRevision parent) {
- super(GitUtil.getShortHash(parent.getHash()));
+ super(DvcsUtil.getShortHash(parent.getHash()));
myFilePath = filePath;
myRevision = rev;
myParentRevision = parent;
diff --git a/plugins/git4idea/src/git4idea/i18n/GitBundle.properties b/plugins/git4idea/src/git4idea/i18n/GitBundle.properties
index 03803fbf985c..f89657535f8a 100644
--- a/plugins/git4idea/src/git4idea/i18n/GitBundle.properties
+++ b/plugins/git4idea/src/git4idea/i18n/GitBundle.properties
@@ -416,20 +416,6 @@ unstash.unstashing=Unstashing...
unstash.view.tooltip=View selected stash
unstash.view=&View
unstashing.title=UnStashing changes...
-update.locally.modified.files.tooltip=Locally modified files.
-update.locally.modified.files=&Files:
-update.locally.modified.git.root=Git Root:
-update.locally.modified.message=<html><p>The following files under this root are locally modified. <br/>\
- Possible reasons: uncommitted changes; a problem with crlf conversion; {0} configuration file auto-save.</p>\
- <p><ul>\
- <li>Press <b>Revert Files</b> to discard these local changes and continue the update process.</li>\
- <li>Press <b>Cancel</b> to cancel the update process. <br/> Use Auto-Stash option to stash local changes before update and restore them after it.</li>\
- </ul></p> \
- </html>
-update.locally.modified.rescan.tooltip=<html>Rescan the repository to check for locally modified files again.<br/>Use this button if you have resolved the problem manually.</html>
-update.locally.modified.rescan=Re&scan
-update.locally.modified.revert=Revert Files
-update.locally.modified.title=Locally modified files are detected
update.options.display.name=Git Update Settings
update.options.no.commit=No &Commit
update.options.save.before.update=Clean working tree before update
diff --git a/plugins/git4idea/src/git4idea/push/GitPushDialog.java b/plugins/git4idea/src/git4idea/push/GitPushDialog.java
index 56476078f692..f12b7b407c89 100644
--- a/plugins/git4idea/src/git4idea/push/GitPushDialog.java
+++ b/plugins/git4idea/src/git4idea/push/GitPushDialog.java
@@ -15,6 +15,7 @@
*/
package git4idea.push;
+import com.intellij.dvcs.DvcsUtil;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.diagnostic.Logger;
@@ -219,7 +220,7 @@ public class GitPushDialog extends DialogWrapper {
private static String logMessageForCommits(GitCommitsByRepoAndBranch commitsToPush) {
StringBuilder logMessage = new StringBuilder();
for (GitCommit commit : commitsToPush.getAllCommits()) {
- logMessage.append(GitUtil.getShortHash(commit.getId().toString()));
+ logMessage.append(DvcsUtil.getShortHash(commit.getId().toString()));
}
return logMessage.toString();
}
diff --git a/plugins/git4idea/src/git4idea/push/GitPushLog.java b/plugins/git4idea/src/git4idea/push/GitPushLog.java
index 99d3c1350698..e3659554bdf2 100644
--- a/plugins/git4idea/src/git4idea/push/GitPushLog.java
+++ b/plugins/git4idea/src/git4idea/push/GitPushLog.java
@@ -29,7 +29,6 @@ import com.intellij.openapi.vcs.changes.ui.ChangesBrowser;
import com.intellij.ui.*;
import com.intellij.util.ArrayUtil;
import com.intellij.util.Consumer;
-import com.intellij.util.text.DateFormatUtil;
import com.intellij.util.ui.UIUtil;
import com.intellij.util.ui.tree.TreeUtil;
import git4idea.GitBranch;
@@ -336,12 +335,12 @@ class GitPushLog extends JPanel implements TypeSafeDataProvider {
@NotNull
private static String getDateString(@NotNull GitCommit commit) {
- return DateFormatUtil.formatPrettyDateTime(commit.getTimestamp()) + " ";
+ return DvcsUtil.getDateString(commit);
}
@NotNull
private static String getHashString(@NotNull GitCommit commit) {
- return GitUtil.getShortHash(commit.getId().toString());
+ return DvcsUtil.getShortHash(commit.getId().toString());
}
private static class MyTreeCellRenderer extends CheckboxTree.CheckboxTreeCellRenderer {
diff --git a/plugins/git4idea/src/git4idea/rebase/GitRebaser.java b/plugins/git4idea/src/git4idea/rebase/GitRebaser.java
index aabf913fbf61..d5a0470d1667 100644
--- a/plugins/git4idea/src/git4idea/rebase/GitRebaser.java
+++ b/plugins/git4idea/src/git4idea/rebase/GitRebaser.java
@@ -30,6 +30,7 @@ import git4idea.commands.*;
import git4idea.merge.GitConflictResolver;
import git4idea.update.GitUpdateResult;
import git4idea.util.GitUIUtil;
+import git4idea.util.LocalChangesWouldBeOverwrittenHelper;
import git4idea.util.StringScanner;
import git4idea.util.UntrackedFilesNotifier;
import org.jetbrains.annotations.NotNull;
@@ -43,6 +44,8 @@ import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
+import static git4idea.commands.GitLocalChangesWouldBeOverwrittenDetector.Operation.CHECKOUT;
+
/**
* @author Kirill Likhodedov
*/
@@ -77,7 +80,9 @@ public class GitRebaser {
final GitRebaseProblemDetector rebaseConflictDetector = new GitRebaseProblemDetector();
rebaseHandler.addLineListener(rebaseConflictDetector);
GitUntrackedFilesOverwrittenByOperationDetector untrackedFilesDetector = new GitUntrackedFilesOverwrittenByOperationDetector(root);
+ GitLocalChangesWouldBeOverwrittenDetector localChangesDetector = new GitLocalChangesWouldBeOverwrittenDetector(root, CHECKOUT);
rebaseHandler.addLineListener(untrackedFilesDetector);
+ rebaseHandler.addLineListener(localChangesDetector);
String progressTitle = "Rebasing";
GitTask rebaseTask = new GitTask(myProject, rebaseHandler, progressTitle);
@@ -108,7 +113,7 @@ public class GitRebaser {
});
if (failure.get()) {
- updateResult.set(handleRebaseFailure(rebaseHandler, root, rebaseConflictDetector, untrackedFilesDetector));
+ updateResult.set(handleRebaseFailure(rebaseHandler, root, rebaseConflictDetector, untrackedFilesDetector, localChangesDetector));
}
}
finally {
@@ -333,19 +338,27 @@ public class GitRebaser {
}
@NotNull
- public GitUpdateResult handleRebaseFailure(@NotNull GitLineHandler handler, @NotNull VirtualFile root,
+ public GitUpdateResult handleRebaseFailure(@NotNull GitLineHandler handler,
+ @NotNull VirtualFile root,
@NotNull GitRebaseProblemDetector rebaseConflictDetector,
- @NotNull GitMessageWithFilesDetector untrackedWouldBeOverwrittenDetector) {
+ @NotNull GitMessageWithFilesDetector untrackedWouldBeOverwrittenDetector,
+ @NotNull GitLocalChangesWouldBeOverwrittenDetector localChangesDetector) {
if (rebaseConflictDetector.isMergeConflict()) {
LOG.info("handleRebaseFailure merge conflict");
final boolean allMerged = new GitRebaser.ConflictResolver(myProject, myGit, root, this).merge();
return allMerged ? GitUpdateResult.SUCCESS_WITH_RESOLVED_CONFLICTS : GitUpdateResult.INCOMPLETE;
- } else if (untrackedWouldBeOverwrittenDetector.wasMessageDetected()) {
+ }
+ else if (untrackedWouldBeOverwrittenDetector.wasMessageDetected()) {
LOG.info("handleRebaseFailure: untracked files would be overwritten by checkout");
UntrackedFilesNotifier.notifyUntrackedFilesOverwrittenBy(myProject, root,
untrackedWouldBeOverwrittenDetector.getRelativeFilePaths(), "rebase", null);
return GitUpdateResult.ERROR;
- } else {
+ }
+ else if (localChangesDetector.wasMessageDetected()) {
+ LocalChangesWouldBeOverwrittenHelper.showErrorNotification(myProject, root, "rebase", localChangesDetector.getRelativeFilePaths());
+ return GitUpdateResult.ERROR;
+ }
+ else {
LOG.info("handleRebaseFailure error " + handler.errors());
GitUIUtil.notifyImportantError(myProject, "Rebase error", GitUIUtil.stringifyErrors(handler.errors()));
return GitUpdateResult.ERROR;
diff --git a/plugins/git4idea/src/git4idea/repo/GitRepositoryImpl.java b/plugins/git4idea/src/git4idea/repo/GitRepositoryImpl.java
index e401334416d6..1444f44c0288 100644
--- a/plugins/git4idea/src/git4idea/repo/GitRepositoryImpl.java
+++ b/plugins/git4idea/src/git4idea/repo/GitRepositoryImpl.java
@@ -19,11 +19,13 @@ import com.intellij.dvcs.repo.RepositoryImpl;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
+import com.intellij.openapi.vcs.AbstractVcs;
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFile;
import git4idea.GitLocalBranch;
import git4idea.GitPlatformFacade;
import git4idea.GitUtil;
+import git4idea.GitVcs;
import git4idea.branch.GitBranchesCollection;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -135,6 +137,12 @@ public class GitRepositoryImpl extends RepositoryImpl implements GitRepository {
return myInfo.getState();
}
+ @Nullable
+ @Override
+ public AbstractVcs getVcs() {
+ return GitVcs.getInstance(getProject());
+ }
+
/**
* @return local and remote branches in this repository.
*/
diff --git a/plugins/git4idea/src/git4idea/reset/GitNewResetDialog.java b/plugins/git4idea/src/git4idea/reset/GitNewResetDialog.java
index 5e2cb18e7c7e..58363b917992 100644
--- a/plugins/git4idea/src/git4idea/reset/GitNewResetDialog.java
+++ b/plugins/git4idea/src/git4idea/reset/GitNewResetDialog.java
@@ -15,6 +15,7 @@
*/
package git4idea.reset;
+import com.intellij.dvcs.DvcsUtil;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
@@ -26,7 +27,6 @@ import com.intellij.util.ui.RadioButtonEnumModel;
import com.intellij.util.ui.UIUtil;
import com.intellij.vcs.log.VcsFullCommitDetails;
import com.intellij.xml.util.XmlStringUtil;
-import git4idea.GitUtil;
import git4idea.repo.GitRepository;
import git4idea.repo.GitRepositoryManager;
import org.jetbrains.annotations.NotNull;
@@ -117,7 +117,7 @@ public class GitNewResetDialog extends DialogWrapper {
@NotNull
private static String getTargetText(@NotNull VcsFullCommitDetails commit) {
- String commitMessage = StringUtil.shortenTextWithEllipsis(commit.getSubject(), 20, 0);
+ String commitMessage = StringUtil.escapeXml(StringUtil.shortenTextWithEllipsis(commit.getSubject(), 20, 0));
return String.format("<code><b>%s</b> \"%s\"</code> by <code>%s</code>",
commit.getId().toShortString(), commitMessage, commit.getAuthor().getName());
}
@@ -127,7 +127,7 @@ public class GitNewResetDialog extends DialogWrapper {
String currentRevision = repository.getCurrentRevision();
assert currentRevision != null;
String text = repository.getCurrentBranch() == null ?
- "HEAD (" + GitUtil.getShortHash(currentRevision) + ")" :
+ "HEAD (" + DvcsUtil.getShortHash(currentRevision) + ")" :
repository.getCurrentBranch().getName();
return "<b>" + text + "</b>";
}
diff --git a/plugins/git4idea/src/git4idea/ui/GitCommitListPanel.java b/plugins/git4idea/src/git4idea/ui/GitCommitListPanel.java
index dcd1c3182b47..94d01022c83e 100644
--- a/plugins/git4idea/src/git4idea/ui/GitCommitListPanel.java
+++ b/plugins/git4idea/src/git4idea/ui/GitCommitListPanel.java
@@ -15,6 +15,7 @@
*/
package git4idea.ui;
+import com.intellij.dvcs.DvcsUtil;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.vcs.VcsDataKeys;
import com.intellij.openapi.vcs.changes.Change;
@@ -28,7 +29,6 @@ import com.intellij.util.ui.ColumnInfo;
import com.intellij.util.ui.ListTableModel;
import com.intellij.util.ui.UIUtil;
import git4idea.GitCommit;
-import git4idea.GitUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -198,7 +198,7 @@ public class GitCommitListPanel extends JPanel implements TypeSafeDataProvider {
}
private static String getHash(GitCommit commit) {
- return GitUtil.getShortHash(commit.getId().toString());
+ return DvcsUtil.getShortHash(commit.getId().toString());
}
private static String getAuthor(GitCommit commit) {
diff --git a/plugins/git4idea/src/git4idea/ui/GitUnstashDialog.java b/plugins/git4idea/src/git4idea/ui/GitUnstashDialog.java
index eccaa446b0ed..44e4f1fab4b9 100644
--- a/plugins/git4idea/src/git4idea/ui/GitUnstashDialog.java
+++ b/plugins/git4idea/src/git4idea/ui/GitUnstashDialog.java
@@ -51,6 +51,7 @@ import git4idea.merge.GitConflictResolver;
import git4idea.repo.GitRepository;
import git4idea.stash.GitStashUtils;
import git4idea.util.GitUIUtil;
+import git4idea.util.LocalChangesWouldBeOverwrittenHelper;
import git4idea.util.UntrackedFilesNotifier;
import git4idea.validators.GitBranchNameValidator;
import org.jetbrains.annotations.NotNull;
@@ -68,6 +69,8 @@ import java.util.HashSet;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
+import static git4idea.commands.GitLocalChangesWouldBeOverwrittenDetector.Operation.MERGE;
+
/**
* The unstash dialog
*/
@@ -349,7 +352,9 @@ public class GitUnstashDialog extends DialogWrapper {
}
});
GitUntrackedFilesOverwrittenByOperationDetector untrackedFilesDetector = new GitUntrackedFilesOverwrittenByOperationDetector(root);
+ GitLocalChangesWouldBeOverwrittenDetector localChangesDetector = new GitLocalChangesWouldBeOverwrittenDetector(root, MERGE);
h.addLineListener(untrackedFilesDetector);
+ h.addLineListener(localChangesDetector);
GitUtil.workingTreeChangeStarted(myProject);
try {
@@ -371,6 +376,8 @@ public class GitUnstashDialog extends DialogWrapper {
} else if (untrackedFilesDetector.wasMessageDetected()) {
UntrackedFilesNotifier.notifyUntrackedFilesOverwrittenBy(myProject, root, untrackedFilesDetector.getRelativeFilePaths(),
"unstash", null);
+ } else if (localChangesDetector.wasMessageDetected()) {
+ LocalChangesWouldBeOverwrittenHelper.showErrorDialog(myProject, root, "unstash", localChangesDetector.getRelativeFilePaths());
} else if (!res.success()) {
GitUIUtil.showOperationErrors(myProject, h.errors(), h.printableCommandLine());
}
diff --git a/plugins/git4idea/src/git4idea/ui/branch/GitBranchPopup.java b/plugins/git4idea/src/git4idea/ui/branch/GitBranchPopup.java
index bd9c8fb3a1b3..1cb7cf6a66c9 100644
--- a/plugins/git4idea/src/git4idea/ui/branch/GitBranchPopup.java
+++ b/plugins/git4idea/src/git4idea/ui/branch/GitBranchPopup.java
@@ -45,14 +45,8 @@ import javax.swing.event.HyperlinkEvent;
import java.util.List;
/**
- * <p>
* The popup which allows to quickly switch and control Git branches.
- * </p>
- * <p>
- * Use {@link #asListPopup()} to achieve the {@link ListPopup} itself.
- * </p>
- *
- * @author Kirill Likhodedov
+ * <p/>
*/
class GitBranchPopup {
@@ -160,32 +154,28 @@ class GitBranchPopup {
}
private void notifyAboutSyncedBranches() {
- VcsNotifier.getInstance(myProject).notifyImportantInfo("Synchronous branch control enabled",
- "You have several Git roots in the project and they all are checked out at the same branch. " +
- "We've enabled synchronous branch control for the project. <br/>" +
- "If you wish to control branches in different roots separately, you may <a href='settings'>disable</a> the setting.",
- new NotificationListener() {
- @Override
- public void hyperlinkUpdate(@NotNull Notification notification,
- @NotNull HyperlinkEvent event) {
- if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
- ShowSettingsUtil.getInstance().showSettingsDialog(myProject, myVcs
- .getConfigurable().getDisplayName());
- if (myVcsSettings.getSyncSetting() == GitBranchSyncSetting.DONT) {
- notification.expire();
- }
- }
- }
- }
- );
+ String description = "You have several Git roots in the project and they all are checked out at the same branch. " +
+ "We've enabled synchronous branch control for the project. <br/>" +
+ "If you wish to control branches in different roots separately, " +
+ "you may <a href='settings'>disable</a> the setting.";
+ NotificationListener listener = new NotificationListener() {
+ @Override
+ public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) {
+ if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
+ ShowSettingsUtil.getInstance().showSettingsDialog(myProject, myVcs.getConfigurable().getDisplayName());
+ if (myVcsSettings.getSyncSetting() == GitBranchSyncSetting.DONT) {
+ notification.expire();
+ }
+ }
+ }
+ };
+ VcsNotifier.getInstance(myProject).notifyImportantInfo("Synchronous branch control enabled", description, listener);
}
private ActionGroup createActions() {
DefaultActionGroup popupGroup = new DefaultActionGroup(null, false);
-
GitRepositoryManager repositoryManager = myRepositoryManager;
if (repositoryManager.moreThanOneRoot()) {
-
if (userWantsSyncControl()) {
fillWithCommonRepositoryActions(popupGroup, repositoryManager);
}
@@ -196,7 +186,6 @@ class GitBranchPopup {
else {
fillPopupWithCurrentRepositoryActions(popupGroup, null);
}
-
popupGroup.addSeparator();
return popupGroup;
}
diff --git a/plugins/git4idea/src/git4idea/ui/branch/GitBranchPopupActions.java b/plugins/git4idea/src/git4idea/ui/branch/GitBranchPopupActions.java
index dbd3f8c902e5..b3cba24540de 100644
--- a/plugins/git4idea/src/git4idea/ui/branch/GitBranchPopupActions.java
+++ b/plugins/git4idea/src/git4idea/ui/branch/GitBranchPopupActions.java
@@ -36,10 +36,6 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
-/**
- *
- * @author Kirill Likhodedov
- */
class GitBranchPopupActions {
private final Project myProject;
@@ -123,7 +119,7 @@ class GitBranchPopupActions {
public void update(AnActionEvent e) {
if (myRepository.isFresh()) {
e.getPresentation().setEnabled(false);
- e.getPresentation().setDescription("Checkout is not possible before the first commit.");
+ e.getPresentation().setDescription("Checkout is not possible before the first commit");
}
}
}
diff --git a/plugins/git4idea/src/git4idea/update/GitRebaseUpdater.java b/plugins/git4idea/src/git4idea/update/GitRebaseUpdater.java
index 04ed3ac845ca..e22c15076170 100644
--- a/plugins/git4idea/src/git4idea/update/GitRebaseUpdater.java
+++ b/plugins/git4idea/src/git4idea/update/GitRebaseUpdater.java
@@ -18,12 +18,10 @@ package git4idea.update;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.project.Project;
-import com.intellij.openapi.util.Ref;
import com.intellij.openapi.vcs.VcsException;
import com.intellij.openapi.vcs.VcsNotifier;
import com.intellij.openapi.vcs.update.UpdatedFiles;
import com.intellij.openapi.vfs.VirtualFile;
-import com.intellij.util.ui.UIUtil;
import git4idea.GitBranch;
import git4idea.GitUtil;
import git4idea.branch.GitBranchPair;
@@ -78,42 +76,12 @@ public class GitRebaseUpdater extends GitUpdater {
return dest.getName();
}
- // TODO
- //if (!checkLocallyModified(myRoot)) {
- // cancel();
- // updateSucceeded.set(false);
- //}
-
-
- // TODO: show at any case of update successfullibility, also don't show here but for all roots
- //if (mySkippedCommits.size() > 0) {
- // GitSkippedCommits.showSkipped(myProject, mySkippedCommits);
- //}
-
public void cancel() {
myRebaser.abortRebase(myRoot);
myProgressIndicator.setText2("Refreshing files for the root " + myRoot.getPath());
myRoot.refresh(false, true);
}
- /**
- * Check and process locally modified files
- *
- * @param root the project root
- * @param ex the exception holder
- */
- protected boolean checkLocallyModified(final VirtualFile root) throws VcsException {
- final Ref<Boolean> cancelled = new Ref<Boolean>(false);
- UIUtil.invokeAndWaitIfNeeded(new Runnable() {
- public void run() {
- if (!GitUpdateLocallyModifiedDialog.showIfNeeded(myProject, root)) {
- cancelled.set(true);
- }
- }
- });
- return !cancelled.get();
- }
-
@Override
public String toString() {
return "Rebase updater";
diff --git a/plugins/git4idea/src/git4idea/update/GitUpdateLocallyModifiedDialog.form b/plugins/git4idea/src/git4idea/update/GitUpdateLocallyModifiedDialog.form
deleted file mode 100644
index a97507f24ec9..000000000000
--- a/plugins/git4idea/src/git4idea/update/GitUpdateLocallyModifiedDialog.form
+++ /dev/null
@@ -1,71 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="git4idea.update.GitUpdateLocallyModifiedDialog">
- <grid id="27dc6" binding="myRootPanel" layout-manager="GridLayoutManager" row-count="3" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
- <margin top="0" left="0" bottom="0" right="0"/>
- <constraints>
- <xy x="20" y="20" width="514" height="322"/>
- </constraints>
- <properties/>
- <border type="none"/>
- <children>
- <component id="62c84" class="javax.swing.JLabel">
- <constraints>
- <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
- </constraints>
- <properties>
- <text resource-bundle="git4idea/i18n/GitBundle" key="update.locally.modified.git.root"/>
- </properties>
- </component>
- <component id="24443" class="javax.swing.JLabel" binding="myGitRoot">
- <constraints>
- <grid row="0" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
- </constraints>
- <properties>
- <text value=""/>
- </properties>
- </component>
- <component id="e43af" class="javax.swing.JLabel" binding="myDescriptionLabel">
- <constraints>
- <grid row="1" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
- </constraints>
- <properties>
- <text value=""/>
- </properties>
- </component>
- <scrollpane class="com.intellij.ui.components.JBScrollPane" id="bde6e">
- <constraints>
- <grid row="2" column="1" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
- </constraints>
- <properties/>
- <border type="none"/>
- <children>
- <component id="5d604" class="com.intellij.ui.components.JBList" binding="myFilesList" default-binding="true">
- <constraints/>
- <properties>
- <toolTipText resource-bundle="git4idea/i18n/GitBundle" key="update.locally.modified.files.tooltip"/>
- </properties>
- </component>
- </children>
- </scrollpane>
- <component id="8f763" class="javax.swing.JButton" binding="myRescanButton" default-binding="true">
- <constraints>
- <grid row="2" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="1" fill="1" indent="0" use-parent-layout="false"/>
- </constraints>
- <properties>
- <text resource-bundle="git4idea/i18n/GitBundle" key="update.locally.modified.rescan"/>
- <toolTipText resource-bundle="git4idea/i18n/GitBundle" key="update.locally.modified.rescan.tooltip"/>
- </properties>
- </component>
- <component id="ab434" class="javax.swing.JLabel">
- <constraints>
- <grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="9" fill="0" indent="0" use-parent-layout="false"/>
- </constraints>
- <properties>
- <labelFor value="bde6e"/>
- <text resource-bundle="git4idea/i18n/GitBundle" key="update.locally.modified.files"/>
- <verticalAlignment value="0"/>
- </properties>
- </component>
- </children>
- </grid>
-</form>
diff --git a/plugins/git4idea/src/git4idea/update/GitUpdateLocallyModifiedDialog.java b/plugins/git4idea/src/git4idea/update/GitUpdateLocallyModifiedDialog.java
deleted file mode 100644
index c3384cea20b0..000000000000
--- a/plugins/git4idea/src/git4idea/update/GitUpdateLocallyModifiedDialog.java
+++ /dev/null
@@ -1,211 +0,0 @@
-/*
- * Copyright 2000-2009 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package git4idea.update;
-
-import com.intellij.openapi.application.ApplicationNamesInfo;
-import com.intellij.openapi.project.Project;
-import com.intellij.openapi.ui.DialogWrapper;
-import com.intellij.openapi.vcs.FilePath;
-import com.intellij.openapi.vcs.VcsException;
-import com.intellij.openapi.vfs.VirtualFile;
-import com.intellij.util.ui.UIUtil;
-import com.intellij.vcsUtil.VcsUtil;
-import git4idea.GitUtil;
-import git4idea.commands.GitCommand;
-import git4idea.commands.GitSimpleHandler;
-import git4idea.util.StringScanner;
-import git4idea.i18n.GitBundle;
-import git4idea.rollback.GitRollbackEnvironment;
-import git4idea.util.GitUIUtil;
-
-import javax.swing.*;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-/**
- * The dialog that displays locally modified files during update process
- */
-public class GitUpdateLocallyModifiedDialog extends DialogWrapper {
- /**
- * The rescan button
- */
- private JButton myRescanButton;
- /**
- * The list of files to revert
- */
- private JList myFilesList;
-
- private JLabel myDescriptionLabel;
- /**
- * The git root label
- */
- private JLabel myGitRoot;
- /**
- * The root panel
- */
- private JPanel myRootPanel;
- /**
- * The collection with locally modified files
- */
- private final List<String> myLocallyModifiedFiles;
-
- /**
- * The constructor
- *
- * @param project the current project
- * @param root the vcs root
- * @param locallyModifiedFiles the collection of locally modified files to use
- */
- protected GitUpdateLocallyModifiedDialog(final Project project, final VirtualFile root, List<String> locallyModifiedFiles) {
- super(project, true);
- myLocallyModifiedFiles = locallyModifiedFiles;
- setTitle(GitBundle.getString("update.locally.modified.title"));
- myGitRoot.setText(root.getPresentableUrl());
- myFilesList.setModel(new DefaultListModel());
- setOKButtonText(GitBundle.getString("update.locally.modified.revert"));
- syncListModel();
- myRescanButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- myLocallyModifiedFiles.clear();
- try {
- scanFiles(project, root, myLocallyModifiedFiles);
- }
- catch (VcsException ex) {
- GitUIUtil.showOperationError(project, ex, "Checking for locally modified files");
- }
- }
- });
- myDescriptionLabel
- .setText(GitBundle.message("update.locally.modified.message", ApplicationNamesInfo.getInstance().getFullProductName()));
- init();
- }
-
- /**
- * Refresh list model according to the current content of the collection
- */
- private void syncListModel() {
- DefaultListModel listModel = (DefaultListModel)myFilesList.getModel();
- listModel.removeAllElements();
- for (String p : myLocallyModifiedFiles) {
- listModel.addElement(p);
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected JComponent createCenterPanel() {
- return myRootPanel;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected String getDimensionServiceKey() {
- return getClass().getName();
- }
-
- /**
- * Scan working tree and detect locally modified files
- *
- * @param project the project to scan
- * @param root the root to scan
- * @param files the collection with files
- * @throws VcsException if there problem with running git or working tree is dirty in unsupported way
- */
- private static void scanFiles(Project project, VirtualFile root, List<String> files) throws VcsException {
- String rootPath = root.getPath();
- GitSimpleHandler h = new GitSimpleHandler(project, root, GitCommand.DIFF);
- h.addParameters("--name-status");
- h.setSilent(true);
- h.setStdoutSuppressed(true);
- StringScanner s = new StringScanner(h.run());
- while (s.hasMoreData()) {
- if (s.isEol()) {
- s.line();
- continue;
- }
- if (s.tryConsume("M\t")) {
- String path = rootPath + "/" + GitUtil.unescapePath(s.line());
- files.add(path);
- }
- else {
- throw new VcsException("Working tree is dirty in unsupported way: " + s.line());
- }
- }
- }
-
-
- /**
- * Show the dialog if needed
- *
- * @param project the project
- * @param root the vcs root
- * @return true if showing is not needed or operation completed successfully
- */
- public static boolean showIfNeeded(final Project project, final VirtualFile root) {
- final ArrayList<String> files = new ArrayList<String>();
- try {
- scanFiles(project, root, files);
- final AtomicBoolean rc = new AtomicBoolean(true);
- if (!files.isEmpty()) {
- UIUtil.invokeAndWaitIfNeeded(new Runnable() {
- public void run() {
- GitUpdateLocallyModifiedDialog d = new GitUpdateLocallyModifiedDialog(project, root, files);
- d.show();
- rc.set(d.isOK());
- }
- });
- if (rc.get()) {
- if (!files.isEmpty()) {
- revertFiles(project, root, files);
- }
- }
- }
- return rc.get();
- }
- catch (final VcsException e) {
- UIUtil.invokeAndWaitIfNeeded(new Runnable() {
- public void run() {
- GitUIUtil.showOperationError(project, e, "Checking for locally modified files");
- }
- });
- return false;
- }
- }
-
- /**
- * Revert files from the list
- *
- * @param project the project
- * @param root the vcs root
- * @param files the files to revert
- */
- private static void revertFiles(Project project, VirtualFile root, ArrayList<String> files) throws VcsException {
- // TODO consider deleted files
- GitRollbackEnvironment rollback = GitRollbackEnvironment.getInstance(project);
- ArrayList<FilePath> list = new ArrayList<FilePath>(files.size());
- for (String p : files) {
- list.add(VcsUtil.getFilePath(p));
- }
- rollback.revert(root, list);
- }
-}
diff --git a/plugins/git4idea/src/git4idea/util/LocalChangesWouldBeOverwrittenHelper.java b/plugins/git4idea/src/git4idea/util/LocalChangesWouldBeOverwrittenHelper.java
index 021ce824b9a7..7659c50e362a 100644
--- a/plugins/git4idea/src/git4idea/util/LocalChangesWouldBeOverwrittenHelper.java
+++ b/plugins/git4idea/src/git4idea/util/LocalChangesWouldBeOverwrittenHelper.java
@@ -35,12 +35,12 @@ import java.util.List;
public class LocalChangesWouldBeOverwrittenHelper {
@NotNull
- public static String getErrorNotificationDescription() {
+ private static String getErrorNotificationDescription() {
return getErrorDescription(true);
}
@NotNull
- public static String getErrorDialogDescription() {
+ private static String getErrorDialogDescription() {
return getErrorDescription(false);
}
@@ -56,7 +56,7 @@ public class LocalChangesWouldBeOverwrittenHelper {
}
}
- public static void showErrorNotification(@NotNull final Project project, @NotNull VirtualFile root, @NotNull final String operationName,
+ public static void showErrorNotification(@NotNull final Project project, @NotNull final VirtualFile root, @NotNull final String operationName,
@NotNull final Collection<String> relativeFilePaths) {
final Collection<String> absolutePaths = GitUtil.toAbsolute(root, relativeFilePaths);
final List<Change> changes = GitUtil.findLocalChangesForPaths(project, root, absolutePaths, false);
@@ -66,20 +66,33 @@ public class LocalChangesWouldBeOverwrittenHelper {
@Override
protected void hyperlinkActivated(@NotNull Notification notification,
@NotNull HyperlinkEvent e) {
- String title = "Local Changes Prevent from " + StringUtil.capitalize(operationName);
- String description = getErrorDialogDescription();
- if (changes.isEmpty()) {
- GitUtil.showPathsInDialog(project, absolutePaths, title, description);
- }
- else {
- DialogBuilder builder = new DialogBuilder(project);
- builder.setNorthPanel(new MultiLineLabel(description));
- builder.setCenterPanel(new ChangesBrowserWithRollback(project, changes));
- builder.addOkAction();
- builder.setTitle(title);
- builder.show();
- }
+ showErrorDialog(project, operationName, changes, absolutePaths);
}
});
}
+
+ public static void showErrorDialog(@NotNull Project project, @NotNull VirtualFile root, @NotNull String operationName,
+ @NotNull Collection<String> relativeFilePaths) {
+ Collection<String> absolutePaths = GitUtil.toAbsolute(root, relativeFilePaths);
+ List<Change> changes = GitUtil.findLocalChangesForPaths(project, root, absolutePaths, false);
+ showErrorDialog(project, operationName, changes, absolutePaths);
+ }
+
+ private static void showErrorDialog(@NotNull Project project, @NotNull String operationName, @NotNull List<Change> changes,
+ @NotNull Collection<String> absolutePaths) {
+ String title = "Local Changes Prevent from " + StringUtil.capitalize(operationName);
+ String description = getErrorDialogDescription();
+ if (changes.isEmpty()) {
+ GitUtil.showPathsInDialog(project, absolutePaths, title, description);
+ }
+ else {
+ DialogBuilder builder = new DialogBuilder(project);
+ builder.setNorthPanel(new MultiLineLabel(description));
+ builder.setCenterPanel(new ChangesBrowserWithRollback(project, changes));
+ builder.addOkAction();
+ builder.setTitle(title);
+ builder.show();
+ }
+ }
+
}