]> source.dussan.org Git - jgit.git/commitdiff
ReceivePack: Use error message if set 69/159969/4
authorMasaya Suzuki <masayasuzuki@google.com>
Tue, 24 Mar 2020 18:50:34 +0000 (11:50 -0700)
committerMasaya Suzuki <masayasuzuki@google.com>
Fri, 27 Mar 2020 19:23:36 +0000 (12:23 -0700)
ReceiveCommand can have an error message. This is shown only for some
cases even if it's set. This change uses the error message if it's set,
and fallback to the default message if unset.

Change-Id: I8d906e71ad08cf49bcdb28caea8fcc66798c68ff
Signed-off-by: Masaya Suzuki <masayasuzuki@google.com>
org.eclipse.jgit/src/org/eclipse/jgit/transport/ReceivePack.java

index ec2b76938e2c38ce7982701566463a6c2f13ac7e..8a8c1ae0ba351a4ef49503d21a8674a775bc473b 100644 (file)
@@ -1814,55 +1814,59 @@ public class ReceivePack {
                                                        .append(" ("); //$NON-NLS-1$
                                }
 
-                               switch (cmd.getResult()) {
-                               case NOT_ATTEMPTED:
-                                       r.append("server bug; ref not processed"); //$NON-NLS-1$
-                                       break;
-
-                               case REJECTED_NOCREATE:
-                                       r.append("creation prohibited"); //$NON-NLS-1$
-                                       break;
-
-                               case REJECTED_NODELETE:
-                                       r.append("deletion prohibited"); //$NON-NLS-1$
-                                       break;
-
-                               case REJECTED_NONFASTFORWARD:
-                                       r.append("non-fast forward"); //$NON-NLS-1$
-                                       break;
-
-                               case REJECTED_CURRENT_BRANCH:
-                                       r.append("branch is currently checked out"); //$NON-NLS-1$
-                                       break;
-
-                               case REJECTED_MISSING_OBJECT:
+                               if (cmd.getResult() == Result.REJECTED_MISSING_OBJECT) {
                                        if (cmd.getMessage() == null)
                                                r.append("missing object(s)"); //$NON-NLS-1$
                                        else if (cmd.getMessage()
                                                        .length() == Constants.OBJECT_ID_STRING_LENGTH) {
+                                               // TODO: Using get/setMessage to store an OID is a
+                                               // misuse. The caller should set a full error message.
                                                r.append("object "); //$NON-NLS-1$
                                                r.append(cmd.getMessage());
                                                r.append(" missing"); //$NON-NLS-1$
-                                       } else
+                                       } else {
                                                r.append(cmd.getMessage());
-                                       break;
+                                       }
+                               } else if (cmd.getMessage() != null) {
+                                       r.append(cmd.getMessage());
+                               } else {
+                                       switch (cmd.getResult()) {
+                                       case NOT_ATTEMPTED:
+                                               r.append("server bug; ref not processed"); //$NON-NLS-1$
+                                               break;
 
-                               case REJECTED_OTHER_REASON:
-                                       if (cmd.getMessage() == null)
+                                       case REJECTED_NOCREATE:
+                                               r.append("creation prohibited"); //$NON-NLS-1$
+                                               break;
+
+                                       case REJECTED_NODELETE:
+                                               r.append("deletion prohibited"); //$NON-NLS-1$
+                                               break;
+
+                                       case REJECTED_NONFASTFORWARD:
+                                               r.append("non-fast forward"); //$NON-NLS-1$
+                                               break;
+
+                                       case REJECTED_CURRENT_BRANCH:
+                                               r.append("branch is currently checked out"); //$NON-NLS-1$
+                                               break;
+
+                                       case REJECTED_OTHER_REASON:
                                                r.append("unspecified reason"); //$NON-NLS-1$
-                                       else
-                                               r.append(cmd.getMessage());
-                                       break;
+                                               break;
 
-                               case LOCK_FAILURE:
-                                       r.append("failed to lock"); //$NON-NLS-1$
-                                       break;
+                                       case LOCK_FAILURE:
+                                               r.append("failed to lock"); //$NON-NLS-1$
+                                               break;
 
-                               case OK:
-                                       // We shouldn't have reached this case (see 'ok' case
-                                       // above).
-                                       continue;
+                                       case REJECTED_MISSING_OBJECT:
+                                       case OK:
+                                               // We shouldn't have reached this case (see 'ok' case
+                                               // above and if-statement above).
+                                               throw new AssertionError();
+                                       }
                                }
+
                                if (!reportStatus) {
                                        r.append(")"); //$NON-NLS-1$
                                }