diff --git a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/data/model/ResourceFetcher.java b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/data/model/ResourceFetcher.java index e3f1115651..4bc0c277d9 100644 --- a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/data/model/ResourceFetcher.java +++ b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/data/model/ResourceFetcher.java @@ -38,11 +38,13 @@ public class ResourceFetcher { } else { Util.sout("Found (" + projectName + "): " + url); Util.sout("At (" + projectName + "): " + path); - RawFile rawFile = new RepositoryObjectTreeWalker(repository).getDirectoryContents().getFileTable().get(path); - if (rawFile != null) { + contents = fetchedUrls.get(url); + if (contents == null) { + RawFile rawFile = new RepositoryObjectTreeWalker(repository).getDirectoryContents().getFileTable().get(path); + if (rawFile == null) { + throw new IllegalStateException("file was not in the current commit, or the git tree, yet path was not null"); + } contents = rawFile.getContents(); - } else { - contents = fetchedUrls.get(url); } } return new RepositoryFile(newPath, contents); diff --git a/services/git-bridge/src/test/java/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest.java b/services/git-bridge/src/test/java/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest.java index b47f7fba33..73097658ff 100644 --- a/services/git-bridge/src/test/java/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest.java +++ b/services/git-bridge/src/test/java/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest.java @@ -63,6 +63,10 @@ public class WLGitBridgeIntegrationTest { put("canCloneDuplicateBinaryFiles", new HashMap() {{ put("state", new SnapshotAPIStateBuilder(getResourceAsStream("/canCloneDuplicateBinaryFiles/state/state.json")).build()); }}); + put("canPullUpdatedBinaryFiles", new HashMap() {{ + put("base", new SnapshotAPIStateBuilder(getResourceAsStream("/canPullUpdatedBinaryFiles/base/state.json")).build()); + put("withUpdatedBinaryFiles", new SnapshotAPIStateBuilder(getResourceAsStream("/canPullUpdatedBinaryFiles/withUpdatedBinaryFiles/state.json")).build()); + }}); put("canPullAModifiedNestedFile", new HashMap() {{ put("base", new SnapshotAPIStateBuilder(getResourceAsStream("/canPullAModifiedNestedFile/base/state.json")).build()); put("withModifiedNestedFile", new SnapshotAPIStateBuilder(getResourceAsStream("/canPullAModifiedNestedFile/withModifiedNestedFile/state.json")).build()); @@ -294,6 +298,29 @@ public class WLGitBridgeIntegrationTest { assertTrue(FileUtil.gitDirectoriesAreEqual(getResource("/canCloneDuplicateBinaryFiles/state/testproj"), testprojDir.toPath())); } + @Test + public void canPullUpdatedBinaryFiles() throws IOException, GitAPIException, InterruptedException { + MockSnapshotServer server = new MockSnapshotServer(4003, getResource("/canPullUpdatedBinaryFiles").toFile()); + server.start(); + server.setState(states.get("canPullUpdatedBinaryFiles").get("base")); + GitBridgeApp wlgb = new GitBridgeApp(new String[] { + makeConfigFile(44003, 4003) + }); + wlgb.run(); + File dir = folder.newFolder(); + Process gitBase = runtime.exec("git clone http://127.0.0.1:44003/testproj.git", null, dir); + int exitCodeBase = gitBase.waitFor(); + File testprojDir = new File(dir, "testproj"); + assertEquals(0, exitCodeBase); + assertTrue(FileUtil.gitDirectoriesAreEqual(getResource("/canPullUpdatedBinaryFiles/base/testproj"), testprojDir.toPath())); + server.setState(states.get("canPullUpdatedBinaryFiles").get("withUpdatedBinaryFiles")); + Process gitWithDeletedBinaryFile = runtime.exec("git pull", null, testprojDir); + int exitCodeWithDeletedBinaryFile = gitWithDeletedBinaryFile.waitFor(); + wlgb.stop(); + assertEquals(0, exitCodeWithDeletedBinaryFile); + assertTrue(FileUtil.gitDirectoriesAreEqual(getResource("/canPullUpdatedBinaryFiles/withUpdatedBinaryFiles/testproj"), testprojDir.toPath())); + } + @Test public void canPullAModifiedNestedFile() throws IOException, GitAPIException, InterruptedException { MockSnapshotServer server = new MockSnapshotServer(3864, getResource("/canPullAModifiedNestedFile").toFile()); diff --git a/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullUpdatedBinaryFiles/base/state.json b/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullUpdatedBinaryFiles/base/state.json new file mode 100644 index 0000000000..ea08b73617 --- /dev/null +++ b/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullUpdatedBinaryFiles/base/state.json @@ -0,0 +1,50 @@ +[ + { + "project": "testproj", + "getDoc": { + "versionID": 1, + "createdAt": "2014-11-30T18:40:58.123Z", + "email": "jdleesmiller+1@gmail.com", + "name": "John+1" + }, + "getSavedVers": [ + { + "versionID": 1, + "comment": "added more info on doc GET and error details", + "email": "jdleesmiller+1@gmail.com", + "name": "John+1", + "createdAt": "2014-11-30T18:47:01.456Z" + } + ], + "getForVers": [ + { + "versionID": 1, + "srcs": [ + { + "content": "content\n", + "path": "main.tex" + }, + { + "content": "This text is from another file.", + "path": "test.tex" + } + ], + "atts": [ + { + "url": "http://127.0.0.1:4003/base/testproj/overleaf-white-410.png", + "path": "overleaf-white-410.png" + }, + { + "url": "http://127.0.0.1:4003/base/testproj/overleaf-white-410.png", + "path": "overleaf-white-410-copy.png" + } + ] + } + ], + "push": "success", + "postback": { + "type": "success", + "versionID": 2 + } + } +] \ No newline at end of file diff --git a/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullUpdatedBinaryFiles/base/testproj/main.tex b/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullUpdatedBinaryFiles/base/testproj/main.tex new file mode 100644 index 0000000000..d95f3ad14d --- /dev/null +++ b/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullUpdatedBinaryFiles/base/testproj/main.tex @@ -0,0 +1 @@ +content diff --git a/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullUpdatedBinaryFiles/base/testproj/overleaf-white-410-copy.png b/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullUpdatedBinaryFiles/base/testproj/overleaf-white-410-copy.png new file mode 100644 index 0000000000..6a23d10c15 Binary files /dev/null and b/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullUpdatedBinaryFiles/base/testproj/overleaf-white-410-copy.png differ diff --git a/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullUpdatedBinaryFiles/base/testproj/overleaf-white-410.png b/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullUpdatedBinaryFiles/base/testproj/overleaf-white-410.png new file mode 100644 index 0000000000..6a23d10c15 Binary files /dev/null and b/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullUpdatedBinaryFiles/base/testproj/overleaf-white-410.png differ diff --git a/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullUpdatedBinaryFiles/base/testproj/test.tex b/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullUpdatedBinaryFiles/base/testproj/test.tex new file mode 100644 index 0000000000..046794f19a --- /dev/null +++ b/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullUpdatedBinaryFiles/base/testproj/test.tex @@ -0,0 +1 @@ +This text is from another file. \ No newline at end of file diff --git a/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullUpdatedBinaryFiles/withUpdatedBinaryFiles/state.json b/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullUpdatedBinaryFiles/withUpdatedBinaryFiles/state.json new file mode 100644 index 0000000000..8270c358fe --- /dev/null +++ b/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullUpdatedBinaryFiles/withUpdatedBinaryFiles/state.json @@ -0,0 +1,80 @@ +[ + { + "project": "testproj", + "getDoc": { + "versionID": 2, + "createdAt": "2014-11-30T18:40:58.123Z", + "email": "jdleesmiller+1@gmail.com", + "name": "John+1" + }, + "getSavedVers": [ + { + "versionID": 2, + "comment": "i deleted the image", + "email": "jdleesmiller+1@gmail.com", + "name": "John+1", + "createdAt": "2014-11-30T18:48:01.123Z" + }, + { + "versionID": 1, + "comment": "added more info on doc GET and error details", + "email": "jdleesmiller+1@gmail.com", + "name": "John+1", + "createdAt": "2014-11-30T18:47:01.456Z" + } + ], + "getForVers": [ + { + "versionID": 2, + "srcs": [ + { + "content": "content\n", + "path": "main.tex" + }, + { + "content": "This text is from another file.", + "path": "test.tex" + } + ], + "atts": [ + { + "url": "http://127.0.0.1:4003/withUpdatedBinaryFiles/testproj/overleaf-white-410.png", + "path": "overleaf-white-410.png" + }, + { + "url": "http://127.0.0.1:4003/withUpdatedBinaryFiles/testproj/overleaf-white-410.png", + "path": "overleaf-white-410-copy.png" + } + ] + }, + { + "versionID": 1, + "srcs": [ + { + "content": "content\n", + "path": "main.tex" + }, + { + "content": "This text is from another file.", + "path": "test.tex" + } + ], + "atts": [ + { + "url": "http://127.0.0.1:4003/base/testproj/overleaf-white-410.png", + "path": "overleaf-white-410.png" + }, + { + "url": "http://127.0.0.1:4003/base/testproj/overleaf-white-410.png", + "path": "overleaf-white-410-copy.png" + } + ] + } + ], + "push": "success", + "postback": { + "type": "success", + "versionID": 2 + } + } +] \ No newline at end of file diff --git a/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullUpdatedBinaryFiles/withUpdatedBinaryFiles/testproj/main.tex b/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullUpdatedBinaryFiles/withUpdatedBinaryFiles/testproj/main.tex new file mode 100644 index 0000000000..d95f3ad14d --- /dev/null +++ b/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullUpdatedBinaryFiles/withUpdatedBinaryFiles/testproj/main.tex @@ -0,0 +1 @@ +content diff --git a/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullUpdatedBinaryFiles/withUpdatedBinaryFiles/testproj/overleaf-white-410-copy.png b/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullUpdatedBinaryFiles/withUpdatedBinaryFiles/testproj/overleaf-white-410-copy.png new file mode 100644 index 0000000000..74e1fcd990 Binary files /dev/null and b/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullUpdatedBinaryFiles/withUpdatedBinaryFiles/testproj/overleaf-white-410-copy.png differ diff --git a/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullUpdatedBinaryFiles/withUpdatedBinaryFiles/testproj/overleaf-white-410.png b/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullUpdatedBinaryFiles/withUpdatedBinaryFiles/testproj/overleaf-white-410.png new file mode 100644 index 0000000000..74e1fcd990 Binary files /dev/null and b/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullUpdatedBinaryFiles/withUpdatedBinaryFiles/testproj/overleaf-white-410.png differ diff --git a/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullUpdatedBinaryFiles/withUpdatedBinaryFiles/testproj/test.tex b/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullUpdatedBinaryFiles/withUpdatedBinaryFiles/testproj/test.tex new file mode 100644 index 0000000000..046794f19a --- /dev/null +++ b/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullUpdatedBinaryFiles/withUpdatedBinaryFiles/testproj/test.tex @@ -0,0 +1 @@ +This text is from another file. \ No newline at end of file