diff options
author | Tomasz Zarna <Tomasz.Zarna@pl.ibm.com> | 2012-09-05 07:59:37 +0200 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2012-09-05 07:59:37 +0200 |
commit | e44c3e713902faaf3c831827915312666cd6ecd6 (patch) | |
tree | 1731718bdedf1bd46ac05af125d477e2a2ba6b1d /org.eclipse.jgit.pgm/src | |
parent | f590a4c6672b6f507db72b8a425f6af4873c9b71 (diff) | |
download | jgit-e44c3e713902faaf3c831827915312666cd6ecd6.tar.gz jgit-e44c3e713902faaf3c831827915312666cd6ecd6.zip |
Output result of switching branch -- o.e.jgit.pgm.Checkout
Change-Id: I9829950b686ce3b8c70b8f7a1774d5e2b55cd00a
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.pgm/src')
-rw-r--r-- | org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/CLIText.java | 5 | ||||
-rw-r--r-- | org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Checkout.java | 40 |
2 files changed, 43 insertions, 2 deletions
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/CLIText.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/CLIText.java index 954977e111..d748d504b1 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/CLIText.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/CLIText.java @@ -59,6 +59,7 @@ public class CLIText extends TranslationBundle { } /***/ public String IPZillaPasswordPrompt; + /***/ public String alreadyOnBranch; /***/ public String authorInfo; /***/ public String averageMSPerRead; /***/ public String branchAlreadyExists; @@ -169,8 +170,10 @@ public class CLIText extends TranslationBundle { /***/ public String notAnObject; /***/ public String notFound; /***/ public String noteObjectTooLargeToPrint; + /***/ public String onBranchToBeBorn; /***/ public String onlyOneMetaVarExpectedIn; /***/ public String onlyOneOfIncludeOnlyAllInteractiveCanBeUsed; + /***/ public String pathspecDidNotMatch; /***/ public String pushTo; /***/ public String pathsRequired; /***/ public String refDoesNotExistOrNoCommit; @@ -180,6 +183,8 @@ public class CLIText extends TranslationBundle { /***/ public String repaint; /***/ public String serviceNotSupported; /***/ public String skippingObject; + /***/ public String switchedToNewBranch; + /***/ public String switchedToBranch; /***/ public String tagLabel; /***/ public String taggerInfo; /***/ public String timeInMilliSeconds; diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Checkout.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Checkout.java index 1b014f04ae..ee1ded09a6 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Checkout.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Checkout.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010, Chris Aniszczyk <caniszczyk@gmail.com> + * Copyright (C) 2010, 2012 Chris Aniszczyk <caniszczyk@gmail.com> * and other copyright owners as documented in the project's IP log. * * This program and the accompanying materials are made available @@ -43,8 +43,16 @@ package org.eclipse.jgit.pgm; +import java.text.MessageFormat; + import org.eclipse.jgit.api.CheckoutCommand; import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.api.errors.RefAlreadyExistsException; +import org.eclipse.jgit.api.errors.RefNotFoundException; +import org.eclipse.jgit.lib.Constants; +import org.eclipse.jgit.lib.ObjectId; +import org.eclipse.jgit.lib.Ref; +import org.eclipse.jgit.lib.Repository; import org.kohsuke.args4j.Argument; import org.kohsuke.args4j.Option; @@ -62,10 +70,38 @@ class Checkout extends TextBuiltin { @Override protected void run() throws Exception { + if (createBranch) { + final ObjectId head = db.resolve(Constants.HEAD); + if (head == null) + throw die(CLIText.get().onBranchToBeBorn); + } + CheckoutCommand command = new Git(db).checkout(); command.setCreateBranch(createBranch); command.setName(name); command.setForce(force); - command.call(); + try { + String oldBranch = db.getBranch(); + Ref ref = command.call(); + if (Repository.shortenRefName(ref.getName()).equals(oldBranch)) { + out.println(MessageFormat.format(CLIText.get().alreadyOnBranch, + name)); + return; + } + if (createBranch) + out.println(MessageFormat.format( + CLIText.get().switchedToNewBranch, + Repository.shortenRefName(ref.getName()))); + else + out.println(MessageFormat.format( + CLIText.get().switchedToBranch, + Repository.shortenRefName(ref.getName()))); + } catch (RefNotFoundException e) { + out.println(MessageFormat.format(CLIText.get().pathspecDidNotMatch, + name)); + } catch (RefAlreadyExistsException e) { + throw die(MessageFormat.format(CLIText.get().branchAlreadyExists, + name)); + } } } |