From 3d206e04273f36229ad6d0d9f3c520a5310f671e Mon Sep 17 00:00:00 2001 From: Ioannis Canellos Date: Wed, 25 Sep 2024 18:39:55 +0300 Subject: [PATCH] chore: generate commands also check if remote repos are defined --- .../argocd/cli/application/GenerationBaseCommand.java | 7 +++++++ .../java/io/quarkiverse/argocd/cli/utils/Git.java | 11 +++++++++++ 2 files changed, 18 insertions(+) diff --git a/cli/src/main/java/io/quarkiverse/argocd/cli/application/GenerationBaseCommand.java b/cli/src/main/java/io/quarkiverse/argocd/cli/application/GenerationBaseCommand.java index b209226..dbfa1f5 100644 --- a/cli/src/main/java/io/quarkiverse/argocd/cli/application/GenerationBaseCommand.java +++ b/cli/src/main/java/io/quarkiverse/argocd/cli/application/GenerationBaseCommand.java @@ -6,6 +6,7 @@ import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.Optional; import java.util.Properties; import java.util.concurrent.Callable; @@ -48,6 +49,12 @@ public Integer call() { return ExitCode.USAGE; } + Map remotes = Git.getRemotes(scmRoot.get()); + if (remotes.isEmpty()) { + System.out.println("Unable to determine the SCM remotes for the project at " + projectRoot + ". Aborting."); + return ExitCode.USAGE; + } + BuildTool buildTool = QuarkusProjectHelper.detectExistingBuildTool(projectRoot); if (buildTool == null) { System.out.println("Unable to determine the build tool used for the project at " + projectRoot); diff --git a/cli/src/main/java/io/quarkiverse/argocd/cli/utils/Git.java b/cli/src/main/java/io/quarkiverse/argocd/cli/utils/Git.java index 59222bf..4669e7e 100644 --- a/cli/src/main/java/io/quarkiverse/argocd/cli/utils/Git.java +++ b/cli/src/main/java/io/quarkiverse/argocd/cli/utils/Git.java @@ -3,6 +3,7 @@ import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.Map; import java.util.Optional; import org.eclipse.jgit.api.FetchCommand; @@ -159,6 +160,16 @@ public static Optional getRemoteName(String url) { }); } + /** + * Get the git remote urls as a map. + * + * @param path the path to the git config. + * @return A {@link Map} of urls per remote. + */ + public static Map getRemotes(Path path) { + return io.dekorate.utils.Git.getRemotes(path); + } + public static Optional getScmRoot() { Path dir = Paths.get("").toAbsolutePath(); while (dir != null && !dir.resolve(DOT_GIT).toFile().exists()) {