summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.pgm
diff options
context:
space:
mode:
authorTomasz Zarna <Tomasz.Zarna@pl.ibm.com>2012-09-05 07:59:37 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2012-09-05 07:59:37 +0200
commite44c3e713902faaf3c831827915312666cd6ecd6 (patch)
tree1731718bdedf1bd46ac05af125d477e2a2ba6b1d /org.eclipse.jgit.pgm
parentf590a4c6672b6f507db72b8a425f6af4873c9b71 (diff)
downloadjgit-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')
-rw-r--r--org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/CLIText.properties9
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/CLIText.java5
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Checkout.java40
3 files changed, 50 insertions, 4 deletions
diff --git a/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/CLIText.properties b/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/CLIText.properties
index a14f374f94..824ee80b2c 100644
--- a/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/CLIText.properties
+++ b/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/CLIText.properties
@@ -6,10 +6,11 @@ ARGUMENTS=ARGUMENTS
N=N
IPZillaPasswordPrompt=IPZilla Password
+alreadyOnBranch=Already on ''{0}''
authorInfo=Author: {0} <{1}>
averageMSPerRead=average {0} ms/read
-branchAlreadyExists=branch {0} already exists
-branchCreatedFrom =branch: Created from {0}
+branchAlreadyExists=A branch named ''{0}'' already exists.
+branchCreatedFrom=branch: Created from {0}
branchDetachedHEAD=detached HEAD
branchIsNotAnAncestorOfYourCurrentHEAD=The branch '{0}' is not an ancestor of your current HEAD.\nIf you are sure you want to delete it, run 'jgit branch -D {0}'.
branchNotFound=branch '{0}' not found.
@@ -122,8 +123,10 @@ notAnIndexFile={0} is not an index file
notAnObject={0} is not an object
notFound=!! NOT FOUND !!
noteObjectTooLargeToPrint=Note object {0} too large to print
+onBranchToBeBorn=You are on a branch yet to be born
onlyOneMetaVarExpectedIn=Only one {0} expected in {1}.
onlyOneOfIncludeOnlyAllInteractiveCanBeUsed=Only one of --include/--only/--all/--interactive can be used.
+pathspecDidNotMatch=error: pathspec ''{0}'' did not match any file(s) known to git.
pushTo=To {0}
pathsRequired=at least one path has to be specified when using --only
refDoesNotExistOrNoCommit={0} does not exist or is not referring to a commit
@@ -133,6 +136,8 @@ remoteSideDoesNotSupportDeletingRefs=remote side does not support deleting refs
repaint=Repaint
serviceNotSupported=Service '{0}' not supported
skippingObject=skipping {0} {1}
+switchedToNewBranch=Switched to a new branch ''{0}''
+switchedToBranch=Switched to branch ''{0}''
tagLabel=tag
taggerInfo=Tagger: {0} <{1}>
timeInMilliSeconds={0} ms
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));
+ }
}
}