Explorar o código

fix: can not check out other remote branch when cloning repository

claws %!s(int64=4) %!d(string=hai) anos
pai
achega
21be1ef5d1

+ 5 - 1
web/src/main/java/cn/seecoder/web/core/pipeline/handler/SonarJavaImageBuildHandler.java

@@ -92,7 +92,11 @@ public class SonarJavaImageBuildHandler extends AbstractHandler {
             //注:temp文件/目录系统会定时删,实际文件名喂 prefix + 它生成的suffix随机数,所以不会命名冲突
             //注:temp文件/目录系统会定时删,实际文件名喂 prefix + 它生成的suffix随机数,所以不会命名冲突
             directory = Files.createTempDirectory("seecoder-devcloud-");
             directory = Files.createTempDirectory("seecoder-devcloud-");
             Git git = gitApi.clone(repoUrl, directory.toString());
             Git git = gitApi.clone(repoUrl, directory.toString());
-            git.checkout().setCreateBranch(false).setStartPoint(branchOrHash).setName(branchOrHash).call();
+            if (isBranch) {
+                git.checkout().setCreateBranch(false).setStartPoint("origin/" + branchOrHash).setName("origin/" + branchOrHash).call();
+            } else {
+                git.checkout().setCreateBranch(false).setStartPoint(branchOrHash).setName(branchOrHash).call();
+            }
         } catch (Exception e) {
         } catch (Exception e) {
             context.appendErrorResult(PipelineException.GIT_CLONE_ERROR, e);
             context.appendErrorResult(PipelineException.GIT_CLONE_ERROR, e);
             throw new PipelineException(HttpStatus.SC_SERVICE_UNAVAILABLE, PipelineException.GIT_CLONE_ERROR, e);
             throw new PipelineException(HttpStatus.SC_SERVICE_UNAVAILABLE, PipelineException.GIT_CLONE_ERROR, e);