diff --git a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/bridge/WLBridgedProject.java b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/bridge/WLBridgedProject.java
index d91af8a4fb..541eeea84d 100644
--- a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/bridge/WLBridgedProject.java
+++ b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/bridge/WLBridgedProject.java
@@ -49,6 +49,9 @@ public class WLBridgedProject {
for (WritableRepositoryContents contents : writableRepositories) {
contents.write();
Git git = new Git(repository);
+ for (String missing : git.status().call().getMissing()) {
+ git.rm().setCached(true).addFilepattern(missing).call();
+ }
git.add().addFilepattern(".").call();
git.commit().setAuthor(new PersonIdent(contents.getUserName(), contents.getUserEmail(), contents.getWhen(), TimeZone.getDefault()))
.setMessage(contents.getCommitMessage())
diff --git a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/test/util/FileUtil.java b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/test/util/FileUtil.java
index d093f9416d..93acf0ba26 100644
--- a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/test/util/FileUtil.java
+++ b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/test/util/FileUtil.java
@@ -34,8 +34,8 @@ public class FileUtil {
}
public static boolean gitDirectoriesAreEqual(Path dir1, Path dir2) {
- Set dir1Contents = getAllFilesRecursivelyInDirectoryApartFrom(dir1, dir1.resolve(".git"));
- Set dir2Contents = getAllFilesRecursivelyInDirectoryApartFrom(dir2, dir2.resolve(".git"));
+ Set dir1Contents = getAllRecursivelyInDirectoryApartFrom(dir1, dir1.resolve(".git"));
+ Set dir2Contents = getAllRecursivelyInDirectoryApartFrom(dir2, dir2.resolve(".git"));
boolean filesEqual = dir1Contents.equals(dir2Contents);
if (!filesEqual) {
System.out.println("Not equal: (" + dir1Contents + ", " + dir2Contents + ")");
@@ -72,20 +72,31 @@ public class FileUtil {
}
}
- public static Set getAllFilesRecursivelyInDirectoryApartFrom(Path dir, Path excluded) {
+ public static Set getAllRecursivelyInDirectoryApartFrom(Path dir, Path excluded) {
+ return getAllRecursivelyInDirectoryApartFrom(dir, excluded, true);
+ }
+
+ public static Set getOnlyFilesRecursivelyInDirectoryApartFrom(Path dir, Path excluded) {
+ return getAllRecursivelyInDirectoryApartFrom(dir, excluded, false);
+ }
+
+ private static Set getAllRecursivelyInDirectoryApartFrom(Path dir, Path excluded, boolean directories) {
if (!dir.toFile().isDirectory()) {
throw new IllegalArgumentException("need a directory");
}
- return getAllFilesRecursively(dir, dir, excluded);
+ return getAllFilesRecursively(dir, dir, excluded, directories);
}
- static Set getAllFilesRecursively(Path baseDir, Path dir, Path excluded) {
+ static Set getAllFilesRecursively(Path baseDir, Path dir, Path excluded, boolean directories) {
Set files = new HashSet();
for (File file : dir.toFile().listFiles()) {
if (!file.equals(excluded.toFile())) {
- files.add(baseDir.relativize(file.toPath()).toString());
- if (file.isDirectory()) {
- files.addAll(getAllFilesRecursively(baseDir, file.toPath(), excluded));
+ boolean isDirectory = file.isDirectory();
+ if (directories || !isDirectory) {
+ files.add(baseDir.relativize(file.toPath()).toString());
+ }
+ if (isDirectory) {
+ files.addAll(getAllFilesRecursively(baseDir, file.toPath(), excluded, directories));
}
}
}
diff --git a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/writelatex/filestore/GitDirectoryContents.java b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/writelatex/filestore/GitDirectoryContents.java
index 23372ca9d8..0004f9a75f 100644
--- a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/writelatex/filestore/GitDirectoryContents.java
+++ b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/writelatex/filestore/GitDirectoryContents.java
@@ -36,6 +36,7 @@ public class GitDirectoryContents implements WritableRepositoryContents {
public void write() throws IOException, FailedConnectionException {
WLFileStore.deleteInDirectoryApartFrom(gitDirectory, ".git");
for (FileNode fileNode : fileNodes) {
+ System.out.println("Writing: " + fileNode.getFilePath());
fileNode.writeToDisk(gitDirectory);
}
}
diff --git a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/writelatex/filestore/store/WLFileStore.java b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/writelatex/filestore/store/WLFileStore.java
index 60865185f4..5746bedb1c 100644
--- a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/writelatex/filestore/store/WLFileStore.java
+++ b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/writelatex/filestore/store/WLFileStore.java
@@ -58,6 +58,7 @@ public class WLFileStore implements PersistentStoreSource {
if (file.isDirectory()) {
deleteInDirectory(file);
}
+ System.out.println("deleting: " + file.getAbsolutePath());
file.delete();
}
}
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 e908ca78a9..41ba162366 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
@@ -36,6 +36,10 @@ public class WLGitBridgeIntegrationTest {
put("base", new SnapshotAPIStateBuilder(getResourceAsStream("/canPullAModifiedTexFile/base/state.json")).build());
put("withModifiedTexFile", new SnapshotAPIStateBuilder(getResourceAsStream("/canPullAModifiedTexFile/withModifiedTexFile/state.json")).build());
}});
+ put("canPullADeletedTexFile", new HashMap() {{
+ put("base", new SnapshotAPIStateBuilder(getResourceAsStream("/canPullADeletedTexFile/base/state.json")).build());
+ put("withDeletedTexFile", new SnapshotAPIStateBuilder(getResourceAsStream("/canPullADeletedTexFile/withDeletedTexFile/state.json")).build());
+ }});
}};
@Rule
@@ -111,6 +115,29 @@ public class WLGitBridgeIntegrationTest {
assertTrue(FileUtil.gitDirectoriesAreEqual(getResource("/canPullAModifiedTexFile/withModifiedTexFile/testproj"), git.toPath()));
}
+ @Test
+ public void canPullADeletedTexFile() throws IOException, GitAPIException {
+ MockSnapshotServer server = new MockSnapshotServer(3860, getResource("/canPullADeletedTexFile").toFile());
+ server.start();
+ server.setState(states.get("canPullADeletedTexFile").get("base"));
+ WLGitBridgeApplication wlgb = new WLGitBridgeApplication(new String[] {
+ makeConfigFile(33860, 3860)
+ });
+ wlgb.run();
+ folder.create();
+ File git = folder.newFolder();
+ Git base = Git.cloneRepository()
+ .setURI("http://127.0.0.1:33860/testproj.git")
+ .setDirectory(git)
+ .call();
+ assertTrue(FileUtil.gitDirectoriesAreEqual(getResource("/canPullADeletedTexFile/base/testproj"), git.toPath()));
+ server.setState(states.get("canPullADeletedTexFile").get("withDeletedTexFile"));
+ base.pull().call();
+ base.close();
+ wlgb.stop();
+ assertTrue(FileUtil.gitDirectoriesAreEqual(getResource("/canPullADeletedTexFile/withDeletedTexFile/testproj"), git.toPath()));
+ }
+
private String makeConfigFile(int port, int apiPort) throws IOException {
File wlgb = folder.newFolder();
File config = folder.newFile();
diff --git a/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullADeletedTexFile/base/state.json b/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullADeletedTexFile/base/state.json
new file mode 100644
index 0000000000..65f186f256
--- /dev/null
+++ b/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullADeletedTexFile/base/state.json
@@ -0,0 +1,46 @@
+[
+ {
+ "project": "testproj",
+ "getDoc": {
+ "versionID": 1,
+ "createdAt": "2014-11-30T18:40:58Z",
+ "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:01Z"
+ }
+ ],
+ "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:3860/base/testproj/overleaf-white-410.png",
+ "path": "overleaf-white-410.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/canPullADeletedTexFile/base/testproj/main.tex b/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullADeletedTexFile/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/canPullADeletedTexFile/base/testproj/main.tex
@@ -0,0 +1 @@
+content
diff --git a/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullADeletedTexFile/base/testproj/overleaf-white-410.png b/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullADeletedTexFile/base/testproj/overleaf-white-410.png
new file mode 100644
index 0000000000..be0315abbb
--- /dev/null
+++ b/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullADeletedTexFile/base/testproj/overleaf-white-410.png
@@ -0,0 +1,12 @@
+
+
+
+Error 404
+
+
+HTTP ERROR: 404
+Problem accessing /state/testproj1/overleaf-white-410.png. Reason:
+
Not Found
+
Powered by Jetty://
+
+
diff --git a/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullADeletedTexFile/base/testproj/test.tex b/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullADeletedTexFile/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/canPullADeletedTexFile/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/canPullADeletedTexFile/withDeletedTexFile/state.json b/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullADeletedTexFile/withDeletedTexFile/state.json
new file mode 100644
index 0000000000..7bd4d5384d
--- /dev/null
+++ b/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullADeletedTexFile/withDeletedTexFile/state.json
@@ -0,0 +1,68 @@
+[
+ {
+ "project": "testproj",
+ "getDoc": {
+ "versionID": 2,
+ "createdAt": "2014-11-30T18:40:58Z",
+ "email": "jdleesmiller+1@gmail.com",
+ "name": "John+1"
+ },
+ "getSavedVers": [
+ {
+ "versionID": 2,
+ "comment": "i deleted test.tex",
+ "email": "jdleesmiller+1@gmail.com",
+ "name": "John+1",
+ "createdAt": "2014-11-30T18:48:01Z"
+ },
+ {
+ "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:01Z"
+ }
+ ],
+ "getForVers": [
+ {
+ "versionID": 2,
+ "srcs": [
+ {
+ "content": "content\nadded more stuff\n",
+ "path": "main.tex"
+ }
+ ],
+ "atts": [
+ {
+ "url": "http://127.0.0.1:3860/withDeletedTexFile/testproj/overleaf-white-410.png",
+ "path": "overleaf-white-410.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:3860/base/testproj/overleaf-white-410.png",
+ "path": "overleaf-white-410.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/canPullADeletedTexFile/withDeletedTexFile/testproj/main.tex b/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullADeletedTexFile/withDeletedTexFile/testproj/main.tex
new file mode 100644
index 0000000000..933682f779
--- /dev/null
+++ b/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullADeletedTexFile/withDeletedTexFile/testproj/main.tex
@@ -0,0 +1,2 @@
+content
+added more stuff
diff --git a/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullADeletedTexFile/withDeletedTexFile/testproj/overleaf-white-410.png b/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullADeletedTexFile/withDeletedTexFile/testproj/overleaf-white-410.png
new file mode 100644
index 0000000000..be0315abbb
--- /dev/null
+++ b/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPullADeletedTexFile/withDeletedTexFile/testproj/overleaf-white-410.png
@@ -0,0 +1,12 @@
+
+
+
+Error 404
+
+
+HTTP ERROR: 404
+Problem accessing /state/testproj1/overleaf-white-410.png. Reason:
+
Not Found
+
Powered by Jetty://
+
+