diff --git a/rt/src/main/java/org/jetbrains/git4idea/rt/http/GitAskPassApp.java b/rt/src/main/java/org/jetbrains/git4idea/rt/http/GitAskPassApp.java index 2009dc1..c99d1cd 100644 --- a/rt/src/main/java/org/jetbrains/git4idea/rt/http/GitAskPassApp.java +++ b/rt/src/main/java/org/jetbrains/git4idea/rt/http/GitAskPassApp.java @@ -15,11 +15,8 @@ */ package org.jetbrains.git4idea.rt.http; -import org.jetbrains.git4idea.rt.GitExternalApp; - import jakarta.annotation.Nonnull; - -import java.util.Map; +import org.jetbrains.git4idea.rt.GitExternalApp; /** *
This is a program that would be called by Git when an HTTP connection is needed, that requires authorization,
@@ -44,6 +41,40 @@
* @author Kirill Likhodedov
*/
public class GitAskPassApp implements GitExternalApp {
+ private record Arguments(boolean usernameNeeded, @Nonnull String url) {
+ @Nonnull
+ public static Arguments parse(@Nonnull String arg) {
+ boolean username = startsWithIgnoreCase(arg, "username");
+ String url;
+ String[] split = arg.split(" ");
+ if (split.length > 2) {
+ url = parseUrl(split[2]);
+ }
+ else {
+ url = ""; // XML RPC doesn't like nulls
+ }
+ return new Arguments(username, url);
+ }
+
+ private static boolean startsWithIgnoreCase(@Nonnull String s, @Nonnull String start) {
+ return s.regionMatches(true, 0, start, 0, start.length());
+ }
+
+ private static String parseUrl(@Nonnull String urlArg) {
+ // un-quote and remove the trailing colon
+ String url = urlArg;
+ if (url.startsWith("'")) {
+ url = url.substring(1);
+ }
+ if (url.endsWith(":")) {
+ url = url.substring(0, url.length() - 1);
+ }
+ if (url.endsWith("'")) {
+ url = url.substring(0, url.length() - 1);
+ }
+ return url;
+ }
+ }
// STDOUT is used to provide credentials to Git process; STDERR is used to print error message to the main IDEA command line.
@SuppressWarnings("UseOfSystemOutOrSystemErr")
@@ -53,20 +84,18 @@ public static void main(String[] args) {
throw new IllegalArgumentException("No arguments specified!");
}
- Map.Entry