]> source.dussan.org Git - jgit.git/commitdiff
Treat CloneCommand.setBranch(null) as setBranch("HEAD") 78/49978/2
authorJonathan Nieder <jrn@google.com>
Wed, 10 Jun 2015 22:43:48 +0000 (15:43 -0700)
committerJonathan Nieder <jrn@google.com>
Thu, 11 Jun 2015 19:03:17 +0000 (12:03 -0700)
This method is documented to take a branch name (not a possibly null
string).  The only way a caller could have set null without either
re-setting to a sane value afterward or producing NullPointerException
was to also call setNoCheckout(true), in which case there would have
been no reason to set the branch in the first place.

Make setBranch(null) request the default behavior (remote's default
branch) instead, imitating C git's clone --no-branch.

Change-Id: I960e7046b8d5b5bc75c7f3688f3a075d3a951b00
Signed-off-by: Jonathan Nieder <jrn@google.com>
org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java

index 20d06331d26ee81790bd4616f91619d4c5beb559..9de2803c0b1dc706ca0d0c5bfc1abb0735efc968 100644 (file)
@@ -420,9 +420,15 @@ public class CloneCommand extends TransportCommand<CloneCommand, Git> {
         *            the initial branch to check out when cloning the repository.
         *            Can be specified as ref name (<code>refs/heads/master</code>),
         *            branch name (<code>master</code>) or tag name (<code>v1.2.3</code>).
+        *            The default is to use the branch pointed to by the cloned
+        *            repository's HEAD and can be requested by passing {@code null}
+        *            or <code>HEAD</code>.
         * @return this instance
         */
        public CloneCommand setBranch(String branch) {
+               if (branch == null) {
+                       branch = Constants.HEAD;
+               }
                this.branch = branch;
                return this;
        }