summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst/org
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2020-11-25 17:39:25 +0100
committerMatthias Sohn <matthias.sohn@sap.com>2020-11-25 17:40:06 +0100
commit7eec48c444e07ab08ea0411517a4e28461033682 (patch)
tree7a206b11feb73a7cc5c6e468fbf1f9dba8cfee4f /org.eclipse.jgit.test/tst/org
parent2993b2feadd08a993b20ffda91eb4c55f72720a0 (diff)
parentb8441e1e355164527ba6aeb857248190f60524ea (diff)
downloadjgit-7eec48c444e07ab08ea0411517a4e28461033682.tar.gz
jgit-7eec48c444e07ab08ea0411517a4e28461033682.zip
Merge branch 'master' into stable-5.10
* master: Update Orbit to S20201118210000 and add target for 4.18 PacketLineIn: ensure that END != DELIM PacketLineIn: ensure that END != DELIM Allow to resolve a conflict by checking out a file Update Orbit to I20201111205634 Document that setLastModified sets time of symlink target Fix bug in PerformanceLogContext Fix IOException occurring during gc Change-Id: I2980552381d1ae61b9b2d81d7289de37d6bf4cae Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.test/tst/org')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PathCheckoutCommandTest.java13
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheEntryTest.java40
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCachePathEditTest.java28
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcBasicPackingTest.java23
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/logging/PerformanceLogContextTest.java45
5 files changed, 139 insertions, 10 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PathCheckoutCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PathCheckoutCommandTest.java
index e0a1c1d61b..f52b715d39 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PathCheckoutCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PathCheckoutCommandTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2011, Kevin Sawicki <kevin@github.com> and others
+ * Copyright (C) 2011, 2020 Kevin Sawicki <kevin@github.com> and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0 which is available at
@@ -24,6 +24,7 @@ import org.eclipse.jgit.dircache.DirCacheEntry;
import org.eclipse.jgit.errors.NoWorkTreeException;
import org.eclipse.jgit.junit.RepositoryTestCase;
import org.eclipse.jgit.lib.ConfigConstants;
+import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectReader;
import org.eclipse.jgit.lib.RepositoryState;
import org.eclipse.jgit.lib.StoredConfig;
@@ -310,6 +311,16 @@ public class PathCheckoutCommandTest extends RepositoryTestCase {
}
@Test
+ public void testCheckoutFileWithConflict() throws Exception {
+ setupConflictingState();
+ assertEquals('[' + FILE1 + ']',
+ git.status().call().getConflicting().toString());
+ git.checkout().setStartPoint(Constants.HEAD).addPath(FILE1).call();
+ assertEquals("3", read(FILE1));
+ assertTrue(git.status().call().isClean());
+ }
+
+ @Test
public void testCheckoutOursWhenNoBase() throws Exception {
String file = "added.txt";
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheEntryTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheEntryTest.java
index 5477f565f4..8e84dfa318 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheEntryTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheEntryTest.java
@@ -242,6 +242,46 @@ public class DirCacheEntryTest {
}
@Test
+ public void testSetStage() {
+ DirCacheEntry e = new DirCacheEntry("some/path", DirCacheEntry.STAGE_1);
+ e.setAssumeValid(true);
+ e.setCreationTime(2L);
+ e.setFileMode(FileMode.EXECUTABLE_FILE);
+ e.setLastModified(EPOCH.plusMillis(3L));
+ e.setLength(100L);
+ e.setObjectId(ObjectId
+ .fromString("0123456789012345678901234567890123456789"));
+ e.setUpdateNeeded(true);
+ e.setStage(DirCacheEntry.STAGE_2);
+
+ assertTrue(e.isAssumeValid());
+ assertEquals(2L, e.getCreationTime());
+ assertEquals(
+ ObjectId.fromString("0123456789012345678901234567890123456789"),
+ e.getObjectId());
+ assertEquals(FileMode.EXECUTABLE_FILE, e.getFileMode());
+ assertEquals(EPOCH.plusMillis(3L), e.getLastModifiedInstant());
+ assertEquals(100L, e.getLength());
+ assertEquals(DirCacheEntry.STAGE_2, e.getStage());
+ assertTrue(e.isUpdateNeeded());
+ assertEquals("some/path", e.getPathString());
+
+ e.setStage(DirCacheEntry.STAGE_0);
+
+ assertTrue(e.isAssumeValid());
+ assertEquals(2L, e.getCreationTime());
+ assertEquals(
+ ObjectId.fromString("0123456789012345678901234567890123456789"),
+ e.getObjectId());
+ assertEquals(FileMode.EXECUTABLE_FILE, e.getFileMode());
+ assertEquals(EPOCH.plusMillis(3L), e.getLastModifiedInstant());
+ assertEquals(100L, e.getLength());
+ assertEquals(DirCacheEntry.STAGE_0, e.getStage());
+ assertTrue(e.isUpdateNeeded());
+ assertEquals("some/path", e.getPathString());
+ }
+
+ @Test
public void testCopyMetaDataWithStage() {
copyMetaDataHelper(false);
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCachePathEditTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCachePathEditTest.java
index 39a1f01803..5778d28d6f 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCachePathEditTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCachePathEditTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2011, Robin Rosenberg and others
+ * Copyright (C) 2011, 2020 Robin Rosenberg and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0 which is available at
@@ -124,6 +124,32 @@ public class DirCachePathEditTest {
}
@Test
+ public void testPathEditWithStagesAndReset() throws Exception {
+ DirCache dc = DirCache.newInCore();
+ DirCacheBuilder builder = new DirCacheBuilder(dc, 3);
+ builder.add(createEntry("a", DirCacheEntry.STAGE_1));
+ builder.add(createEntry("a", DirCacheEntry.STAGE_2));
+ builder.add(createEntry("a", DirCacheEntry.STAGE_3));
+ builder.finish();
+
+ DirCacheEditor editor = dc.editor();
+ PathEdit edit = new PathEdit("a") {
+
+ @Override
+ public void apply(DirCacheEntry ent) {
+ ent.setStage(DirCacheEntry.STAGE_0);
+ }
+ };
+ editor.add(edit);
+ editor.finish();
+
+ assertEquals(1, dc.getEntryCount());
+ DirCacheEntry entry = dc.getEntry(0);
+ assertEquals("a", entry.getPathString());
+ assertEquals(DirCacheEntry.STAGE_0, entry.getStage());
+ }
+
+ @Test
public void testFileReplacesTree() throws Exception {
DirCache dc = DirCache.newInCore();
DirCacheEditor editor = dc.editor();
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcBasicPackingTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcBasicPackingTest.java
index e8d1cd3d7e..d007dd4511 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcBasicPackingTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcBasicPackingTest.java
@@ -80,6 +80,29 @@ public class GcBasicPackingTest extends GcTestCase {
}
@Theory
+ public void testPack2Commits_noPackFolder(boolean aggressive) throws Exception {
+ File packDir = repo.getObjectDatabase().getPackDirectory();
+ assertTrue(packDir.delete());
+
+ BranchBuilder bb = tr.branch("refs/heads/master");
+ bb.commit().add("A", "A").add("B", "B").create();
+ bb.commit().add("A", "A2").add("B", "B2").create();
+
+ stats = gc.getStatistics();
+ assertEquals(8, stats.numberOfLooseObjects);
+ assertEquals(0, stats.numberOfPackedObjects);
+ configureGc(gc, aggressive);
+ gc.gc();
+ stats = gc.getStatistics();
+ assertEquals(0, stats.numberOfLooseObjects);
+ assertEquals(8, stats.numberOfPackedObjects);
+ assertEquals(1, stats.numberOfPackFiles);
+ assertEquals(2, stats.numberOfBitmaps);
+
+ assertTrue(packDir.exists());
+ }
+
+ @Theory
public void testPackAllObjectsInOnePack(boolean aggressive)
throws Exception {
tr.branch("refs/heads/master").commit().add("A", "A").add("B", "B")
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/logging/PerformanceLogContextTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/logging/PerformanceLogContextTest.java
index e061833d17..f3c1ddec8a 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/logging/PerformanceLogContextTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/logging/PerformanceLogContextTest.java
@@ -1,6 +1,7 @@
package org.eclipse.jgit.logging;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
@@ -37,30 +38,58 @@ public class PerformanceLogContextTest {
}
@Test
- public void testAddEventsTwoThreads() {
- TestRunnable thread1 = new TestRunnable("record1", 1);
- TestRunnable thread2 = new TestRunnable("record2", 2);
+ public void testAddEventsTwoThreads() throws InterruptedException {
+ TestRunnable runnable1 = new TestRunnable("record1", 1);
+ TestRunnable runnable2 = new TestRunnable("record2", 2);
- new Thread(thread1).start();
- new Thread(thread2).start();
+ Thread thread1 = new Thread(runnable1);
+ Thread thread2 = new Thread(runnable2);
+
+ thread1.start();
+ thread2.start();
+
+ thread1.join();
+ thread2.join();
+ assertEquals(1, runnable1.getEventRecordsCount());
+ assertEquals(1, runnable2.getEventRecordsCount());
+ assertFalse(runnable1.isThrown());
+ assertFalse(runnable2.isThrown());
}
private static class TestRunnable implements Runnable {
private String name;
+
private long durationMs;
+ private long eventRecordsCount;
+
+ private boolean thrown = false;
+
public TestRunnable(String name, long durationMs) {
this.name = name;
this.durationMs = durationMs;
}
+ public boolean isThrown() {
+ return thrown;
+ }
+
+ public long getEventRecordsCount() {
+ return eventRecordsCount;
+ }
+
@Override
public void run() {
PerformanceLogRecord record = new PerformanceLogRecord(name,
durationMs);
- PerformanceLogContext.getInstance().addEvent(record);
- assertEquals(1, PerformanceLogContext.getInstance()
- .getEventRecords().size());
+ try {
+ PerformanceLogContext.getInstance().addEvent(record);
+ eventRecordsCount = PerformanceLogContext.getInstance()
+ .getEventRecords().size();
+ PerformanceLogContext.getInstance().cleanEvents();
+ } catch (Exception e) {
+ thrown = true;
+ }
}
}
}