Просмотр исходного кода

When a repo has migrated to v2, print message about updating remote

Shane Kilkelly 8 лет назад
Родитель
Сommit
326d0a0722

+ 24 - 5
services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/snapshot/base/MissingRepositoryException.java

@@ -15,11 +15,30 @@ public class MissingRepositoryException extends SnapshotAPIException {
         "If this problem persists, please contact us."
     );
 
-    public static final List<String> EXPORTED_TO_V2 = Arrays.asList(
-        "This Overleaf project has been moved to Overleaf v2, and git access is temporarily unsupported.",
-        "",
-        "See https://www.overleaf.com/help/342 for more information."
-    );
+    static List<String> buildExportedToV2Message(String remoteUrl) {
+        if (remoteUrl == null) {
+            return Arrays.asList(
+                    "This Overleaf project has been moved to Overleaf v2, and cannot be used with git at this time.",
+                    "",
+                    "If this error persists, please contact us at support@overleaf.com, or",
+                    "see https://www.overleaf.com/help/342 for more information."
+            );
+        } else {
+            return Arrays.asList(
+                    "This Overleaf project has been moved to Overleaf v2, You should change your remote to:",
+                    "",
+                    "    " + remoteUrl,
+                    "",
+                    "Assuming you are using the default \"origin\" remote, the following commands",
+                    "will change the remote for you:",
+                    "",
+                    "    git remote set-url origin " + remoteUrl,
+                    "",
+                    "If this does not work, contact us at support@overleaf.com, or",
+                    "see https://www.overleaf.com/help/342 for more information."
+            );
+        }
+    }
 
     private List<String> descriptionLines;
 

+ 9 - 1
services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/snapshot/base/Request.java

@@ -79,9 +79,17 @@ public abstract class Request<T extends Result> {
                     try {
                         JsonObject json = Instance.gson.fromJson(httpCause.getContent(), JsonObject.class);
                         String message = json.get("message").getAsString();
+                        String newRemote;
+                        if (json.has("new_remote")) {
+                            newRemote = json.get("new_remote").getAsString();
+                        } else {
+                            newRemote = null;
+                        }
 
                         if ("Exported to v2".equals(message)) {
-                            throw new MissingRepositoryException(MissingRepositoryException.EXPORTED_TO_V2);
+                            throw new MissingRepositoryException(
+                                MissingRepositoryException.buildExportedToV2Message(newRemote)
+                            );
                         }
                     } catch (IllegalStateException
                             | ClassCastException