<commit_before>package com.khoubyari.example.git;

import java.io.File;
import java.io.IOException;

import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
import org.eclipse.jgit.transport.FetchResult;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.slf4j.Logger;



public class GitManager {

	@Autowired
	private RepositoryProperties repositoryProperties;
	
	private static final Logger log = LoggerFactory.getLogger(GitManager.class);

	public GitManager() {

	}

	public void updateLocalRepository() {
		try {
		Git git = openRepository();
		FetchResult result = git.fetch().setCheckFetchedObjects(true).call();
		log.debug("The result of fetching the repo:" + result);
		}
		catch(IOException | IllegalStateException | GitAPIException ex) {
			log.error("An exception occured while updating the local repo:", ex);
		}
	}
	
	private Git openRepository() throws IOException, IllegalStateException, GitAPIException {
		File gitDirectory = new File(repositoryProperties.getLocalRepo());
		FileRepositoryBuilder builder = new FileRepositoryBuilder();
		builder.addCeilingDirectory(gitDirectory);
		builder.findGitDir(gitDirectory);
		
		Git git;
		if (builder.getGitDir() == null) {
			git = Git.init().setDirectory(gitDirectory.getParentFile()).call();
		} else {
			git = new Git(builder.build());
		}
		return git;
	}
}
<commit_msg>when a repo does not exist clone it instead of init one.<commit_after>package com.khoubyari.example.git;

import java.io.File;
import java.io.IOException;

import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.InvalidRemoteException;
import org.eclipse.jgit.api.errors.TransportException;
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
import org.eclipse.jgit.transport.FetchResult;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.slf4j.Logger;



public class GitManager {

	@Autowired
	private RepositoryProperties repositoryProperties;
	
	private static final Logger log = LoggerFactory.getLogger(GitManager.class);

	public GitManager() {

	}

	public void updateLocalRepository() {
		Git git = null;
		try {
		    git = openRepository();
			FetchResult result = git.fetch().setCheckFetchedObjects(true).call();
			log.debug("The result of fetching the repo:" + result);
		}
		catch(IOException | IllegalStateException | GitAPIException ex) {
			log.error("An exception occured while updating the local repo:", ex);
		}
		finally {
			if(git != null && git.getRepository() != null) {
				// workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=474093
				git.getRepository().close();
			}
		}
	}
	
	private Git openRepository() throws IOException, IllegalStateException, GitAPIException {
		File gitDirectory = new File(repositoryProperties.getLocalRepo());
		FileRepositoryBuilder builder = new FileRepositoryBuilder();
		builder.addCeilingDirectory(gitDirectory);
		builder.findGitDir(gitDirectory);
		
		Git git;
		if (builder.getGitDir() == null) {
			git = cloneRepository(gitDirectory);
		} else {
			git = new Git(builder.build());
		}
		return git;
	}
	
	private Git cloneRepository(File gitDirectory) throws InvalidRemoteException, TransportException, GitAPIException {
		gitDirectory.delete();
       
       log.debug("Cloning from " + repositoryProperties.getRemoteRepo() + " to " + gitDirectory);
        try (Git result = Git.cloneRepository()
                .setURI(repositoryProperties.getRemoteRepo())
                .setDirectory(gitDirectory)
                .call()) {
	        // Note: the call() returns an opened repository already which needs to be closed to avoid file handle leaks!
	        log.debug("Having repository: " + result.getRepository().getDirectory());
	        return result;
        }

	}
}

{'fraction_non_alphanumeric': 0.10842158345940495, 'fraction_numerical': 0.0025214321734745334, 'mean_word_length': 4.35357624831309, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, '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': '252640', 'n_tokens_mistral': 1228, 'n_tokens_neox': 1117, 'n_words': 260}