]> source.dussan.org Git - jgit.git/commitdiff
pgm: Handle exceptions in Branch command 00/135200/3
authorMatthias Sohn <matthias.sohn@sap.com>
Sun, 20 Jan 2019 00:17:10 +0000 (01:17 +0100)
committerMatthias Sohn <matthias.sohn@sap.com>
Sun, 20 Jan 2019 00:17:10 +0000 (01:17 +0100)
This avoids we show a stacktrace on the console by default when one of
the expected exceptions is thrown during the run method is executed.

Change-Id: Ib07cc8dd26b45b62de1d77739380eb36833082f1
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Branch.java

index a88354deba937f612671b79d9c76862dd36917cd..7b3c958ef8bf5caa653fe751c74a7cd81fd1307a 100644 (file)
@@ -54,6 +54,7 @@ import java.util.Map.Entry;
 import org.eclipse.jgit.api.Git;
 import org.eclipse.jgit.api.ListBranchCommand;
 import org.eclipse.jgit.api.ListBranchCommand.ListMode;
+import org.eclipse.jgit.api.errors.GitAPIException;
 import org.eclipse.jgit.lib.Constants;
 import org.eclipse.jgit.lib.ObjectId;
 import org.eclipse.jgit.lib.ObjectReader;
@@ -182,15 +183,17 @@ class Branch extends TextBuiltin {
 
        /** {@inheritDoc} */
        @Override
-       protected void run() throws Exception {
-               if (delete != null || deleteForce != null) {
-                       if (delete != null) {
-                               delete(delete, false);
-                       }
-                       if (deleteForce != null) {
-                               delete(deleteForce, true);
+       protected void run() {
+               try {
+                       if (delete != null || deleteForce != null) {
+                               if (delete != null) {
+                                       delete(delete, false);
+                               }
+                               if (deleteForce != null) {
+                                       delete(deleteForce, true);
+                               }
+                               return;
                        }
-               } else {
                        if (rename) {
                                String src, dst;
                                if (otherBranch == null) {
@@ -264,10 +267,12 @@ class Branch extends TextBuiltin {
                                }
                                list();
                        }
+               } catch (IOException | GitAPIException e) {
+                       throw die(e.getMessage(), e);
                }
        }
 
-       private void list() throws Exception {
+       private void list() throws IOException, GitAPIException {
                Ref head = db.exactRef(Constants.HEAD);
                // This can happen if HEAD is stillborn
                if (head != null) {
@@ -316,7 +321,7 @@ class Branch extends TextBuiltin {
        }
 
        private void printHead(final ObjectReader reader, final String ref,
-                       final boolean isCurrent, final Ref refObj) throws Exception {
+                       final boolean isCurrent, final Ref refObj) throws IOException {
                outw.print(isCurrent ? '*' : ' ');
                outw.print(' ');
                outw.print(ref);