mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Fixed bug with git not adding deleted files.
This commit is contained in:
parent
d4613864c0
commit
e124a74c2f
12 changed files with 193 additions and 8 deletions
|
@ -49,6 +49,9 @@ public class WLBridgedProject {
|
||||||
for (WritableRepositoryContents contents : writableRepositories) {
|
for (WritableRepositoryContents contents : writableRepositories) {
|
||||||
contents.write();
|
contents.write();
|
||||||
Git git = new Git(repository);
|
Git git = new Git(repository);
|
||||||
|
for (String missing : git.status().call().getMissing()) {
|
||||||
|
git.rm().setCached(true).addFilepattern(missing).call();
|
||||||
|
}
|
||||||
git.add().addFilepattern(".").call();
|
git.add().addFilepattern(".").call();
|
||||||
git.commit().setAuthor(new PersonIdent(contents.getUserName(), contents.getUserEmail(), contents.getWhen(), TimeZone.getDefault()))
|
git.commit().setAuthor(new PersonIdent(contents.getUserName(), contents.getUserEmail(), contents.getWhen(), TimeZone.getDefault()))
|
||||||
.setMessage(contents.getCommitMessage())
|
.setMessage(contents.getCommitMessage())
|
||||||
|
|
|
@ -34,8 +34,8 @@ public class FileUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean gitDirectoriesAreEqual(Path dir1, Path dir2) {
|
public static boolean gitDirectoriesAreEqual(Path dir1, Path dir2) {
|
||||||
Set<String> dir1Contents = getAllFilesRecursivelyInDirectoryApartFrom(dir1, dir1.resolve(".git"));
|
Set<String> dir1Contents = getAllRecursivelyInDirectoryApartFrom(dir1, dir1.resolve(".git"));
|
||||||
Set<String> dir2Contents = getAllFilesRecursivelyInDirectoryApartFrom(dir2, dir2.resolve(".git"));
|
Set<String> dir2Contents = getAllRecursivelyInDirectoryApartFrom(dir2, dir2.resolve(".git"));
|
||||||
boolean filesEqual = dir1Contents.equals(dir2Contents);
|
boolean filesEqual = dir1Contents.equals(dir2Contents);
|
||||||
if (!filesEqual) {
|
if (!filesEqual) {
|
||||||
System.out.println("Not equal: (" + dir1Contents + ", " + dir2Contents + ")");
|
System.out.println("Not equal: (" + dir1Contents + ", " + dir2Contents + ")");
|
||||||
|
@ -72,20 +72,31 @@ public class FileUtil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Set<String> getAllFilesRecursivelyInDirectoryApartFrom(Path dir, Path excluded) {
|
public static Set<String> getAllRecursivelyInDirectoryApartFrom(Path dir, Path excluded) {
|
||||||
|
return getAllRecursivelyInDirectoryApartFrom(dir, excluded, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Set<String> getOnlyFilesRecursivelyInDirectoryApartFrom(Path dir, Path excluded) {
|
||||||
|
return getAllRecursivelyInDirectoryApartFrom(dir, excluded, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Set<String> getAllRecursivelyInDirectoryApartFrom(Path dir, Path excluded, boolean directories) {
|
||||||
if (!dir.toFile().isDirectory()) {
|
if (!dir.toFile().isDirectory()) {
|
||||||
throw new IllegalArgumentException("need a directory");
|
throw new IllegalArgumentException("need a directory");
|
||||||
}
|
}
|
||||||
return getAllFilesRecursively(dir, dir, excluded);
|
return getAllFilesRecursively(dir, dir, excluded, directories);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Set<String> getAllFilesRecursively(Path baseDir, Path dir, Path excluded) {
|
static Set<String> getAllFilesRecursively(Path baseDir, Path dir, Path excluded, boolean directories) {
|
||||||
Set<String> files = new HashSet<String>();
|
Set<String> files = new HashSet<String>();
|
||||||
for (File file : dir.toFile().listFiles()) {
|
for (File file : dir.toFile().listFiles()) {
|
||||||
if (!file.equals(excluded.toFile())) {
|
if (!file.equals(excluded.toFile())) {
|
||||||
files.add(baseDir.relativize(file.toPath()).toString());
|
boolean isDirectory = file.isDirectory();
|
||||||
if (file.isDirectory()) {
|
if (directories || !isDirectory) {
|
||||||
files.addAll(getAllFilesRecursively(baseDir, file.toPath(), excluded));
|
files.add(baseDir.relativize(file.toPath()).toString());
|
||||||
|
}
|
||||||
|
if (isDirectory) {
|
||||||
|
files.addAll(getAllFilesRecursively(baseDir, file.toPath(), excluded, directories));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,7 @@ public class GitDirectoryContents implements WritableRepositoryContents {
|
||||||
public void write() throws IOException, FailedConnectionException {
|
public void write() throws IOException, FailedConnectionException {
|
||||||
WLFileStore.deleteInDirectoryApartFrom(gitDirectory, ".git");
|
WLFileStore.deleteInDirectoryApartFrom(gitDirectory, ".git");
|
||||||
for (FileNode fileNode : fileNodes) {
|
for (FileNode fileNode : fileNodes) {
|
||||||
|
System.out.println("Writing: " + fileNode.getFilePath());
|
||||||
fileNode.writeToDisk(gitDirectory);
|
fileNode.writeToDisk(gitDirectory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,6 +58,7 @@ public class WLFileStore implements PersistentStoreSource {
|
||||||
if (file.isDirectory()) {
|
if (file.isDirectory()) {
|
||||||
deleteInDirectory(file);
|
deleteInDirectory(file);
|
||||||
}
|
}
|
||||||
|
System.out.println("deleting: " + file.getAbsolutePath());
|
||||||
file.delete();
|
file.delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,10 @@ public class WLGitBridgeIntegrationTest {
|
||||||
put("base", new SnapshotAPIStateBuilder(getResourceAsStream("/canPullAModifiedTexFile/base/state.json")).build());
|
put("base", new SnapshotAPIStateBuilder(getResourceAsStream("/canPullAModifiedTexFile/base/state.json")).build());
|
||||||
put("withModifiedTexFile", new SnapshotAPIStateBuilder(getResourceAsStream("/canPullAModifiedTexFile/withModifiedTexFile/state.json")).build());
|
put("withModifiedTexFile", new SnapshotAPIStateBuilder(getResourceAsStream("/canPullAModifiedTexFile/withModifiedTexFile/state.json")).build());
|
||||||
}});
|
}});
|
||||||
|
put("canPullADeletedTexFile", new HashMap<String, SnapshotAPIState>() {{
|
||||||
|
put("base", new SnapshotAPIStateBuilder(getResourceAsStream("/canPullADeletedTexFile/base/state.json")).build());
|
||||||
|
put("withDeletedTexFile", new SnapshotAPIStateBuilder(getResourceAsStream("/canPullADeletedTexFile/withDeletedTexFile/state.json")).build());
|
||||||
|
}});
|
||||||
}};
|
}};
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
|
@ -111,6 +115,29 @@ public class WLGitBridgeIntegrationTest {
|
||||||
assertTrue(FileUtil.gitDirectoriesAreEqual(getResource("/canPullAModifiedTexFile/withModifiedTexFile/testproj"), git.toPath()));
|
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 {
|
private String makeConfigFile(int port, int apiPort) throws IOException {
|
||||||
File wlgb = folder.newFolder();
|
File wlgb = folder.newFolder();
|
||||||
File config = folder.newFile();
|
File config = folder.newFile();
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
|
@ -0,0 +1 @@
|
||||||
|
content
|
|
@ -0,0 +1,12 @@
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"/>
|
||||||
|
<title>Error 404 </title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h2>HTTP ERROR: 404</h2>
|
||||||
|
<p>Problem accessing /state/testproj1/overleaf-white-410.png. Reason:
|
||||||
|
<pre> Not Found</pre></p>
|
||||||
|
<hr /><i><small>Powered by Jetty://</small></i>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -0,0 +1 @@
|
||||||
|
This text is from another file.
|
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
|
@ -0,0 +1,2 @@
|
||||||
|
content
|
||||||
|
added more stuff
|
|
@ -0,0 +1,12 @@
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"/>
|
||||||
|
<title>Error 404 </title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h2>HTTP ERROR: 404</h2>
|
||||||
|
<p>Problem accessing /state/testproj1/overleaf-white-410.png. Reason:
|
||||||
|
<pre> Not Found</pre></p>
|
||||||
|
<hr /><i><small>Powered by Jetty://</small></i>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in a new issue