diff --git a/app/server/appsmith-git/src/main/java/com/appsmith/git/service/GitExecutorImpl.java b/app/server/appsmith-git/src/main/java/com/appsmith/git/service/GitExecutorImpl.java index 4127437c7a..809bdad086 100644 --- a/app/server/appsmith-git/src/main/java/com/appsmith/git/service/GitExecutorImpl.java +++ b/app/server/appsmith-git/src/main/java/com/appsmith/git/service/GitExecutorImpl.java @@ -329,11 +329,10 @@ public class GitExecutorImpl implements GitExecutor { } @Override - public Mono> listBranches(Path repoSuffix, ListBranchCommand.ListMode listMode, String remoteUrl, String privateKey, String publicKey) { + public Mono> listBranches(Path repoSuffix, ListBranchCommand.ListMode listMode, String defaultBranch) { Path baseRepoPath = createRepoPath(repoSuffix); return Mono.fromCallable(() -> { log.debug(Thread.currentThread().getName() + ": Get branches for the application " + repoSuffix); - TransportConfigCallback transportConfigCallback = new SshTransportConfigCallback(privateKey, publicKey); Git git = Git.open(baseRepoPath.toFile()); List refList; if (listMode == null) { @@ -351,21 +350,15 @@ public class GitExecutorImpl implements GitExecutor { gitBranchListDTO.setDefault(true); branchList.add(gitBranchListDTO); } else { - // Get default branch name from the remote - String defaultBranch = git.lsRemote().setRemote(remoteUrl).setTransportConfigCallback(transportConfigCallback).callAsMap().get("HEAD").getTarget().getName(); - GitBranchListDTO gitBranchListDTO = new GitBranchListDTO(); - gitBranchListDTO.setBranchName(defaultBranch.replace("refs/heads/","")); - gitBranchListDTO.setDefault(true); - branchList.add(gitBranchListDTO); - for(Ref ref : refList) { - if(!ref.getName().equals(defaultBranch)) { - gitBranchListDTO = new GitBranchListDTO(); - gitBranchListDTO.setBranchName(ref.getName() - .replace("refs/heads/","")); - gitBranchListDTO.setDefault(false); - branchList.add(gitBranchListDTO); + GitBranchListDTO gitBranchListDTO = new GitBranchListDTO(); + gitBranchListDTO.setBranchName(ref.getName() + .replace("refs/heads/","")); + gitBranchListDTO.setDefault(false); + if(gitBranchListDTO.getBranchName().equals(defaultBranch)) { + gitBranchListDTO.setDefault(true); } + branchList.add(gitBranchListDTO); } } git.close(); diff --git a/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/git/GitExecutor.java b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/git/GitExecutor.java index bfef27622a..532c12a9c7 100644 --- a/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/git/GitExecutor.java +++ b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/git/GitExecutor.java @@ -103,7 +103,7 @@ public interface GitExecutor { * @param repoSuffix repo suffix path in local repo * @return List of branches for the application */ - Mono> listBranches(Path repoSuffix, ListBranchCommand.ListMode listMode, String remoteUrl, String privateKey, String publicKey); + Mono> listBranches(Path repoSuffix, ListBranchCommand.ListMode listMode, String defaultBranch); /** * This method will handle the git-status functionality diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/GitServiceImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/GitServiceImpl.java index 64e2b679d8..f81452182b 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/GitServiceImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/GitServiceImpl.java @@ -596,7 +596,7 @@ public class GitServiceImpl implements GitService { gitExecutor.checkoutToBranch(repoSuffix, srcBranch) .onErrorResume(error -> Mono.error(new AppsmithException(AppsmithError.GIT_ACTION_FAILED, "checkout", "Unable to find " + srcBranch))), gitExecutor.fetchRemote(repoSuffix, defaultGitAuth.getPublicKey(), defaultGitAuth.getPrivateKey(), false)) - .flatMap(ignore -> gitExecutor.listBranches(repoSuffix, ListBranchCommand.ListMode.REMOTE, srcBranchGitData.getRemoteUrl(), defaultGitAuth.getPublicKey(), defaultGitAuth.getPrivateKey()) + .flatMap(ignore -> gitExecutor.listBranches(repoSuffix, ListBranchCommand.ListMode.REMOTE, srcBranchGitData.getBranchName()) .flatMap(branchList -> { boolean isDuplicateName = branchList.stream() // TODO We are only supporting origin as the remote name so this is safe @@ -800,9 +800,7 @@ public class GitServiceImpl implements GitService { return gitExecutor.listBranches(repoPath, null, - gitApplicationMetadata.getRemoteUrl(), - gitApplicationMetadata.getGitAuth().getPrivateKey(), - gitApplicationMetadata.getGitAuth().getPublicKey()) + gitApplicationMetadata.getBranchName()) .onErrorResume(error -> Mono.error(new AppsmithException( AppsmithError.GIT_ACTION_FAILED, "branch --list", diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/GitServiceTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/GitServiceTest.java index 8080b88658..4aa66cbf1b 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/GitServiceTest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/GitServiceTest.java @@ -598,7 +598,7 @@ public class GitServiceTest { branchList.add(gitBranchListDTO); Mockito.when(userService.findByEmail(Mockito.anyString())).thenReturn(Mono.just(new User())); - Mockito.when(gitExecutor.listBranches(Mockito.any(Path.class), eq(null), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) + Mockito.when(gitExecutor.listBranches(Mockito.any(Path.class), eq(null), Mockito.anyString())) .thenReturn(Mono.just(branchList)); Mockito.when(gitExecutor.cloneApplication(Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just("defaultBranchName")); @@ -646,7 +646,7 @@ public class GitServiceTest { branchList.add(gitBranchListDTO); Mockito.when(userService.findByEmail(Mockito.anyString())).thenReturn(Mono.just(new User())); - Mockito.when(gitExecutor.listBranches(Mockito.any(Path.class), eq(null), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) + Mockito.when(gitExecutor.listBranches(Mockito.any(Path.class), eq(null), Mockito.anyString())) .thenReturn(Mono.just(branchList)); Mockito.when(gitExecutor.cloneApplication(Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just("defaultBranchName"));