diff options
author | Thomas Wolf <thomas.wolf@paranor.ch> | 2020-02-03 21:00:46 +0100 |
---|---|---|
committer | Thomas Wolf <thomas.wolf@paranor.ch> | 2020-02-04 08:49:07 +0100 |
commit | 75a80c5d3c790260a35ccf21ee54329f5d160879 (patch) | |
tree | 09328e168a600edb47074ddd3f473e4e812071f5 /org.eclipse.jgit.test/tst/org | |
parent | 3d59d1b80cd90bf22a43e522d372d72f0c2ee8a6 (diff) | |
download | jgit-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.test/tst/org')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java index 3224bbb784..c42cee375d 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java @@ -441,6 +441,7 @@ public class CloneCommandTest extends RepositoryTestCase { Git git2 = command.call(); addRepoToClose(git2.getRepository()); assertNotNull(git2); + assertTrue(git2.getRepository().isBare()); assertNotNull(git2.getRepository().resolve("tag-for-blob")); assertNotNull(git2.getRepository().resolve("tag-initial")); assertEquals(git2.getRepository().getFullBranch(), "refs/heads/master"); @@ -481,6 +482,60 @@ public class CloneCommandTest extends RepositoryTestCase { specs.get(0)); } + @Test + public void testCloneRepositoryAllBranchesTakesPreference() + throws Exception { + File directory = createTempDirectory( + "testCloneRepositoryAllBranchesTakesPreference"); + CloneCommand command = Git.cloneRepository(); + command.setCloneAllBranches(true); + command.setBranchesToClone( + Collections.singletonList("refs/heads/test")); + command.setDirectory(directory); + command.setURI(fileUri()); + Git git2 = command.call(); + addRepoToClose(git2.getRepository()); + assertNotNull(git2); + assertEquals(git2.getRepository().getFullBranch(), "refs/heads/test"); + // Expect both remote branches to exist; setCloneAllBranches(true) + // should override any setBranchesToClone(). + assertNotNull( + git2.getRepository().resolve("refs/remotes/origin/master")); + assertNotNull(git2.getRepository().resolve("refs/remotes/origin/test")); + RemoteConfig cfg = new RemoteConfig(git2.getRepository().getConfig(), + Constants.DEFAULT_REMOTE_NAME); + List<RefSpec> specs = cfg.getFetchRefSpecs(); + assertEquals(1, specs.size()); + assertEquals(new RefSpec("+refs/heads/*:refs/remotes/origin/*"), + specs.get(0)); + } + + @Test + public void testCloneRepositoryAllBranchesIndependent() throws Exception { + File directory = createTempDirectory( + "testCloneRepositoryAllBranchesIndependent"); + CloneCommand command = Git.cloneRepository(); + command.setCloneAllBranches(true); + command.setBranchesToClone( + Collections.singletonList("refs/heads/test")); + command.setCloneAllBranches(false); + command.setDirectory(directory); + command.setURI(fileUri()); + Git git2 = command.call(); + addRepoToClose(git2.getRepository()); + assertNotNull(git2); + assertEquals(git2.getRepository().getFullBranch(), "refs/heads/test"); + // Expect only the test branch; allBranches was re-set to false + assertNull(git2.getRepository().resolve("refs/remotes/origin/master")); + assertNotNull(git2.getRepository().resolve("refs/remotes/origin/test")); + RemoteConfig cfg = new RemoteConfig(git2.getRepository().getConfig(), + Constants.DEFAULT_REMOTE_NAME); + List<RefSpec> specs = cfg.getFetchRefSpecs(); + assertEquals(1, specs.size()); + assertEquals(new RefSpec("+refs/heads/test:refs/remotes/origin/test"), + specs.get(0)); + } + public static String allRefNames(List<Ref> refs) { StringBuilder sb = new StringBuilder(); for (Ref f : refs) { |