Skip to content

Commit

Permalink
[HWORKS-787] Fix git repository not updating current commit and branc…
Browse files Browse the repository at this point in the history
…h (#1582) (#1410)

* Fix git repository not updating current commit and branch

* PR review comment
  • Loading branch information
gibchikafa authored Oct 12, 2023
1 parent eafc534 commit 7f644f9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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
Expand All @@ -232,5 +234,6 @@ private void finalizeSuccessfulExecution(GitOpExecution execution, GitCommandExe
remotesJson), repository);
}
}
return updateRepository;
}
}

0 comments on commit 7f644f9

Please sign in to comment.