From 316ba82f29b3b23dd79add4849aebacd6d05ca1a Mon Sep 17 00:00:00 2001 From: Aleksey Pivovarov Date: Wed, 24 Jan 2018 19:15:10 +0300 Subject: [PATCH] git: support partial changes for moved files --- .../vcs/impl/LineStatusTrackerManager.kt | 4 +-- .../checkin/GitCheckinEnvironment.java | 34 +++++++++++++++++-- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/LineStatusTrackerManager.kt b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/LineStatusTrackerManager.kt index 5c50fe31b354..3db35a2ab15e 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/LineStatusTrackerManager.kt +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/LineStatusTrackerManager.kt @@ -299,8 +299,8 @@ class LineStatusTrackerManager( val change = ChangeListManager.getInstance(project).getChange(virtualFile) return change != null && change.javaClass == Change::class.java && - change.type == Change.Type.MODIFICATION && change.afterRevision is CurrentContentRevision - + (change.type == Change.Type.MODIFICATION || change.type == Change.Type.MOVED) && + change.afterRevision is CurrentContentRevision } override fun arePartialChangelistsEnabled(virtualFile: VirtualFile): Boolean { diff --git a/plugins/git4idea/src/git4idea/checkin/GitCheckinEnvironment.java b/plugins/git4idea/src/git4idea/checkin/GitCheckinEnvironment.java index b69b4a5d3e38..efbf7ba76d1c 100644 --- a/plugins/git4idea/src/git4idea/checkin/GitCheckinEnvironment.java +++ b/plugins/git4idea/src/git4idea/checkin/GitCheckinEnvironment.java @@ -53,6 +53,7 @@ import com.intellij.ui.components.JBCheckBox; import com.intellij.ui.components.JBLabel; import com.intellij.util.FunctionUtil; import com.intellij.util.NullableFunction; +import com.intellij.util.ObjectUtils; import com.intellij.util.PairConsumer; import com.intellij.util.concurrency.FutureResult; import com.intellij.util.textCompletion.DefaultTextCompletionValueDescriptor; @@ -399,8 +400,20 @@ public class GitCheckinEnvironment implements CheckinEnvironment { List helpers = result.first; List partialChanges = result.second; + + List pathsToDelete = new ArrayList<>(); + for (Change change : partialChanges) { + if (change.getType() == Change.Type.MOVED) { + ContentRevision beforeRevision = ObjectUtils.assertNotNull(change.getBeforeRevision()); + pathsToDelete.add(beforeRevision.getFile()); + } + } + GitFileUtils.delete(myProject, repository.getRoot(), pathsToDelete, "--ignore-unmatch"); + + for (int i = 0; i < partialChanges.size(); i++) { - CurrentContentRevision revision = (CurrentContentRevision)partialChanges.get(i).getAfterRevision(); + Change change = partialChanges.get(i); + CurrentContentRevision revision = (CurrentContentRevision)change.getAfterRevision(); assert revision != null; FilePath path = revision.getFile(); @@ -408,7 +421,7 @@ public class GitCheckinEnvironment implements CheckinEnvironment { VirtualFile file = revision.getVirtualFile(); if (file == null) throw new VcsException("Can't find file: " + path.getPath()); - GitIndexUtil.StagedFile stagedFile = GitIndexUtil.list(repository, path); + GitIndexUtil.StagedFile stagedFile = getStagedFile(repository, change); boolean isExecutable = stagedFile != null && stagedFile.isExecutable(); Pair.NonNull fileContent = @@ -417,6 +430,7 @@ public class GitCheckinEnvironment implements CheckinEnvironment { GitIndexUtil.write(repository, path, fileContent.second, isExecutable); } + Runnable callback = () -> ApplicationManager.getApplication().invokeLater(() -> { for (PartialCommitHelper helper : helpers) { try { @@ -431,6 +445,22 @@ public class GitCheckinEnvironment implements CheckinEnvironment { return Pair.create(callback, partialChanges); } + @Nullable + private static GitIndexUtil.StagedFile getStagedFile(@NotNull GitRepository repository, @NotNull Change change) throws VcsException { + FilePath bPath = getBeforePath(change); + if (bPath != null) { + GitIndexUtil.StagedFile file = GitIndexUtil.list(repository, bPath); + if (file != null) return file; + } + + FilePath aPath = getAfterPath(change); + if (aPath != null) { + GitIndexUtil.StagedFile file = GitIndexUtil.list(repository, aPath); + if (file != null) return file; + } + return null; + } + @Nullable private static T computeAfterLSTManagerUpdate(@NotNull Project project, @NotNull final Computable computation) { assert !ApplicationManager.getApplication().isDispatchThread();