package fr.emse.gitlab.saref.jobs;

import org.eclipse.jgit.api.Git;

import fr.emse.gitlab.saref.SAREFPipelineException;
import fr.emse.gitlab.saref.entities.git.Version;

public class CheckoutJob extends JobRunner {

	public CheckoutJob(String testSuiteName) {
		super(testSuiteName);
	}
	
	public void checkoutVersion(Version version) throws SAREFPipelineException {
		if(version.getRef() == null) {
			return;
		}
		try(Git git = Git.open(version.getRepository().getDirectory())) {
			git.checkout().setName(version.getRef().getName()).call();
		} catch(Exception e) {
			SAREFPipelineException ex = new SAREFPipelineException("Error while checkout version " + version, e);
			logger.error("Error while checkout version " + version, e);
			throw ex;
		}
	}

}
