Invalidate branches cache synchronously on create new branch

This commit is contained in:
Eduard Heimbuch
2020-07-22 10:18:52 +02:00
parent 9a1ec7a5ef
commit 5e10f6b730
5 changed files with 57 additions and 1 deletions

View File

@@ -30,6 +30,7 @@ import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.lib.Ref;
import sonia.scm.event.ScmEventBus;
import sonia.scm.repository.Branch;
import sonia.scm.repository.BranchCreatedEvent;
import sonia.scm.repository.GitUtil;
import sonia.scm.repository.InternalRepositoryException;
import sonia.scm.repository.PostReceiveRepositoryHookEvent;
@@ -69,6 +70,8 @@ public class GitBranchCommand extends AbstractGitCommand implements BranchComman
eventBus.post(new PreReceiveRepositoryHookEvent(hookEvent));
Ref ref = git.branchCreate().setStartPoint(request.getParentBranch()).setName(request.getNewBranch()).call();
eventBus.post(new PostReceiveRepositoryHookEvent(hookEvent));
// Clear cache synchronously to avoid branch not found in invalid cache
eventBus.post(new BranchCreatedEvent(repository, request.getNewBranch()));
return Branch.normalBranch(request.getNewBranch(), GitUtil.getId(ref.getObjectId()));
} catch (GitAPIException | IOException ex) {
throw new InternalRepositoryException(repository, "could not create branch " + request.getNewBranch(), ex);