Преглед изворни кода

Fix issue with pulling 2 new identical binary files with known name

Winston Li пре 11 година
родитељ
комит
70c963c38f
12 измењених фајлова са 167 додато и 4 уклоњено
  1. 6 4
      services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/data/model/ResourceFetcher.java
  2. 27 0
      services/git-bridge/src/test/java/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest.java
  3. 50 0
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullUpdatedBinaryFiles/base/state.json
  4. 1 0
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullUpdatedBinaryFiles/base/testproj/main.tex
  5. BIN
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullUpdatedBinaryFiles/base/testproj/overleaf-white-410-copy.png
  6. BIN
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullUpdatedBinaryFiles/base/testproj/overleaf-white-410.png
  7. 1 0
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullUpdatedBinaryFiles/base/testproj/test.tex
  8. 80 0
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullUpdatedBinaryFiles/withUpdatedBinaryFiles/state.json
  9. 1 0
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullUpdatedBinaryFiles/withUpdatedBinaryFiles/testproj/main.tex
  10. BIN
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullUpdatedBinaryFiles/withUpdatedBinaryFiles/testproj/overleaf-white-410-copy.png
  11. BIN
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullUpdatedBinaryFiles/withUpdatedBinaryFiles/testproj/overleaf-white-410.png
  12. 1 0
      services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullUpdatedBinaryFiles/withUpdatedBinaryFiles/testproj/test.tex

+ 6 - 4
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);

+ 27 - 0
services/git-bridge/src/test/java/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest.java

@@ -63,6 +63,10 @@ public class WLGitBridgeIntegrationTest {
                 put("canCloneDuplicateBinaryFiles", new HashMap<String, SnapshotAPIState>() {{
                     put("state", new SnapshotAPIStateBuilder(getResourceAsStream("/canCloneDuplicateBinaryFiles/state/state.json")).build());
                 }});
+                put("canPullUpdatedBinaryFiles", new HashMap<String, SnapshotAPIState>() {{
+                    put("base", new SnapshotAPIStateBuilder(getResourceAsStream("/canPullUpdatedBinaryFiles/base/state.json")).build());
+                    put("withUpdatedBinaryFiles", new SnapshotAPIStateBuilder(getResourceAsStream("/canPullUpdatedBinaryFiles/withUpdatedBinaryFiles/state.json")).build());
+                }});
                 put("canPullAModifiedNestedFile", new HashMap<String, SnapshotAPIState>() {{
                     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());

+ 50 - 0
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
+		}
+	}
+]

+ 1 - 0
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullUpdatedBinaryFiles/base/testproj/main.tex

@@ -0,0 +1 @@
+content

BIN
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullUpdatedBinaryFiles/base/testproj/overleaf-white-410-copy.png


BIN
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullUpdatedBinaryFiles/base/testproj/overleaf-white-410.png


+ 1 - 0
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.

+ 80 - 0
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
+		}
+	}
+]

+ 1 - 0
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullUpdatedBinaryFiles/withUpdatedBinaryFiles/testproj/main.tex

@@ -0,0 +1 @@
+content

BIN
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullUpdatedBinaryFiles/withUpdatedBinaryFiles/testproj/overleaf-white-410-copy.png


BIN
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullUpdatedBinaryFiles/withUpdatedBinaryFiles/testproj/overleaf-white-410.png


+ 1 - 0
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.