Merge pull request #13124 from thingsboard/fix/gateway-dashboard-sync
Improve local repository opening
This commit is contained in:
commit
cb9fd0162e
@ -41,6 +41,8 @@ import org.eclipse.jgit.diff.HistogramDiff;
|
|||||||
import org.eclipse.jgit.diff.RawText;
|
import org.eclipse.jgit.diff.RawText;
|
||||||
import org.eclipse.jgit.diff.RawTextComparator;
|
import org.eclipse.jgit.diff.RawTextComparator;
|
||||||
import org.eclipse.jgit.errors.LargeObjectException;
|
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.Constants;
|
||||||
import org.eclipse.jgit.lib.ObjectId;
|
import org.eclipse.jgit.lib.ObjectId;
|
||||||
import org.eclipse.jgit.lib.ObjectLoader;
|
import org.eclipse.jgit.lib.ObjectLoader;
|
||||||
@ -147,23 +149,32 @@ public class GitRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static GitRepository openOrClone(Path directory, RepositorySettings settings, boolean fetch) throws IOException, GitAPIException {
|
public static GitRepository openOrClone(Path directory, RepositorySettings settings, boolean fetch) throws IOException, GitAPIException {
|
||||||
GitRepository repository;
|
|
||||||
if (GitRepository.exists(directory.toString())) {
|
if (GitRepository.exists(directory.toString())) {
|
||||||
repository = GitRepository.open(directory.toFile(), settings);
|
try {
|
||||||
|
GitRepository repository = GitRepository.open(directory.toFile(), settings);
|
||||||
if (fetch) {
|
if (fetch) {
|
||||||
repository.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 {
|
} else {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
FileUtils.deleteDirectory(directory.toFile());
|
FileUtils.deleteDirectory(directory.toFile());
|
||||||
Files.createDirectories(directory);
|
Files.createDirectories(directory);
|
||||||
if (settings.isLocalOnly()) {
|
if (settings.isLocalOnly()) {
|
||||||
repository = GitRepository.create(settings, directory.toFile());
|
return GitRepository.create(settings, directory.toFile());
|
||||||
} else {
|
} 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 {
|
public static void test(RepositorySettings settings, File directory) throws Exception {
|
||||||
if (settings.isLocalOnly()) {
|
if (settings.isLocalOnly()) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user