diff options
author | Christian Halstrick <christian.halstrick@sap.com> | 2011-05-24 00:45:21 +0200 |
---|---|---|
committer | Shawn O. Pearce <spearce@spearce.org> | 2011-05-31 08:58:45 -0700 |
commit | cc2197ed9c3be35c875c8316f17a2d6e8d338c88 (patch) | |
tree | a124cc1028b294fd082471a5700a75963f71e142 /org.eclipse.jgit | |
parent | cc319fff0db7e23e244fe650f4102150da5633d5 (diff) | |
download | jgit-cc2197ed9c3be35c875c8316f17a2d6e8d338c88.tar.gz jgit-cc2197ed9c3be35c875c8316f17a2d6e8d338c88.zip |
Fix CloneCommand not to fetch into remote tracking branches when bare
When cloning into a bare repository we should not create remote
tracking branches (e.g refs/remotes/origin/testX). Branches of the
remote repository should but fetched into into branches of the same
name (e.g refs/heads/testX). Also add the noCheckout option which
would prevent checkout after fetch.
Change-Id: I5d4cc0389f3f30c53aa0065f38119af2a1430909
Signed-off-by: Christian Halstrick <christian.halstrick@sap.com>
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java index 39652306b0..aa8cf6e30a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java @@ -98,6 +98,8 @@ public class CloneCommand implements Callable<Git> { private boolean cloneAllBranches; + private boolean noCheckout; + private Collection<String> branchesToClone; /** @@ -112,7 +114,8 @@ public class CloneCommand implements Callable<Git> { URIish u = new URIish(uri); Repository repository = init(u); FetchResult result = fetch(repository, u); - checkout(repository, result); + if (!noCheckout) + checkout(repository, result); return new Git(repository); } catch (IOException ioe) { throw new JGitInternalException(ioe.getMessage(), ioe); @@ -140,7 +143,8 @@ public class CloneCommand implements Callable<Git> { RemoteConfig config = new RemoteConfig(repo.getConfig(), remote); config.addURI(u); - final String dst = Constants.R_REMOTES + config.getName(); + final String dst = bare ? Constants.R_HEADS : Constants.R_REMOTES + + config.getName(); RefSpec refSpec = new RefSpec(); refSpec = refSpec.setForceUpdate(true); refSpec = refSpec.setSourceDestination(Constants.R_HEADS + "*", dst + "/*"); //$NON-NLS-1$ //$NON-NLS-2$ @@ -368,4 +372,16 @@ public class CloneCommand implements Callable<Git> { return this; } + /** + * @param noCheckout + * if set to <code>true</code> no branch will be checked out + * after the clone. This enhances performance of the clone + * command when there is no need for a checked out branch. + * @return {@code this} + */ + public CloneCommand setNoCheckout(boolean noCheckout) { + this.noCheckout = noCheckout; + return this; + } + } |