mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-09 09:16:13 +00:00
Merge pull request #50 from overleaf/sk-fix-imported-unchanged-projects
Handle imported, and unchanged, projects
This commit is contained in:
commit
d86d257b05
6 changed files with 78 additions and 6 deletions
|
@ -97,7 +97,10 @@ public class SnapshotApiFacade {
|
|||
= api.getSavedVers(oauth2, projectName);
|
||||
GetDocResult latestDoc = SnapshotApi.getResult(getDoc);
|
||||
int latest = latestDoc.getVersionID();
|
||||
if (latest > version) {
|
||||
// Handle edge-case for projects with no changes, that were imported
|
||||
// to v2. In which case both `latest` and `version` will be zero.
|
||||
// See: https://github.com/overleaf/writelatex-git-bridge/pull/50
|
||||
if (latest > version || (latest == 0 && version == 0)) {
|
||||
for (
|
||||
SnapshotInfo snapshotInfo :
|
||||
SnapshotApi.getResult(savedVers).getSavedVers()
|
||||
|
|
|
@ -98,7 +98,14 @@ public class GetDocResult extends Result {
|
|||
}
|
||||
} else {
|
||||
versionID = jsonObject.get("latestVerId").getAsInt();
|
||||
createdAt = jsonObject.get("latestVerAt").getAsString();
|
||||
// Handle edge-case for projects with no changes, that were imported
|
||||
// to v2. In which case `latestVerAt` will not be present.
|
||||
// See: https://github.com/overleaf/writelatex-git-bridge/pull/50
|
||||
if (jsonObject.has("latestVerAt")) {
|
||||
createdAt = jsonObject.get("latestVerAt").getAsString();
|
||||
} else {
|
||||
createdAt = null;
|
||||
}
|
||||
if (jsonObject.has("migratedFromId")) {
|
||||
migratedFromID = jsonObject.get("migratedFromId").getAsString();
|
||||
} else {
|
||||
|
|
|
@ -83,7 +83,20 @@ public class SnapshotAPIStateBuilder {
|
|||
String projectName,
|
||||
JsonObject jsonGetDoc
|
||||
) {
|
||||
int versionID = jsonGetDoc.get("versionID").getAsInt();
|
||||
String createdAt = null;
|
||||
String email = null;
|
||||
String name = null;
|
||||
String migratedFromId = null;
|
||||
if (jsonGetDoc.has("createdAt")) {
|
||||
createdAt = jsonGetDoc.get("createdAt").getAsString();
|
||||
}
|
||||
if (jsonGetDoc.has("email")) {
|
||||
email = jsonGetDoc.get("email").getAsString();
|
||||
}
|
||||
if (jsonGetDoc.has("name")) {
|
||||
name = jsonGetDoc.get("name").getAsString();
|
||||
}
|
||||
if (jsonGetDoc.has("migratedFromId")) {
|
||||
migratedFromId = jsonGetDoc.get("migratedFromId").getAsString();
|
||||
}
|
||||
|
@ -91,10 +104,10 @@ public class SnapshotAPIStateBuilder {
|
|||
projectName,
|
||||
new GetDocResult(
|
||||
jsonGetDoc.get("error"),
|
||||
jsonGetDoc.get("versionID").getAsInt(),
|
||||
jsonGetDoc.get("createdAt").getAsString(),
|
||||
jsonGetDoc.get("email").getAsString(),
|
||||
jsonGetDoc.get("name").getAsString(),
|
||||
versionID,
|
||||
createdAt,
|
||||
email,
|
||||
name,
|
||||
migratedFromId
|
||||
)
|
||||
);
|
||||
|
|
|
@ -123,6 +123,9 @@ public class WLGitBridgeIntegrationTest {
|
|||
put("skipMigrationWhenMigratedFromMissing", new HashMap<String, SnapshotAPIState>() {{
|
||||
put("state", new SnapshotAPIStateBuilder(getResourceAsStream("/skipMigrationWhenMigratedFromMissing/state/state.json")).build());
|
||||
}});
|
||||
put("canCloneAMigratedRepositoryWithoutChanges", new HashMap<String, SnapshotAPIState>() {{
|
||||
put("state", new SnapshotAPIStateBuilder(getResourceAsStream("/canCloneAMigratedRepositoryWithoutChanges/state/state.json")).build());
|
||||
}});
|
||||
}};
|
||||
|
||||
@Rule
|
||||
|
@ -830,6 +833,22 @@ public class WLGitBridgeIntegrationTest {
|
|||
assertTrue(FileUtil.gitDirectoriesAreEqual(getResource("/skipMigrationWhenMigratedFromMissing/state/testproj2"), testprojDir2.toPath()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canCloneAMigratedRepositoryWithoutChanges() throws IOException, GitAPIException, InterruptedException {
|
||||
int gitBridgePort = 33883;
|
||||
int mockServerPort = 3883;
|
||||
MockSnapshotServer server = new MockSnapshotServer(mockServerPort, getResource("/canCloneAMigratedRepositoryWithoutChanges").toFile());
|
||||
server.start();
|
||||
server.setState(states.get("canCloneAMigratedRepositoryWithoutChanges").get("state"));
|
||||
GitBridgeApp wlgb = new GitBridgeApp(new String[] {
|
||||
makeConfigFile(gitBridgePort, mockServerPort)
|
||||
});
|
||||
wlgb.run();
|
||||
File testprojDir = gitClone("testproj_no_change", gitBridgePort, dir);
|
||||
wlgb.stop();
|
||||
assertTrue(FileUtil.gitDirectoriesAreEqual(getResource("/canCloneAMigratedRepositoryWithoutChanges/state/testproj_no_change"), testprojDir.toPath()));
|
||||
}
|
||||
|
||||
private String makeConfigFile(
|
||||
int port,
|
||||
int apiPort
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
[
|
||||
{
|
||||
"project": "testproj_no_change",
|
||||
"getDoc": {
|
||||
"versionID": 0,
|
||||
"createdAt": "2014-11-30T18:40:58.123Z",
|
||||
"email": "jdleesmiller+1@gmail.com",
|
||||
"name": "John+1"
|
||||
},
|
||||
"getSavedVers": [],
|
||||
"getForVers": [
|
||||
{
|
||||
"versionID": 0,
|
||||
"srcs": [
|
||||
{
|
||||
"content": "test content\n",
|
||||
"path": "main.tex"
|
||||
}
|
||||
],
|
||||
"atts": []
|
||||
}
|
||||
],
|
||||
"push": "success",
|
||||
"postback": {
|
||||
"type": "success",
|
||||
"versionID": 1
|
||||
}
|
||||
}
|
||||
]
|
Loading…
Add table
Reference in a new issue