|
|
|
@ -41,6 +41,8 @@ import org.eclipse.jgit.diff.HistogramDiff; |
|
|
|
import org.eclipse.jgit.diff.RawText; |
|
|
|
import org.eclipse.jgit.diff.RawTextComparator; |
|
|
|
import org.eclipse.jgit.errors.LargeObjectException; |
|
|
|
import org.eclipse.jgit.errors.RepositoryNotFoundException; |
|
|
|
import org.eclipse.jgit.errors.TransportException; |
|
|
|
import org.eclipse.jgit.lib.Constants; |
|
|
|
import org.eclipse.jgit.lib.ObjectId; |
|
|
|
import org.eclipse.jgit.lib.ObjectLoader; |
|
|
|
@ -147,22 +149,31 @@ public class GitRepository { |
|
|
|
} |
|
|
|
|
|
|
|
public static GitRepository openOrClone(Path directory, RepositorySettings settings, boolean fetch) throws IOException, GitAPIException { |
|
|
|
GitRepository repository; |
|
|
|
if (GitRepository.exists(directory.toString())) { |
|
|
|
repository = GitRepository.open(directory.toFile(), settings); |
|
|
|
if (fetch) { |
|
|
|
repository.fetch(); |
|
|
|
try { |
|
|
|
GitRepository repository = GitRepository.open(directory.toFile(), settings); |
|
|
|
if (fetch) { |
|
|
|
repository.fetch(); |
|
|
|
} |
|
|
|
return repository; |
|
|
|
} catch (RepositoryNotFoundException e) { |
|
|
|
log.warn("{} not a git repository, reinitializing", directory); |
|
|
|
} catch (TransportException e) { |
|
|
|
if (StringUtils.containsIgnoreCase(e.getMessage(), "missing commit")) { |
|
|
|
log.warn("Couldn't fetch {} due to {}, reinitializing", directory, e.getMessage()); |
|
|
|
} else { |
|
|
|
throw e; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
FileUtils.deleteDirectory(directory.toFile()); |
|
|
|
Files.createDirectories(directory); |
|
|
|
if (settings.isLocalOnly()) { |
|
|
|
return GitRepository.create(settings, directory.toFile()); |
|
|
|
} else { |
|
|
|
FileUtils.deleteDirectory(directory.toFile()); |
|
|
|
Files.createDirectories(directory); |
|
|
|
if (settings.isLocalOnly()) { |
|
|
|
repository = GitRepository.create(settings, directory.toFile()); |
|
|
|
} else { |
|
|
|
repository = GitRepository.clone(settings, directory.toFile()); |
|
|
|
} |
|
|
|
return GitRepository.clone(settings, directory.toFile()); |
|
|
|
} |
|
|
|
return repository; |
|
|
|
} |
|
|
|
|
|
|
|
public static void test(RepositorySettings settings, File directory) throws Exception { |
|
|
|
|