Get default branch from DB instead of remote to save time (#8844)
This commit is contained in:
parent
baf67a8988
commit
b951d8db21
|
|
@ -329,11 +329,10 @@ public class GitExecutorImpl implements GitExecutor {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Mono<List<GitBranchListDTO>> listBranches(Path repoSuffix, ListBranchCommand.ListMode listMode, String remoteUrl, String privateKey, String publicKey) {
|
||||
public Mono<List<GitBranchListDTO>> 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<Ref> 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();
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@ public interface GitExecutor {
|
|||
* @param repoSuffix repo suffix path in local repo
|
||||
* @return List of branches for the application
|
||||
*/
|
||||
Mono<List<GitBranchListDTO>> listBranches(Path repoSuffix, ListBranchCommand.ListMode listMode, String remoteUrl, String privateKey, String publicKey);
|
||||
Mono<List<GitBranchListDTO>> listBranches(Path repoSuffix, ListBranchCommand.ListMode listMode, String defaultBranch);
|
||||
|
||||
/**
|
||||
* This method will handle the git-status functionality
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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"));
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user