<commit_before>package repositories

import (
	"github.com/ovh/cds/sdk"
	"github.com/ovh/cds/sdk/log"
)

func (s *Service) processCheckout(op *sdk.Operation) error {
	gitRepo, _, currentBranch, err := s.processGitClone(op)
	if err != nil {
		return sdk.WrapError(err, "unable to process gitclone")
	}

	//Check is repo has diverged
	hasDiverged, err := gitRepo.HasDiverged()
	if err != nil {
		log.Error("Repositories> processCheckout> HasDiverged> [%s] Error: %v", op.UUID, err)
		return err
	}

	if hasDiverged {
		if err := gitRepo.ResetHard("origin/" + currentBranch); err != nil {
			log.Error("Repositories> processCheckout> ResetHard> [%s] Error: %v", op.UUID, err)
			return err
		}
	}

	if op.Setup.Checkout.Branch == "" {
		op.Setup.Checkout.Branch = op.RepositoryInfo.DefaultBranch
	}<commit_msg>fix(repositories): always reset hard (#4282)<commit_after>package repositories

import (
	"github.com/ovh/cds/sdk"
	"github.com/ovh/cds/sdk/log"
)

func (s *Service) processCheckout(op *sdk.Operation) error {
	gitRepo, _, currentBranch, err := s.processGitClone(op)
	if err != nil {
		return sdk.WrapError(err, "unable to process gitclone")
	}

	if err := gitRepo.ResetHard("origin/" + currentBranch); err != nil {
		log.Error("Repositories> processCheckout> ResetHard> [%s] Error: %v", op.UUID, err)
		return err
	}

	if op.Setup.Checkout.Branch == "" {
		op.Setup.Checkout.Branch = op.RepositoryInfo.DefaultBranch
	}
{'fraction_non_alphanumeric': 0.15017543859649124, 'fraction_numerical': 0.002807017543859649, 'mean_word_length': 4.360902255639098, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5383347', 'n_tokens_mistral': 548, 'n_tokens_neox': 536, 'n_words': 115}