diff --git a/plugins/git4idea/src/git4idea/GitUtil.java b/plugins/git4idea/src/git4idea/GitUtil.java index 8383ec155496..b7d10a442e8e 100644 --- a/plugins/git4idea/src/git4idea/GitUtil.java +++ b/plugins/git4idea/src/git4idea/GitUtil.java @@ -552,13 +552,26 @@ public class GitUtil { } /** - * Unescape path returned by the Git + *
Unescape path returned by Git.
+ *
+ * If there are quotes in the file name, Git not only escapes them, but also encloses the file name into quotes:
+ * "\"quote"
+ *
+ * If there are spaces in the file name, Git displays the name as is, without escaping spaces and without enclosing name in quotes. + *
* * @param path a path to unescape - * @return unescaped path + * @return unescaped path ready to be searched in the VFS or file system. * @throws com.intellij.openapi.vcs.VcsException if the path in invalid */ - public static String unescapePath(String path) throws VcsException { + @NotNull + public static String unescapePath(@NotNull String path) throws VcsException { + final String QUOTE = "\""; + if (path.startsWith(QUOTE) && path.endsWith(QUOTE)) { + path = path.substring(1, path.length() - 1); + } + final int l = path.length(); StringBuilder rc = new StringBuilder(l); for (int i = 0; i < path.length(); i++) { @@ -580,6 +593,9 @@ public class GitUtil { case 'n': rc.append('\n'); break; + case '"': + rc.append('"'); + break; default: if (VcsFileUtil.isOctal(e)) { // collect sequence of characters as a byte array.