package com.atlassian.stash.internal.scm.git.upgrade;

import com.atlassian.stash.internal.scm.git.GitHookUtils;
import com.atlassian.bitbucket.repository.Repository;
import com.atlassian.bitbucket.scm.git.GitScmConfig;

import javax.annotation.Nonnull;
import java.io.IOException;

public class InstallHooksTask implements SynchronousUpgradeTask {

    private final GitScmConfig config;

    public InstallHooksTask(GitScmConfig config) {
        this.config = config;
    }

    @Nonnull
    @Override
    public String getDescription() {
        return "Install hook scripts in all Git repositories";
    }

    @Override
    public int getOrder() {
        return 3;
    }

    @Override
    public void upgrade(@Nonnull Repository repository) throws IOException {
        GitHookUtils.installHookScripts(config.getRepositoryDir(repository));
    }
}
