From 2192eaf0ea33c4fa93e0b90d1983719ac88ec42b Mon Sep 17 00:00:00 2001 From: "Nadya.Zabrodina" Date: Wed, 20 Feb 2013 14:26:33 +0400 Subject: [PATCH] IDEA-101361 Copying file from hg ignored directory and adding it to VCS problem fixed. *How to reproduce: try to copy unversioned or ignored file, then hg ask you to add it to vcs,when you say "Yes" file will be copied,but not added to vcs. it happens because hg can't perform "hg copy" action with unversoned source file. * if source file is not under vcs the copy command should be replaced by add command. --- .../src/org/zmlx/hg4idea/HgVFSListener.java | 16 ++++++++++++++++ .../zmlx/hg4idea/command/HgStatusCommand.java | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/HgVFSListener.java b/plugins/hg4idea/src/org/zmlx/hg4idea/HgVFSListener.java index e8ef1fa502cd..1f1be2056375 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/HgVFSListener.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/HgVFSListener.java @@ -140,6 +140,22 @@ public class HgVFSListener extends VcsVFSListener { @Override public void run(@NotNull ProgressIndicator aProgressIndicator) { final ArrayList adds = new ArrayList(); final HashMap copies = new HashMap(); // from -> to + //delete unversioned and ignored files from copy source + if (myProject != null) { + Collection unversionedAndIgnoredFiles = new ArrayList(); + final Map> sortedSourceFilesByRepos = HgUtil.sortByHgRoots(myProject, copyFromMap.values()); + HgStatusCommand statusCommand = new HgStatusCommand(myProject); + statusCommand.setOnlyUntrackedTrue(); + statusCommand.setIncludeIgnored(true); + for (VirtualFile repo : sortedSourceFilesByRepos.keySet()) { + Set changes = statusCommand.execute(repo); + for (HgChange change : changes) { + unversionedAndIgnoredFiles.add(change.afterFile().toFilePath().getVirtualFile()); + } + } + copyFromMap.values().removeAll(unversionedAndIgnoredFiles); + } + // separate adds from copies for (VirtualFile file : addedFiles) { diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgStatusCommand.java b/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgStatusCommand.java index 9c469657ad98..3d377e9155c6 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgStatusCommand.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgStatusCommand.java @@ -187,7 +187,7 @@ public class HgStatusCommand { return changes; } - private void setOnlyUntrackedTrue() { + public void setOnlyUntrackedTrue() { includeAdded = false; includeModified = false; includeRemoved = false;