Allow a different conflict message for manifest.

Stuff like "repo download" that might work on most projects doesn't work
on manifest projects, so adding the option for a different message on
conflict so different instructions can be posted to users.

Change-Id: Icca4099a5ae875d254ab229d6231b1814a6d928e
diff --git a/src/main/java/com/googlesource/gerrit/plugins/automerger/ConfigLoader.java b/src/main/java/com/googlesource/gerrit/plugins/automerger/ConfigLoader.java
index a3c5e18..41c1bf5 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/automerger/ConfigLoader.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/automerger/ConfigLoader.java
@@ -165,6 +165,20 @@
   }
 
   /**
+   * Returns a string to append to the end of the merge conflict message for the manifest project.
+   *
+   * @return The message string, or the empty string if nothing is specified.
+   * @throws ConfigInvalidException
+   */
+  public String getManifestConflictMessage() throws ConfigInvalidException {
+    String conflictMessage = getConfig().getString("global", null, "manifestConflictMessage");
+    if (Strings.isNullOrEmpty(conflictMessage)) {
+      conflictMessage = getConflictMessage();
+    }
+    return conflictMessage;
+  }
+
+  /**
    * Get the projects that should be merged for the given pair of branches.
    *
    * @param fromBranch Branch we are merging from.
@@ -293,6 +307,19 @@
     return user.get().getAccountId();
   }
 
+  /**
+   * Returns overriden manifest config if specified, default if not
+   * @return The string name of the manifest project.
+   * @throws ConfigInvalidException
+   */
+  public String getManifestProject() throws ConfigInvalidException {
+    String manifestProject = getConfig().getString("global", null, "manifestProject");
+    if (manifestProject == null) {
+      throw new ConfigInvalidException("manifestProject not specified.");
+    }
+    return manifestProject;
+  }
+
   // Returns overriden manifest config if specified, default if not
   private String getManifestFile() throws ConfigInvalidException {
     String manifestFile = getConfig().getString("global", null, "manifestFile");
@@ -302,15 +329,6 @@
     return manifestFile;
   }
 
-  // Returns overriden manifest config if specified, default if not
-  private String getManifestProject() throws ConfigInvalidException {
-    String manifestProject = getConfig().getString("global", null, "manifestProject");
-    if (manifestProject == null) {
-      throw new ConfigInvalidException("manifestProject not specified.");
-    }
-    return manifestProject;
-  }
-
   // Returns contents of manifest file for the given branch pair
   // If manifest does not exist, return empty set.
   private Set<String> getManifestProjects(String fromBranch, String toBranch)
diff --git a/src/main/java/com/googlesource/gerrit/plugins/automerger/DownstreamCreator.java b/src/main/java/com/googlesource/gerrit/plugins/automerger/DownstreamCreator.java
index 070b9b7..d2b29c9 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/automerger/DownstreamCreator.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/automerger/DownstreamCreator.java
@@ -412,6 +412,10 @@
       }
 
       if (!failedMergeBranchMap.isEmpty()) {
+        String conflictMessage = config.getConflictMessage();
+        if (mdsMergeInput.project.equals(config.getManifestProject())) {
+          conflictMessage = config.getManifestConflictMessage();
+        }
         throw new FailedMergeException(
             failedMergeBranchMap,
             mdsMergeInput.currentRevision,
@@ -419,7 +423,7 @@
             mdsMergeInput.project,
             mdsMergeInput.changeNumber,
             mdsMergeInput.patchsetNumber,
-            config.getConflictMessage(),
+            conflictMessage,
             mdsMergeInput.topic);
       }
     }
diff --git a/src/main/resources/Documentation/config.md b/src/main/resources/Documentation/config.md
index a1752b1..6e629b3 100644
--- a/src/main/resources/Documentation/config.md
+++ b/src/main/resources/Documentation/config.md
@@ -10,6 +10,7 @@
     hostName = https://hostname.example.com
     conflictMessage = Merge conflict found on ${branch}\n\
 " # Example of multiline conflict message"
+    manifestConflictMessage = Conflict found on platform/manifest
     manifestProject = platform/manifest
     manifestFile = default.xml
     alwaysBlankMerge = .*SKIP ME ALWAYS.*
@@ -71,6 +72,12 @@
     conflictMessage = Conflict message ${conflict} found on branch ${branch}
   ```
 
+global.manifestConflictMessage
+: Like conflictMessage, but only applies to the manifestProject.
+
+  Some messages on normal projects don't apply to manifest projects. This
+  provides users the option to have a different message for manifest projects.
+
 global.manifestProject
 : Project to look for a [repo manifest][1] in.
 
diff --git a/src/test/java/com/googlesource/gerrit/plugins/automerger/ConfigLoaderIT.java b/src/test/java/com/googlesource/gerrit/plugins/automerger/ConfigLoaderIT.java
index d20f878..0235cd8 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/automerger/ConfigLoaderIT.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/automerger/ConfigLoaderIT.java
@@ -222,6 +222,20 @@
   }
 
   @Test
+  public void getDefaultManifestConflictMessageTest() throws Exception {
+    defaultSetup("automerger.config");
+    assertThat(configLoader.getManifestConflictMessage())
+        .isEqualTo("Merge conflict found on ${branch}");
+  }
+
+  @Test
+  public void getMultilineManifestConflictMessageTest() throws Exception {
+    defaultSetup("alternate.config");
+    assertThat(configLoader.getManifestConflictMessage())
+        .isEqualTo("mline1\n" + "mline2\n" + "mline3 ${branch}\n" + "mline4");
+  }
+
+  @Test
   public void getMinAutomergeVoteTest() throws Exception {
     defaultSetup("alternate.config");
     assertThat(configLoader.getMinAutomergeVote()).isEqualTo(-3);
diff --git a/src/test/resources/com/googlesource/gerrit/plugins/automerger/alternate.config b/src/test/resources/com/googlesource/gerrit/plugins/automerger/alternate.config
index 19d69c1..80b7bb6 100644
--- a/src/test/resources/com/googlesource/gerrit/plugins/automerger/alternate.config
+++ b/src/test/resources/com/googlesource/gerrit/plugins/automerger/alternate.config
@@ -18,4 +18,8 @@
 line2\n\
 line3 ${branch}\n\
 line4
+  manifestConflictMessage = mline1\n\
+mline2\n\
+mline3 ${branch}\n\
+mline4
   missingDownstreamsMessage = there is no ${missingDownstreams}
\ No newline at end of file