From 2860b4df882bd14e55ac5eee4e1b6b10f171dea1 Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Tue, 1 Jul 2014 19:25:55 +0400 Subject: [PATCH] [git] Fix NPE: use before revision if there is no after revision Can happen if the file was deleted in the selected commit. --- .../changes/GitCommittedChangeListProvider.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/plugins/git4idea/src/git4idea/changes/GitCommittedChangeListProvider.java b/plugins/git4idea/src/git4idea/changes/GitCommittedChangeListProvider.java index baf835820ddb..f1ab1d476c6f 100644 --- a/plugins/git4idea/src/git4idea/changes/GitCommittedChangeListProvider.java +++ b/plugins/git4idea/src/git4idea/changes/GitCommittedChangeListProvider.java @@ -22,6 +22,7 @@ import com.intellij.openapi.util.io.FileUtil; 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.ContentRevision; import com.intellij.openapi.vcs.changes.committed.DecoratorManager; import com.intellij.openapi.vcs.changes.committed.VcsCommittedListsZipper; import com.intellij.openapi.vcs.changes.committed.VcsCommittedViewAuxiliary; @@ -197,7 +198,14 @@ public class GitCommittedChangeListProvider implements CommittedChangesProvider< final Collection changes = commit.getChanges(); if (changes.size() == 1) { - return Pair.create(commit, changes.iterator().next().getAfterRevision().getFile()); + Change change = changes.iterator().next(); + ContentRevision revision = change.getAfterRevision(); + if (revision == null) { + revision = change.getBeforeRevision(); + } + assert revision != null : "Revision can't be null in " + change; + FilePath filePathInRevision = revision.getFile(); + return Pair.create(commit, filePathInRevision); } for (Change change : changes) { if (change.getAfterRevision() != null && FileUtil.filesEqual(filePath.getIOFile(), change.getAfterRevision().getFile().getIOFile())) {