package com.atlassian.bitbucket.mesh.git.builder;

import com.atlassian.bitbucket.mesh.git.hook.DefaultGitHookService;
import com.atlassian.bitbucket.mesh.git.hook.GitHookService;

import javax.annotation.Nonnull;

/**
 * {@code GitProcessBuilderConfigurer} that allows the {@link GitHookService} to set the required environment variables
 * needed for the git hook callbacks. It's important that this gets triggered on <em>all</em> git processes to ensure
 * the {@code reference-transaction} hook gets called whenever a ref update in a repository is attempted.
 * <p>
 * {@link DefaultGitHookService} cannot not directly implement {@link GitProcessBuilderConfigurer} without triggering
 * a wiring loop {@code (gitProcessBuilderFactory -> gitHookService -> packObjectsHookHandler -> gitProcessBuilderFactory)}.
 * This class breaks that loop.
 */
public class HookGitProcessBuilderConfigurer implements GitProcessBuilderConfigurer {

    private final GitHookService gitHookService;

    public HookGitProcessBuilderConfigurer(GitHookService hookService) {
        gitHookService = hookService;
    }

    @Override
    public void configure(@Nonnull GitProcessBuilder builder) {
        gitHookService.configure(builder);
    }
}
