From e4225a51691cbf807c138f3637db9c4eb278fe7a Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Thu, 21 Jun 2012 20:06:14 +0400 Subject: [PATCH] [git] IDEA-87513 Support quotes in file names (Git escapes them); remove quotes added by Git, surrounding file names, if they contain escaped sequences. --- plugins/git4idea/src/git4idea/GitUtil.java | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) 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.