diff --git a/plugins/git4idea/src/git4idea/changes/GitCommittedChangeListProvider.java b/plugins/git4idea/src/git4idea/changes/GitCommittedChangeListProvider.java index 3faed6261dc7..dd9d77760fb4 100644 --- a/plugins/git4idea/src/git4idea/changes/GitCommittedChangeListProvider.java +++ b/plugins/git4idea/src/git4idea/changes/GitCommittedChangeListProvider.java @@ -20,6 +20,7 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vcs.*; +import com.intellij.openapi.vcs.changes.Change; import com.intellij.openapi.vcs.changes.committed.DecoratorManager; import com.intellij.openapi.vcs.changes.committed.VcsCommittedListsZipper; import com.intellij.openapi.vcs.changes.committed.VcsCommittedViewAuxiliary; @@ -227,7 +228,6 @@ public class GitCommittedChangeListProvider implements CommittedChangesProvider< @Override public Pair getOneList(VirtualFile file, final VcsRevisionNumber number) throws VcsException { - // todo implement in proper way final FilePathImpl filePath = new FilePathImpl(file); final GitRepositoryLocation l = (GitRepositoryLocation) getLocationFor(filePath); VirtualFile root = LocalFileSystem.getInstance().findFileByIoFile(l.getRoot()); @@ -239,6 +239,7 @@ public class GitCommittedChangeListProvider implements CommittedChangesProvider< GitUtil.getLocalCommittedChanges(myProject, root, new Consumer() { public void consume(GitSimpleHandler h) { h.addParameters("-n1"); + h.addParameters("-M"); h.addParameters(number.asString()); } }, new Consumer() { @@ -247,7 +248,45 @@ public class GitCommittedChangeListProvider implements CommittedChangesProvider< result[0] = committedChangeList; } }, false); - return new Pair(result[0], filePath); + + final Collection changes = result[0].getChanges(); + if (changes.size() == 1) { + return new Pair(result[0], changes.iterator().next().getAfterRevision().getFile()); + } + for (Change change : changes) { + if (change.getAfterRevision() != null && filePath.getIOFile().equals(change.getAfterRevision().getFile().getIOFile())) { + return new Pair(result[0], filePath); + } + } + // go for history + final File[] correctPath = new File[1]; + correctPath[0] = filePath.getIOFile(); + GitUtil.getLocalCommittedChanges(myProject, root, new Consumer() { + public void consume(GitSimpleHandler h) { + h.addParameters("-M"); + h.addParameters(number.asString() + ".."); + } + }, new Consumer() { + @Override + public void consume(CommittedChangeList committedChangeList) { + final Collection list = committedChangeList.getChanges(); + checkForRename(list, correctPath); + } + }, false); + checkForRename(result[0].getChanges(), correctPath); + return new Pair(result[0], new FilePathImpl(correctPath[0], false)); + } + + private void checkForRename(Collection list, File[] obj) { + for (Change change : list) { + if (change.getAfterRevision() != null && change.getBeforeRevision() != null) { + if (change.getAfterRevision().getFile().getIOFile().equals(obj[0]) && + (! change.getBeforeRevision().getFile().getIOFile().equals(obj[0]))) { + obj[0] = change.getBeforeRevision().getFile().getIOFile(); + return; + } + } + } } public int getFormatVersion() {