summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorThomas Wolf <thomas.wolf@paranor.ch>2020-02-03 21:00:46 +0100
committerThomas Wolf <thomas.wolf@paranor.ch>2020-02-04 08:49:07 +0100
commit75a80c5d3c790260a35ccf21ee54329f5d160879 (patch)
tree09328e168a600edb47074ddd3f473e4e812071f5 /org.eclipse.jgit
parent3d59d1b80cd90bf22a43e522d372d72f0c2ee8a6 (diff)
downloadjgit-75a80c5d3c790260a35ccf21ee54329f5d160879.tar.gz
jgit-75a80c5d3c790260a35ccf21ee54329f5d160879.zip
Restore behavior of CloneCommand
Commit 6216b0de changed the behavior of the setMirror(), setCloneAllBranches(), and setBranchesToClone() operations. Before that commit, these could be set and reset independently and only in call() it would be determined what exactly to do. Since that commit, the last of these calls would determine the operation. This means that the sequence cloneCommand.setCloneAllBranches(true); cloneCommand.setBranchesToClone(/* some list of refs */); would formerly do a "clone all" giving a fetch refspec with wildcards +refs/heads/*:refs/remotes/origin/* which picks up new upstream branches, whereas since commit 6216b0de individual non-wildcard fetch refspecs would be generated and new upstream branches would not be fetched anymore. Undo this behavioral change. Make the operations independently settable and resettable again, and determine the exact operation only in call(): mirror=true > cloneAll=true > specific refs, where ">" means "takes precedence over", and if none is set assume cloneAll=true. Note that mirror=true implies setBare(true). Bug: 559796 Change-Id: I7162b60e99de5e3e512bf27ff4113f554c94f5a6 Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java42
1 files changed, 26 insertions, 16 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 809f2d111a..7008cd49a8 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java
@@ -104,7 +104,9 @@ public class CloneCommand extends TransportCommand<CloneCommand, Git> {
private ProgressMonitor monitor = NullProgressMonitor.INSTANCE;
- private FETCH_TYPE fetchType = FETCH_TYPE.ALL_BRANCHES;
+ private boolean cloneAllBranches;
+
+ private boolean mirror;
private boolean cloneSubmodules;
@@ -118,6 +120,8 @@ public class CloneCommand extends TransportCommand<CloneCommand, Git> {
private boolean gitDirExistsInitially;
+ private FETCH_TYPE fetchType;
+
private enum FETCH_TYPE {
MULTIPLE_BRANCHES, ALL_BRANCHES, MIRROR
}
@@ -195,6 +199,7 @@ public class CloneCommand extends TransportCommand<CloneCommand, Git> {
throw new InvalidRemoteException(
MessageFormat.format(JGitText.get().invalidURL, uri));
}
+ setFetchType();
@SuppressWarnings("resource") // Closed by caller
Repository repository = init();
FetchResult fetchResult = null;
@@ -238,6 +243,20 @@ public class CloneCommand extends TransportCommand<CloneCommand, Git> {
return new Git(repository, true);
}
+ private void setFetchType() {
+ if (mirror) {
+ fetchType = FETCH_TYPE.MIRROR;
+ setBare(true);
+ } else if (cloneAllBranches) {
+ fetchType = FETCH_TYPE.ALL_BRANCHES;
+ } else if (branchesToClone != null && !branchesToClone.isEmpty()) {
+ fetchType = FETCH_TYPE.MULTIPLE_BRANCHES;
+ } else {
+ // Default: neither mirror nor all nor specific refs given
+ fetchType = FETCH_TYPE.ALL_BRANCHES;
+ }
+ }
+
private static boolean isNonEmptyDirectory(File dir) {
if (dir != null && dir.exists()) {
File[] files = dir.listFiles();
@@ -619,8 +638,7 @@ public class CloneCommand extends TransportCommand<CloneCommand, Git> {
* @return {@code this}
*/
public CloneCommand setCloneAllBranches(boolean cloneAllBranches) {
- this.fetchType = cloneAllBranches ? FETCH_TYPE.ALL_BRANCHES
- : this.fetchType;
+ this.cloneAllBranches = cloneAllBranches;
return this;
}
@@ -640,10 +658,7 @@ public class CloneCommand extends TransportCommand<CloneCommand, Git> {
* @since 5.6
*/
public CloneCommand setMirror(boolean mirror) {
- if (mirror) {
- this.fetchType = FETCH_TYPE.MIRROR;
- setBare(true);
- }
+ this.mirror = mirror;
return this;
}
@@ -664,8 +679,9 @@ public class CloneCommand extends TransportCommand<CloneCommand, Git> {
* Set the branches or tags to clone.
* <p>
* This is ignored if {@link #setCloneAllBranches(boolean)
- * setCloneAllBranches(true)} is used. If {@code branchesToClone} is
- * {@code null} or empty, it's also ignored and all branches will be cloned.
+ * setCloneAllBranches(true)} or {@link #setMirror(boolean) setMirror(true)}
+ * is used. If {@code branchesToClone} is {@code null} or empty, it's also
+ * ignored.
* </p>
*
* @param branchesToClone
@@ -675,13 +691,7 @@ public class CloneCommand extends TransportCommand<CloneCommand, Git> {
* @return {@code this}
*/
public CloneCommand setBranchesToClone(Collection<String> branchesToClone) {
- if (branchesToClone == null || branchesToClone.isEmpty()) {
- // fallback to default
- fetchType = FETCH_TYPE.ALL_BRANCHES;
- } else {
- this.fetchType = FETCH_TYPE.MULTIPLE_BRANCHES;
- this.branchesToClone = branchesToClone;
- }
+ this.branchesToClone = branchesToClone;
return this;
}