Use no-op filter as default for lfs

This commit is contained in:
Rene Pfeuffer
2019-10-07 18:45:12 +02:00
parent a1da5eaddb
commit 24e18b4414
4 changed files with 101 additions and 33 deletions

View File

@@ -38,25 +38,8 @@ public class GitModifyCommand_LFSTest extends AbstractGitCommandTestBase {
@Test
public void shouldCreateCommit() throws IOException, GitAPIException {
BlobStore blobStore = mock(BlobStore.class);
Blob blob = mock(Blob.class);
when(lfsBlobStoreFactory.getLfsBlobStore(any())).thenReturn(blobStore);
when(blobStore.create("fe32608c9ef5b6cf7e3f946480253ff76f24f4ec0678f3d0f07f9844cbff9601")).thenReturn(blob);
when(blobStore.get("fe32608c9ef5b6cf7e3f946480253ff76f24f4ec0678f3d0f07f9844cbff9601")).thenReturn(null, blob);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
when(blob.getOutputStream()).thenReturn(outputStream);
when(blob.getSize()).thenReturn((long) "new content".length());
File newFile = Files.write(temporaryFolder.newFile().toPath(), "new content".getBytes()).toFile();
GitModifyCommand command = createCommand();
ModifyCommandRequest request = new ModifyCommandRequest();
request.setCommitMessage("test commit");
request.addRequest(new ModifyCommandRequest.CreateFileRequest("new_lfs.png", newFile, false));
request.setAuthor(new Person("Dirk Gently", "dirk@holistic.det"));
String newRef = command.execute(request);
String newRef = createCommit("new_lfs.png", "new content", "fe32608c9ef5b6cf7e3f946480253ff76f24f4ec0678f3d0f07f9844cbff9601", outputStream);
try (Git git = new Git(createContext().open())) {
RevCommit lastCommit = getLastCommit(git);
@@ -68,6 +51,45 @@ public class GitModifyCommand_LFSTest extends AbstractGitCommandTestBase {
assertThat(outputStream.toString()).isEqualTo("new content");
}
@Test
public void shouldCreateSecondCommits() throws IOException, GitAPIException {
new GitLfsFilterModule().configure(null);
createCommit("new_lfs.png", "new content", "fe32608c9ef5b6cf7e3f946480253ff76f24f4ec0678f3d0f07f9844cbff9601", new ByteArrayOutputStream());
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
String newRef = createCommit("more_lfs.png", "more content", "2c2316737c9313956dfc0083da3a2a62ce259f66484f3e26440f0d1b02dd4128", outputStream);
try (Git git = new Git(createContext().open())) {
RevCommit lastCommit = getLastCommit(git);
assertThat(lastCommit.getFullMessage()).isEqualTo("test commit");
assertThat(lastCommit.getAuthorIdent().getName()).isEqualTo("Dirk Gently");
assertThat(newRef).isEqualTo(lastCommit.toObjectId().name());
}
assertThat(outputStream.toString()).isEqualTo("more content");
}
private String createCommit(String fileName, String content, String hashOfContent, ByteArrayOutputStream outputStream) throws IOException {
BlobStore blobStore = mock(BlobStore.class);
Blob blob = mock(Blob.class);
when(lfsBlobStoreFactory.getLfsBlobStore(any())).thenReturn(blobStore);
when(blobStore.create(hashOfContent)).thenReturn(blob);
when(blobStore.get(hashOfContent)).thenReturn(null, blob);
when(blob.getOutputStream()).thenReturn(outputStream);
when(blob.getSize()).thenReturn((long) content.length());
File newFile = Files.write(temporaryFolder.newFile().toPath(), content.getBytes()).toFile();
GitModifyCommand command = createCommand();
ModifyCommandRequest request = new ModifyCommandRequest();
request.setCommitMessage("test commit");
request.addRequest(new ModifyCommandRequest.CreateFileRequest(fileName, newFile, false));
request.setAuthor(new Person("Dirk Gently", "dirk@holistic.det"));
return command.execute(request);
}
private RevCommit getLastCommit(Git git) throws GitAPIException {
return git.log().setMaxCount(1).call().iterator().next();
}