From 29546877b158d45b3b8b1d8d2a02751db1759798 Mon Sep 17 00:00:00 2001 From: Robin Rosenberg Date: Wed, 13 Feb 2013 00:27:52 +0100 Subject: Add the --branch flag to the jgit clone command --branch or -b allows the user to specify which branch to checkout after clone. Change-Id: Ie27533e5ecb43097862a8337a27a742b501e17a5 --- .../src/org/eclipse/jgit/pgm/CLIText.java | 1 + org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) (limited to 'org.eclipse.jgit.pgm/src') 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 552629eba1..807fe39db9 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 @@ -180,6 +180,7 @@ public class CLIText extends TranslationBundle { /***/ public String needApprovalToDestroyCurrentRepository; /***/ public String noGitRepositoryConfigured; /***/ public String noSuchFile; + /***/ public String noSuchRemoteRef; /***/ public String noTREESectionInIndex; /***/ public String nonFastForward; /***/ public String notABranch; diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java index 9af0570f31..898203da29 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java @@ -74,6 +74,9 @@ class Clone extends AbstractFetchCommand { @Option(name = "--origin", aliases = { "-o" }, metaVar = "metaVar_remoteName", usage = "usage_useNameInsteadOfOriginToTrackUpstream") private String remoteName = Constants.DEFAULT_REMOTE_NAME; + @Option(name = "--branch", aliases = { "-b" }, metaVar = "metaVar_branchName", usage = "usage_checkoutBranchAfterClone") + private String branch; + @Argument(index = 0, required = true, metaVar = "metaVar_uriish") private String sourceUri; @@ -117,8 +120,16 @@ class Clone extends AbstractFetchCommand { saveRemote(uri); final FetchResult r = runFetch(); - final Ref branch = guessHEAD(r); - doCheckout(branch); + final Ref checkoutRef; + if (branch == null) + checkoutRef = guessHEAD(r); + else { + checkoutRef = r.getAdvertisedRef(Constants.R_HEADS + branch); + if (checkoutRef == null) + throw die(MessageFormat.format(CLIText.get().noSuchRemoteRef, + branch)); + } + doCheckout(checkoutRef); } private void saveRemote(final URIish uri) throws URISyntaxException, -- cgit v1.2.3