[git] IDEA-89445 Update the IO-File of the FilePath to handle moves of the file ...
authorKirill Likhodedov <Kirill.Likhodedov@jetbrains.com>
Thu, 2 Aug 2012 16:59:25 +0000 (20:59 +0400)
committerKirill Likhodedov <Kirill.Likhodedov@jetbrains.com>
Thu, 2 Aug 2012 17:00:12 +0000 (21:00 +0400)
plugins/git4idea/src/git4idea/history/GitHistoryProvider.java

index 541ae7f41bb84465310f2b75aa6feb75280b9539..5b90c14b07e36918d65ec88dbbec3bf7c922f168 100644 (file)
@@ -20,6 +20,7 @@ import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.openapi.vcs.FilePath;
+import com.intellij.openapi.vcs.FilePathImpl;
 import com.intellij.openapi.vcs.VcsException;
 import com.intellij.openapi.vcs.changes.ContentRevision;
 import com.intellij.openapi.vcs.history.*;
@@ -160,7 +161,7 @@ public class GitHistoryProvider implements VcsHistoryProvider, VcsCacheableHisto
     partner.reportCreatedEmptySession(emptySession);
     final GitExecutableValidator validator = GitVcs.getInstance(myProject).getExecutableValidator();
     try {
-      GitHistoryUtils.history(myProject, path, null, new Consumer<GitFileRevision>() {
+      GitHistoryUtils.history(myProject, refreshPath(path), null, new Consumer<GitFileRevision>() {
         public void consume(GitFileRevision gitFileRevision) {
           partner.acceptRevision(gitFileRevision);
         }
@@ -177,8 +178,17 @@ public class GitHistoryProvider implements VcsHistoryProvider, VcsCacheableHisto
   }
 
   /**
-   * {@inheritDoc}
+   * Refreshes the IO File inside this FilePath to let it survive moves.
    */
+  @NotNull
+  private static FilePath refreshPath(@NotNull FilePath path) {
+    VirtualFile virtualFile = path.getVirtualFile();
+    if (virtualFile == null) {
+      return path;
+    }
+    return new FilePathImpl(virtualFile);
+  }
+
   public boolean supportsHistoryForDirectories() {
     return true;
   }