@Test public void testPredefinedRepository() throws Exception { final var source = local().build(); assertThat(source).isNotNull(); assertThat(toString(source, path("data.txt"))).isEqualTo("One"); assertThat(toString(source, path("data.txt", "master", TAG))).isEqualTo("Three"); assertThat(source.load(path("nodata.txt", "develop"))).isNotNull(); assertThat(toString(source, path("data.txt", "develop", TAG))).isEqualTo("Four"); assertThat(toString(source, path("data.txt", "refs/tags/develop"))).isEqualTo("Four"); assertThat(toString(source, path("data.txt", "refs/heads/master"))).isEqualTo("One"); assertThat(toString(source, path("data.txt", "refs/tags/master"))).isEqualTo("Three"); assertThat(toString(source, path("data.txt", "954a68210f524228ed29a85e7b8574dd1577bf40"))).isEqualTo("Five"); assertThat(toString(source, path("data.txt", "tag-2"))).isEqualTo("Two"); assertThat(toString(source, path("data.txt", "refs/tags/tag-2"), 1570108694000L)).isEqualTo("Two"); assertThat(source.loadIfModified(path("data.txt", "refs/tags/tag-2"), new LastModified(1570108695000L))).isNull(); assertThrows(FileNotFoundException.class, () -> source.load(path("data.txt", "develop"))); assertThrows(IllegalArgumentException.class, () -> source.load(path("data.txt", "tag-3"))); }
@Override public LoadedResource loadIfModified(GitResourceId resourceId, SourceVersion version) { try { pull(); var refValue = mapIfRequired(resourceId.getRefValue()); var filter = CommitTimeRevFilter.after((long) version.val()); var logsCmd = git.log().all(); if (refValue.isHash()) { var objectId = getObjectId(resourceId.getRefValue()); logsCmd.add(objectId).setRevFilter(AndRevFilter.create(filter, exact(objectId))); } else { if (refValue.isTag()) { var ref = git.getRepository().findRef(refValue.getFullName()); var objectId = checkExists(refValue.getFullName(), ref != null ? ref.getPeeledObjectId() : null); logsCmd.setRevFilter(AndRevFilter.create(filter, exact(objectId))); } else { logsCmd.addPath(resourceId.getFilePath()).setRevFilter(filter); } } for (var commit : logsCmd.call()) { if (refValue.isBranchType()) { var branches = git.branchList() .setListMode(ListBranchCommand.ListMode.ALL) .setContains(commit.getId().name()) .call(); for (var branchRefValue : branches) { var branchRef = new GitRef(branchRefValue.getName()); if (refValue.isConnectedWith(branchRef)) { return loadFromCommit(resourceId, commit); } } } else { return loadFromCommit(resourceId, commit); } } if (version.equals(EMPTY)) { throw new FileNotFoundException(format("No file [%s] found for ref %s", resourceId.getFilePath(), resourceId.getRefValue())); } else { return null; } } catch (Throwable t) { throw Exceptions.wrap(t); } }
GitSource extends AbstractSource<GitResourceId> implements NonListenableSource<GitResourceId> { @Override public LoadedResource loadIfModified(GitResourceId resourceId, SourceVersion version) { try { pull(); var refValue = mapIfRequired(resourceId.getRefValue()); var filter = CommitTimeRevFilter.after((long) version.val()); var logsCmd = git.log().all(); if (refValue.isHash()) { var objectId = getObjectId(resourceId.getRefValue()); logsCmd.add(objectId).setRevFilter(AndRevFilter.create(filter, exact(objectId))); } else { if (refValue.isTag()) { var ref = git.getRepository().findRef(refValue.getFullName()); var objectId = checkExists(refValue.getFullName(), ref != null ? ref.getPeeledObjectId() : null); logsCmd.setRevFilter(AndRevFilter.create(filter, exact(objectId))); } else { logsCmd.addPath(resourceId.getFilePath()).setRevFilter(filter); } } for (var commit : logsCmd.call()) { if (refValue.isBranchType()) { var branches = git.branchList() .setListMode(ListBranchCommand.ListMode.ALL) .setContains(commit.getId().name()) .call(); for (var branchRefValue : branches) { var branchRef = new GitRef(branchRefValue.getName()); if (refValue.isConnectedWith(branchRef)) { return loadFromCommit(resourceId, commit); } } } else { return loadFromCommit(resourceId, commit); } } if (version.equals(EMPTY)) { throw new FileNotFoundException(format("No file [%s] found for ref %s", resourceId.getFilePath(), resourceId.getRefValue())); } else { return null; } } catch (Throwable t) { throw Exceptions.wrap(t); } } }
GitSource extends AbstractSource<GitResourceId> implements NonListenableSource<GitResourceId> { @Override public LoadedResource loadIfModified(GitResourceId resourceId, SourceVersion version) { try { pull(); var refValue = mapIfRequired(resourceId.getRefValue()); var filter = CommitTimeRevFilter.after((long) version.val()); var logsCmd = git.log().all(); if (refValue.isHash()) { var objectId = getObjectId(resourceId.getRefValue()); logsCmd.add(objectId).setRevFilter(AndRevFilter.create(filter, exact(objectId))); } else { if (refValue.isTag()) { var ref = git.getRepository().findRef(refValue.getFullName()); var objectId = checkExists(refValue.getFullName(), ref != null ? ref.getPeeledObjectId() : null); logsCmd.setRevFilter(AndRevFilter.create(filter, exact(objectId))); } else { logsCmd.addPath(resourceId.getFilePath()).setRevFilter(filter); } } for (var commit : logsCmd.call()) { if (refValue.isBranchType()) { var branches = git.branchList() .setListMode(ListBranchCommand.ListMode.ALL) .setContains(commit.getId().name()) .call(); for (var branchRefValue : branches) { var branchRef = new GitRef(branchRefValue.getName()); if (refValue.isConnectedWith(branchRef)) { return loadFromCommit(resourceId, commit); } } } else { return loadFromCommit(resourceId, commit); } } if (version.equals(EMPTY)) { throw new FileNotFoundException(format("No file [%s] found for ref %s", resourceId.getFilePath(), resourceId.getRefValue())); } else { return null; } } catch (Throwable t) { throw Exceptions.wrap(t); } } GitSource(Git git, TransportConfigCallback transportConfig, boolean asyncPull); }
GitSource extends AbstractSource<GitResourceId> implements NonListenableSource<GitResourceId> { @Override public LoadedResource loadIfModified(GitResourceId resourceId, SourceVersion version) { try { pull(); var refValue = mapIfRequired(resourceId.getRefValue()); var filter = CommitTimeRevFilter.after((long) version.val()); var logsCmd = git.log().all(); if (refValue.isHash()) { var objectId = getObjectId(resourceId.getRefValue()); logsCmd.add(objectId).setRevFilter(AndRevFilter.create(filter, exact(objectId))); } else { if (refValue.isTag()) { var ref = git.getRepository().findRef(refValue.getFullName()); var objectId = checkExists(refValue.getFullName(), ref != null ? ref.getPeeledObjectId() : null); logsCmd.setRevFilter(AndRevFilter.create(filter, exact(objectId))); } else { logsCmd.addPath(resourceId.getFilePath()).setRevFilter(filter); } } for (var commit : logsCmd.call()) { if (refValue.isBranchType()) { var branches = git.branchList() .setListMode(ListBranchCommand.ListMode.ALL) .setContains(commit.getId().name()) .call(); for (var branchRefValue : branches) { var branchRef = new GitRef(branchRefValue.getName()); if (refValue.isConnectedWith(branchRef)) { return loadFromCommit(resourceId, commit); } } } else { return loadFromCommit(resourceId, commit); } } if (version.equals(EMPTY)) { throw new FileNotFoundException(format("No file [%s] found for ref %s", resourceId.getFilePath(), resourceId.getRefValue())); } else { return null; } } catch (Throwable t) { throw Exceptions.wrap(t); } } GitSource(Git git, TransportConfigCallback transportConfig, boolean asyncPull); @Override LoadedResource loadIfModified(GitResourceId resourceId, SourceVersion version); ObjectId getObjectId(GitRef refValue); @Override String describe(); @Override SourceVersion emptyVersion(); }
GitSource extends AbstractSource<GitResourceId> implements NonListenableSource<GitResourceId> { @Override public LoadedResource loadIfModified(GitResourceId resourceId, SourceVersion version) { try { pull(); var refValue = mapIfRequired(resourceId.getRefValue()); var filter = CommitTimeRevFilter.after((long) version.val()); var logsCmd = git.log().all(); if (refValue.isHash()) { var objectId = getObjectId(resourceId.getRefValue()); logsCmd.add(objectId).setRevFilter(AndRevFilter.create(filter, exact(objectId))); } else { if (refValue.isTag()) { var ref = git.getRepository().findRef(refValue.getFullName()); var objectId = checkExists(refValue.getFullName(), ref != null ? ref.getPeeledObjectId() : null); logsCmd.setRevFilter(AndRevFilter.create(filter, exact(objectId))); } else { logsCmd.addPath(resourceId.getFilePath()).setRevFilter(filter); } } for (var commit : logsCmd.call()) { if (refValue.isBranchType()) { var branches = git.branchList() .setListMode(ListBranchCommand.ListMode.ALL) .setContains(commit.getId().name()) .call(); for (var branchRefValue : branches) { var branchRef = new GitRef(branchRefValue.getName()); if (refValue.isConnectedWith(branchRef)) { return loadFromCommit(resourceId, commit); } } } else { return loadFromCommit(resourceId, commit); } } if (version.equals(EMPTY)) { throw new FileNotFoundException(format("No file [%s] found for ref %s", resourceId.getFilePath(), resourceId.getRefValue())); } else { return null; } } catch (Throwable t) { throw Exceptions.wrap(t); } } GitSource(Git git, TransportConfigCallback transportConfig, boolean asyncPull); @Override LoadedResource loadIfModified(GitResourceId resourceId, SourceVersion version); ObjectId getObjectId(GitRef refValue); @Override String describe(); @Override SourceVersion emptyVersion(); static final TransportConfigCallback EMPTY_TRANSPORT_CONFIG; }