From b66390d9f09f9a34a6366ff857511eacc6ea296e Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Sat, 15 Dec 2012 18:36:40 +0400 Subject: [PATCH] [git tests] GitExecutor: allow command parameters with spaces surrounded by single quotes --- .../git4idea/test/GitExecutor.groovy | 43 ++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/plugins/git4idea/testFramework/git4idea/test/GitExecutor.groovy b/plugins/git4idea/testFramework/git4idea/test/GitExecutor.groovy index 74845a1c0691..3b3c3b4e5672 100644 --- a/plugins/git4idea/testFramework/git4idea/test/GitExecutor.groovy +++ b/plugins/git4idea/testFramework/git4idea/test/GitExecutor.groovy @@ -36,7 +36,7 @@ class GitExecutor extends Executor { public static String git(String command) { printVersionTheFirstTime(); - def split = StringUtil.split(command, " ") + def split = splitCommandInParameters(command) split.add(0, GIT_EXECUTABLE) log("git $command") for (int attempt = 0; attempt < 3; attempt++) { @@ -53,6 +53,47 @@ class GitExecutor extends Executor { throw new RuntimeException("fatal error during execution of Git command: $command"); } + private static List splitCommandInParameters(String command) { + List split = new ArrayList<>() + + boolean insideParam = false; + StringBuilder currentParam = new StringBuilder() + for (char c : command.toCharArray()) { + boolean flush = false; + if (insideParam) { + if (c == '\'') { + insideParam = false; + flush = true + } + else { + currentParam.append(c) + } + } + else if (c == '\'') { + insideParam = true; + } + else if (c == ' ') { + flush = true; + } + else { + currentParam.append(c) + } + + if (flush) { + if (!StringUtil.isEmptyOrSpaces(currentParam.toString())) { + split.add(currentParam.toString()) + } + currentParam = new StringBuilder() + } + } + + // last flush + if (!StringUtil.isEmptyOrSpaces(currentParam.toString())) { + split.add(currentParam.toString()) + } + return split; + } + public static String git(GitRepository repository, String command) { cd repository.root.path git command