From d2d75dc1680e906199bffc1a71b3635ed49a85eb Mon Sep 17 00:00:00 2001 From: Gibson Chikafa Date: Thu, 12 Oct 2023 12:08:29 +0200 Subject: [PATCH] [HWORKS-787] Fix git repository not updating current commit and branch (#1582) (#1583) (#1411) * Fix git repository not updating current commit and branch * PR review comment --- .../hops/hopsworks/common/dao/git/GitRepositoryFacade.java | 4 +++- .../hops/hopsworks/common/git/GitExecutionController.java | 7 +++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/hopsworks-common/src/main/java/io/hops/hopsworks/common/dao/git/GitRepositoryFacade.java b/hopsworks-common/src/main/java/io/hops/hopsworks/common/dao/git/GitRepositoryFacade.java index 43d6eb5224..869536bcd0 100644 --- a/hopsworks-common/src/main/java/io/hops/hopsworks/common/dao/git/GitRepositoryFacade.java +++ b/hopsworks-common/src/main/java/io/hops/hopsworks/common/dao/git/GitRepositoryFacade.java @@ -121,7 +121,9 @@ public GitRepository create(Project project, GitProvider gitProvider, Users user } public GitRepository updateRepository(GitRepository repository) { - return super.update(repository); + repository = em.merge(repository); + em.flush(); + return repository; } public GitRepository updateRepositoryCid(GitRepository repository, String pid) { diff --git a/hopsworks-common/src/main/java/io/hops/hopsworks/common/git/GitExecutionController.java b/hopsworks-common/src/main/java/io/hops/hopsworks/common/git/GitExecutionController.java index 81e365ecce..49d847f7d3 100644 --- a/hopsworks-common/src/main/java/io/hops/hopsworks/common/git/GitExecutionController.java +++ b/hopsworks-common/src/main/java/io/hops/hopsworks/common/git/GitExecutionController.java @@ -195,7 +195,7 @@ public synchronized GitOpExecution updateGitExecutionState(Project project, User GitOpExecution execution = getExecutionInRepository(repository, executionId); if (newState.isFinalState()) { if (newState == GitOpExecutionState.SUCCESS) { - finalizeSuccessfulExecution(execution, stateDTO); + repository = finalizeSuccessfulExecution(execution, stateDTO); } if (newState == GitOpExecutionState.CANCELLED) { gitCommandExecutor.cancelGitExecution(execution, stateDTO.getMessage()); @@ -213,11 +213,13 @@ public synchronized GitOpExecution updateGitExecutionState(Project project, User return gitOpExecutionFacade.updateState(execution, newState, stateDTO.getMessage()); } - private void finalizeSuccessfulExecution(GitOpExecution execution, GitCommandExecutionStateUpdateDTO stateDTO) { + private GitRepository finalizeSuccessfulExecution(GitOpExecution execution, + GitCommandExecutionStateUpdateDTO stateDTO) { //Every successful operation should update the repository current commit and branch GitRepository repository = execution.getRepository(); repository.setCurrentBranch(stateDTO.getBranch()); repository.setCurrentCommit(stateDTO.getCommitHash()); + GitRepository updateRepository = gitRepositoryFacade.updateRepository(repository); GitCommandConfiguration executedCommandConfig = execution.getGitCommandConfiguration(); if (executedCommandConfig.getCommandType() == GitCommandType.DELETE_BRANCH) { //if we deleted a branch then we should also delete all the commits for this branch @@ -232,5 +234,6 @@ private void finalizeSuccessfulExecution(GitOpExecution execution, GitCommandExe remotesJson), repository); } } + return updateRepository; } }