aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2022-07-06 17:01:03 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2022-07-06 17:02:04 +0200
commit34600e3ca23262ed67555d147fa46892b5a5e67b (patch)
treed1c4362d9df0bf05a27ea7918cfea7da5a58b9c4 /org.eclipse.jgit.test
parent58f5302e1d8c1c7a4111c141bea0533c41129a74 (diff)
parentd01376106af8800017ac3c08d7c7ac1fd5ccc9ee (diff)
downloadjgit-34600e3ca23262ed67555d147fa46892b5a5e67b.tar.gz
jgit-34600e3ca23262ed67555d147fa46892b5a5e67b.zip
Merge branch 'stable-6.1' into stable-6.2
* stable-6.1: UploadPack: don't prematurely terminate timer in case of error Do not create reflog for remote tracking branches during clone UploadPack: do not check reachability of visible SHA1s Add missing package import javax.management to org.eclipse.jgit Change-Id: Ib3ff6a038e1b92a931a7f2624c19bbefd8cb95fd
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java44
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/FetchCommandTest.java20
2 files changed, 64 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 de25870bd0..c928d2ad22 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
@@ -22,6 +22,7 @@ import java.net.URISyntaxException;
import java.util.Collections;
import java.util.List;
import java.util.Map;
+import java.util.stream.Stream;
import org.eclipse.jgit.api.ListBranchCommand.ListMode;
import org.eclipse.jgit.api.errors.GitAPIException;
@@ -115,6 +116,49 @@ public class CloneCommandTest extends RepositoryTestCase {
}
@Test
+ public void testCloneRepository_refLogForLocalRefs()
+ throws IOException, JGitInternalException, GitAPIException {
+ File directory = createTempDirectory("testCloneRepository");
+ CloneCommand command = Git.cloneRepository();
+ command.setDirectory(directory);
+ command.setURI(fileUri());
+ Git git2 = command.call();
+ Repository clonedRepo = git2.getRepository();
+ addRepoToClose(clonedRepo);
+
+ List<Ref> clonedRefs = clonedRepo.getRefDatabase().getRefs();
+ Stream<Ref> remoteRefs = clonedRefs.stream()
+ .filter(CloneCommandTest::isRemote);
+ Stream<Ref> localHeadsRefs = clonedRefs.stream()
+ .filter(CloneCommandTest::isLocalHead);
+
+ remoteRefs.forEach(ref -> assertFalse(
+ "Ref " + ref.getName()
+ + " is remote and should not have a reflog",
+ hasRefLog(clonedRepo, ref)));
+ localHeadsRefs.forEach(ref -> assertTrue(
+ "Ref " + ref.getName()
+ + " is local head and should have a reflog",
+ hasRefLog(clonedRepo, ref)));
+ }
+
+ private static boolean isRemote(Ref ref) {
+ return ref.getName().startsWith(Constants.R_REMOTES);
+ }
+
+ private static boolean isLocalHead(Ref ref) {
+ return !isRemote(ref) && ref.getName().startsWith(Constants.R_HEADS);
+ }
+
+ private static boolean hasRefLog(Repository repo, Ref ref) {
+ try {
+ return repo.getReflogReader(ref.getName()).getLastEntry() != null;
+ } catch (IOException ioe) {
+ throw new IllegalStateException(ioe);
+ }
+ }
+
+ @Test
public void testCloneRepositoryExplicitGitDir() throws IOException,
JGitInternalException, GitAPIException {
File directory = createTempDirectory("testCloneRepository");
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/FetchCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/FetchCommandTest.java
index 0884d72235..3ec454cfc3 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/FetchCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/FetchCommandTest.java
@@ -77,6 +77,26 @@ public class FetchCommandTest extends RepositoryTestCase {
}
@Test
+ public void testFetchHasRefLogForRemoteRef() throws Exception {
+ // create an initial commit SHA1 for the default branch
+ ObjectId defaultBranchSha1 = remoteGit.commit()
+ .setMessage("initial commit").call().getId();
+
+ git.fetch().setRemote("test")
+ .setRefSpecs("refs/heads/*:refs/remotes/origin/*").call();
+
+ List<Ref> allFetchedRefs = git.getRepository().getRefDatabase()
+ .getRefs();
+ assertEquals(allFetchedRefs.size(), 1);
+ Ref remoteRef = allFetchedRefs.get(0);
+
+ assertTrue(remoteRef.getName().startsWith(Constants.R_REMOTES));
+ assertEquals(defaultBranchSha1, remoteRef.getObjectId());
+ assertNotNull(git.getRepository().getReflogReader(remoteRef.getName())
+ .getLastEntry());
+ }
+
+ @Test
public void testForcedFetch() throws Exception {
remoteGit.commit().setMessage("commit").call();
remoteGit.commit().setMessage("commit2").call();