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
This commit is contained in:
parent
ae57189712
commit
29546877b1
|
@ -76,6 +76,7 @@ metaVar_author=AUTHOR
|
||||||
metaVar_base=base
|
metaVar_base=base
|
||||||
metaVar_blameL=START,END
|
metaVar_blameL=START,END
|
||||||
metaVar_blameReverse=START..END
|
metaVar_blameReverse=START..END
|
||||||
|
metaVar_branchName=branch
|
||||||
metaVar_bucket=BUCKET
|
metaVar_bucket=BUCKET
|
||||||
metaVar_command=command
|
metaVar_command=command
|
||||||
metaVar_commandDetail=DETAIL
|
metaVar_commandDetail=DETAIL
|
||||||
|
@ -116,6 +117,7 @@ mostCommonlyUsedCommandsAre=The most commonly used commands are:
|
||||||
needApprovalToDestroyCurrentRepository=Need approval to destroy current repository
|
needApprovalToDestroyCurrentRepository=Need approval to destroy current repository
|
||||||
noGitRepositoryConfigured=No Git repository configured.
|
noGitRepositoryConfigured=No Git repository configured.
|
||||||
noSuchFile=no such file: {0}
|
noSuchFile=no such file: {0}
|
||||||
|
noSuchRemoteRef=no such remote ref: ''{0}''
|
||||||
noTREESectionInIndex=no 'TREE' section in index
|
noTREESectionInIndex=no 'TREE' section in index
|
||||||
nonFastForward=non-fast forward
|
nonFastForward=non-fast forward
|
||||||
notABranch={0} is not a branch
|
notABranch={0} is not a branch
|
||||||
|
@ -274,5 +276,6 @@ usage_symbolicVersionForTheProject=Symbolic version for the project
|
||||||
usage_tagMessage=tag message
|
usage_tagMessage=tag message
|
||||||
usage_updateRemoteRefsFromAnotherRepository=Update remote refs from another repository
|
usage_updateRemoteRefsFromAnotherRepository=Update remote refs from another repository
|
||||||
usage_useNameInsteadOfOriginToTrackUpstream=use <name> instead of 'origin' to track upstream
|
usage_useNameInsteadOfOriginToTrackUpstream=use <name> instead of 'origin' to track upstream
|
||||||
|
usage_checkoutBranchAfterClone=checkout named branch instead of remotes's HEAD
|
||||||
usage_viewCommitHistory=View commit history
|
usage_viewCommitHistory=View commit history
|
||||||
warningNoCommitGivenOnCommandLine=warning: No commit given on command line, assuming {0}
|
warningNoCommitGivenOnCommandLine=warning: No commit given on command line, assuming {0}
|
||||||
|
|
|
@ -180,6 +180,7 @@ public static String formatLine(String line) {
|
||||||
/***/ public String needApprovalToDestroyCurrentRepository;
|
/***/ public String needApprovalToDestroyCurrentRepository;
|
||||||
/***/ public String noGitRepositoryConfigured;
|
/***/ public String noGitRepositoryConfigured;
|
||||||
/***/ public String noSuchFile;
|
/***/ public String noSuchFile;
|
||||||
|
/***/ public String noSuchRemoteRef;
|
||||||
/***/ public String noTREESectionInIndex;
|
/***/ public String noTREESectionInIndex;
|
||||||
/***/ public String nonFastForward;
|
/***/ public String nonFastForward;
|
||||||
/***/ public String notABranch;
|
/***/ public String notABranch;
|
||||||
|
|
|
@ -74,6 +74,9 @@ class Clone extends AbstractFetchCommand {
|
||||||
@Option(name = "--origin", aliases = { "-o" }, metaVar = "metaVar_remoteName", usage = "usage_useNameInsteadOfOriginToTrackUpstream")
|
@Option(name = "--origin", aliases = { "-o" }, metaVar = "metaVar_remoteName", usage = "usage_useNameInsteadOfOriginToTrackUpstream")
|
||||||
private String remoteName = Constants.DEFAULT_REMOTE_NAME;
|
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")
|
@Argument(index = 0, required = true, metaVar = "metaVar_uriish")
|
||||||
private String sourceUri;
|
private String sourceUri;
|
||||||
|
|
||||||
|
@ -117,8 +120,16 @@ protected void run() throws Exception {
|
||||||
|
|
||||||
saveRemote(uri);
|
saveRemote(uri);
|
||||||
final FetchResult r = runFetch();
|
final FetchResult r = runFetch();
|
||||||
final Ref branch = guessHEAD(r);
|
final Ref checkoutRef;
|
||||||
doCheckout(branch);
|
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,
|
private void saveRemote(final URIish uri) throws URISyntaxException,
|
||||||
|
|
Loading…
Reference in New Issue