Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parsing of editor commandline in git-pr #259

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -40,12 +40,11 @@
import java.util.*;
import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
import java.util.logging.Level;
import java.util.regex.Matcher;
import java.util.stream.Collectors;

public class GitPr {
private static final StandardOpenOption APPEND = StandardOpenOption.APPEND;
private static final Pattern ISSUE_ID_PATTERN = Pattern.compile("([A-Za-z][A-Za-z0-9]+)?-([0-9]+)");
private static final Pattern ISSUE_MARKDOWN_PATTERN =
Pattern.compile("^\\[([A-Z]+-[0-9]+)\\]\\(https:\\/\\/bugs.openjdk.java.net\\/browse\\/[A-Z]+-[0-9]+\\): .*$");
@@ -55,13 +54,6 @@ private static void exit(String fmt, Object...args) {
System.exit(1);
}

private static <T> Supplier<T> die(String fmt, Object... args) {
return () -> {
exit(fmt, args);
return null;
};
}

private static String gitConfig(String key) {
try {
var pb = new ProcessBuilder("git", "config", key);
@@ -304,7 +296,17 @@ private static boolean spawnEditor(ReadOnlyRepository repo, Path file) throws IO
editor = "vi";
}

var pb = new ProcessBuilder(editor, file.toString());
// As an editor command may have multiple arguments, we need to add each single one
// to the ProcessBuilder. Arguments are split by whitespace and can be quoted.
// e.g. I found core.editor =
// \"C:\\\\Program Files\\\\Notepad++\\\\notepad++.exe\" -multiInst -notabbar -nosession -noPlugin
List<String> editorParts = new ArrayList<>();
Matcher em = Pattern.compile("\\s*([^\"]\\S*|\".+?\")\\s*").matcher(editor);
while (em.find()) {
editorParts.add(em.group(1));
}
editorParts.add(file.toString());
var pb = new ProcessBuilder(editorParts);
pb.inheritIO();
var p = pb.start();
try {