Merge branch 'stable-4.2'

* stable-4.2:
  Don't use deprecated LockFile constructor
  Fix warnings about unchecked conversion of MergeResult
  MockServletConfig: Fix warning about unchecked conversion of Enumeration
  HugeFileTest: Make Git a class member and open in try-with-resource
  Suppress "unchecked cast" warnings related to UploadPackFactory.DISABLED
  DiffAlgorithms: Fix warnings about variable hiding
  DirCacheBasicTest: Open ObjectInserter.Formatter in try-with-resource
  DirCacheBuilderIteratorTest: Open TreeWalk in try-with-resource
  DirCacheCGitCompatabilityTest: Open TreeWalk in try-with-resource
  DirCacheCheckoutMaliciousPathTest: Open Git and RevWalk in t-w-r
  DirCacheIteratorTest: Open TreeWalk instances in try-with-resource
  ForPathTest: Open TreeWalk in try-with-resource
  GitConstructionTest: Open Git instance in try-with-resource
  IndexDiffTest: Open Git instances in try-with-resources
  ManifestParserTest: Don't use deprecated StringBufferInputStream
  InMemoryRepository: Remove unused RevWalk from batch method signature
  IndexModificationTimesTest: Open Git instances in try-with-resource
  InterIndexDiffFilterTest: Open TreeWalk in try-with-resource
  LockFileTest: Open Git instance in try-with-resource
  JGit v4.1.2.201602141800-r
  MergeCommandTest: Use JUnit's assume to check preconditions
  MergeCommandTest: Open Git instances in try-with-resource

Change-Id: Ie5dba6b9132a29e86958a04fa2b76465bcd2c6b5
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
This commit is contained in:
Matthias Sohn 2016-02-15 23:27:28 +01:00
commit 514b11ddcc
32 changed files with 1720 additions and 1679 deletions

View File

@ -79,6 +79,7 @@ public void setUp() throws Exception {
factory = new DefaultReceivePackFactory();
}
@SuppressWarnings("unchecked")
@Test
public void testDisabledSingleton() throws ServiceNotAuthorizedException {
factory = (ReceivePackFactory<HttpServletRequest>) ReceivePackFactory.DISABLED;

View File

@ -77,6 +77,7 @@ public void setUp() throws Exception {
factory = new DefaultUploadPackFactory();
}
@SuppressWarnings("unchecked")
@Test
public void testDisabledSingleton() throws ServiceNotAuthorizedException {
factory = (UploadPackFactory<HttpServletRequest>) UploadPackFactory.DISABLED;

View File

@ -62,7 +62,7 @@ public String getInitParameter(String name) {
return parameters.get(name);
}
public Enumeration getInitParameterNames() {
public Enumeration<String> getInitParameterNames() {
final Iterator<String> i = parameters.keySet().iterator();
return new Enumeration<String>() {
public boolean hasMoreElements() {

View File

@ -905,7 +905,7 @@ private static File nameFor(ObjectDirectory odb, ObjectId name, String t) {
private void writeFile(final File p, final byte[] bin) throws IOException,
ObjectWritingException {
final LockFile lck = new LockFile(p, db.getFS());
final LockFile lck = new LockFile(p);
if (!lck.lock())
throw new ObjectWritingException("Can't write " + p);
try {

View File

@ -155,16 +155,16 @@ protected void run() throws Exception {
else
rb.findGitDir(dir);
Repository db = rb.build();
Repository repo = rb.build();
try {
run(db);
run(repo);
} finally {
db.close();
repo.close();
}
}
}
private void run(Repository db) throws Exception {
private void run(Repository repo) throws Exception {
List<Test> all = init();
long files = 0;
@ -173,14 +173,14 @@ private void run(Repository db) throws Exception {
int maxN = 0;
AbbreviatedObjectId startId;
try (ObjectReader or = db.newObjectReader();
try (ObjectReader or = repo.newObjectReader();
RevWalk rw = new RevWalk(or)) {
final MutableObjectId id = new MutableObjectId();
TreeWalk tw = new TreeWalk(or);
tw.setFilter(TreeFilter.ANY_DIFF);
tw.setRecursive(true);
ObjectId start = db.resolve(Constants.HEAD);
ObjectId start = repo.resolve(Constants.HEAD);
startId = or.abbreviate(start);
rw.markStart(rw.parseCommit(start));
for (;;) {
@ -235,14 +235,15 @@ private void run(Repository db) throws Exception {
Collections.sort(all, new Comparator<Test>() {
public int compare(Test a, Test b) {
int cmp = Long.signum(a.runningTimeNanos - b.runningTimeNanos);
if (cmp == 0)
cmp = a.algorithm.name.compareTo(b.algorithm.name);
return cmp;
int result = Long.signum(a.runningTimeNanos - b.runningTimeNanos);
if (result == 0) {
result = a.algorithm.name.compareTo(b.algorithm.name);
}
return result;
}
});
File directory = db.getDirectory();
File directory = repo.getDirectory();
if (directory != null) {
String name = directory.getName();
File parent = directory.getParentFile();

View File

@ -235,7 +235,7 @@ private void detachHead() throws IOException {
final ObjectId id = db.resolve(Constants.HEAD);
if (!ObjectId.isId(head) && id != null) {
final LockFile lf;
lf = new LockFile(new File(db.getDirectory(), Constants.HEAD), db.getFS());
lf = new LockFile(new File(db.getDirectory(), Constants.HEAD));
if (!lf.lock())
throw new IOException(MessageFormat.format(CLIText.get().cannotLock, Constants.HEAD));
lf.write(id);
@ -263,7 +263,7 @@ private void recreateRefs() throws Exception {
protected void writeFile(final String name, final byte[] content)
throws IOException {
final File file = new File(db.getDirectory(), name);
final LockFile lck = new LockFile(file, db.getFS());
final LockFile lck = new LockFile(file);
if (!lck.lock())
throw new ObjectWritingException(MessageFormat.format(CLIText.get().cantWrite, file));
try {

View File

@ -66,11 +66,12 @@ public class GitConstructionTest extends RepositoryTestCase {
@Before
public void setUp() throws Exception {
super.setUp();
Git git = new Git(db);
try (Git git = new Git(db)) {
git.commit().setMessage("initial commit").call();
writeTrashFile("Test.txt", "Hello world");
git.add().addFilepattern("Test.txt").call();
git.commit().setMessage("Initial commit").call();
}
bareRepo = Git.cloneRepository().setBare(true)
.setURI(db.getDirectory().toURI().toString())

View File

@ -51,6 +51,8 @@
import org.eclipse.jgit.api.ResetCommand.ResetType;
import org.eclipse.jgit.junit.RepositoryTestCase;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
@ -60,12 +62,26 @@ public class HugeFileTest extends RepositoryTestCase {
private long lastt = t;
private Git git;
private void measure(String name) {
long c = System.currentTimeMillis();
System.out.println(name + ", dt=" + (c - lastt) / 1000.0 + "s");
lastt = c;
}
@Before
public void before() {
git = new Git(db);
}
@After
public void after() {
if (git != null) {
git.close();
}
}
@Ignore("Test takes way too long (~10 minutes) to be part of the standard suite")
@Test
public void testAddHugeFile() throws Exception {
@ -75,7 +91,6 @@ public void testAddHugeFile() throws Exception {
rf.setLength(4429185024L);
rf.close();
measure("Created file");
Git git = new Git(db);
git.add().addFilepattern("a.txt").call();
measure("Added file");

View File

@ -50,6 +50,7 @@
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeTrue;
import java.io.File;
import java.util.Iterator;
@ -96,11 +97,12 @@ public void setUp() throws Exception {
@Test
public void testMergeInItself() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
git.commit().setMessage("initial commit").call();
MergeResult result = git.merge().include(db.exactRef(Constants.HEAD)).call();
assertEquals(MergeResult.MergeStatus.ALREADY_UP_TO_DATE, result.getMergeStatus());
}
// no reflog entry written by merge
assertEquals("commit (initial): initial commit",
db
@ -112,7 +114,7 @@ public void testMergeInItself() throws Exception {
@Test
public void testAlreadyUpToDate() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
RevCommit first = git.commit().setMessage("initial commit").call();
createBranch(first, "refs/heads/branch1");
@ -120,6 +122,7 @@ public void testAlreadyUpToDate() throws Exception {
MergeResult result = git.merge().include(db.exactRef("refs/heads/branch1")).call();
assertEquals(MergeResult.MergeStatus.ALREADY_UP_TO_DATE, result.getMergeStatus());
assertEquals(second, result.getNewHead());
}
// no reflog entry written by merge
assertEquals("commit: second commit", db
.getReflogReader(Constants.HEAD).getLastEntry().getComment());
@ -129,7 +132,7 @@ public void testAlreadyUpToDate() throws Exception {
@Test
public void testFastForward() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
RevCommit first = git.commit().setMessage("initial commit").call();
createBranch(first, "refs/heads/branch1");
@ -141,6 +144,7 @@ public void testFastForward() throws Exception {
assertEquals(MergeResult.MergeStatus.FAST_FORWARD, result.getMergeStatus());
assertEquals(second, result.getNewHead());
}
assertEquals("merge refs/heads/master: Fast-forward",
db.getReflogReader(Constants.HEAD).getLastEntry().getComment());
assertEquals("merge refs/heads/master: Fast-forward",
@ -149,7 +153,7 @@ public void testFastForward() throws Exception {
@Test
public void testFastForwardNoCommit() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
RevCommit first = git.commit().setMessage("initial commit").call();
createBranch(first, "refs/heads/branch1");
@ -163,6 +167,7 @@ public void testFastForwardNoCommit() throws Exception {
assertEquals(MergeResult.MergeStatus.FAST_FORWARD,
result.getMergeStatus());
assertEquals(second, result.getNewHead());
}
assertEquals("merge refs/heads/master: Fast-forward", db
.getReflogReader(Constants.HEAD).getLastEntry().getComment());
assertEquals("merge refs/heads/master: Fast-forward", db
@ -171,8 +176,7 @@ public void testFastForwardNoCommit() throws Exception {
@Test
public void testFastForwardWithFiles() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("file1", "file1");
git.add().addFilepattern("file1").call();
RevCommit first = git.commit().setMessage("initial commit").call();
@ -194,6 +198,7 @@ public void testFastForwardWithFiles() throws Exception {
assertTrue(new File(db.getWorkTree(), "file2").exists());
assertEquals(MergeResult.MergeStatus.FAST_FORWARD, result.getMergeStatus());
assertEquals(second, result.getNewHead());
}
assertEquals("merge refs/heads/master: Fast-forward",
db.getReflogReader(Constants.HEAD).getLastEntry().getComment());
assertEquals("merge refs/heads/master: Fast-forward",
@ -202,8 +207,7 @@ public void testFastForwardWithFiles() throws Exception {
@Test
public void testMultipleHeads() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("file1", "file1");
git.add().addFilepattern("file1").call();
RevCommit first = git.commit().setMessage("initial commit").call();
@ -231,12 +235,12 @@ public void testMultipleHeads() throws Exception {
// expected this exception
}
}
}
@Theory
public void testMergeSuccessAllStrategies(MergeStrategy mergeStrategy)
throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
RevCommit first = git.commit().setMessage("first").call();
createBranch(first, "refs/heads/side");
@ -252,6 +256,7 @@ public void testMergeSuccessAllStrategies(MergeStrategy mergeStrategy)
MergeResult result = git.merge().setStrategy(mergeStrategy)
.include(db.exactRef(R_HEADS + MASTER)).call();
assertEquals(MergeStatus.MERGED, result.getMergeStatus());
}
assertEquals(
"merge refs/heads/master: Merge made by "
+ mergeStrategy.getName() + ".",
@ -265,8 +270,7 @@ public void testMergeSuccessAllStrategies(MergeStrategy mergeStrategy)
@Theory
public void testMergeSuccessAllStrategiesNoCommit(
MergeStrategy mergeStrategy) throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
RevCommit first = git.commit().setMessage("first").call();
createBranch(first, "refs/heads/side");
@ -286,11 +290,11 @@ public void testMergeSuccessAllStrategiesNoCommit(
assertEquals(db.exactRef(Constants.HEAD).getTarget().getObjectId(),
thirdCommit.getId());
}
}
@Test
public void testContentMerge() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n");
writeTrashFile("b", "1\nb\n3\n");
writeTrashFile("c/c/c", "1\nc\n3\n");
@ -331,11 +335,11 @@ public void testContentMerge() throws Exception {
assertEquals(RepositoryState.MERGING, db.getRepositoryState());
}
}
@Test
public void testMergeTag() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("a", "a");
git.add().addFilepattern("a").call();
RevCommit initialCommit = git.commit().setMessage("initial").call();
@ -358,11 +362,11 @@ public void testMergeTag() throws Exception {
MergeResult result = git.merge().include(tag).setStrategy(MergeStrategy.RESOLVE).call();
assertEquals(MergeStatus.MERGED, result.getMergeStatus());
}
}
@Test
public void testMergeMessage() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n");
git.add().addFilepattern("a").call();
RevCommit initialCommit = git.commit().setMessage("initial").call();
@ -387,13 +391,13 @@ public void testMergeMessage() throws Exception {
assertEquals("Merge branch 'side'\n\nConflicts:\n\ta\n",
db.readMergeCommitMsg());
}
}
@Test
public void testMergeNonVersionedPaths() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n");
writeTrashFile("b", "1\nb\n3\n");
writeTrashFile("c/c/c", "1\nc\n3\n");
@ -440,11 +444,11 @@ public void testMergeNonVersionedPaths() throws Exception {
assertEquals(RepositoryState.MERGING, db.getRepositoryState());
}
}
@Test
public void testMultipleCreations() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n");
git.add().addFilepattern("a").call();
RevCommit initialCommit = git.commit().setMessage("initial").call();
@ -466,11 +470,11 @@ public void testMultipleCreations() throws Exception {
.setStrategy(MergeStrategy.RESOLVE).call();
assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus());
}
}
@Test
public void testMultipleCreationsSameContent() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n");
git.add().addFilepattern("a").call();
RevCommit initialCommit = git.commit().setMessage("initial").call();
@ -501,11 +505,11 @@ public void testMultipleCreationsSameContent() throws Exception {
.getReflogReader(db.getBranch())
.getLastEntry().getComment());
}
}
@Test
public void testSuccessfulContentMerge() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n");
writeTrashFile("b", "1\nb\n3\n");
writeTrashFile("c/c/c", "1\nc\n3\n");
@ -559,11 +563,11 @@ public void testSuccessfulContentMerge() throws Exception {
assertEquals(RepositoryState.SAFE, db.getRepositoryState());
// test index state
}
}
@Test
public void testSuccessfulContentMergeNoCommit() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n");
writeTrashFile("b", "1\nb\n3\n");
writeTrashFile("c/c/c", "1\nc\n3\n");
@ -609,12 +613,12 @@ public void testSuccessfulContentMergeNoCommit() throws Exception {
assertNull(result.getNewHead());
assertEquals(RepositoryState.MERGING_RESOLVED, db.getRepositoryState());
}
}
@Test
public void testSuccessfulContentMergeAndDirtyworkingTree()
throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n");
writeTrashFile("b", "1\nb\n3\n");
writeTrashFile("d", "1\nd\n3\n");
@ -670,11 +674,11 @@ public void testSuccessfulContentMergeAndDirtyworkingTree()
assertEquals(RepositoryState.SAFE, db.getRepositoryState());
}
}
@Test
public void testSingleDeletion() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n");
writeTrashFile("b", "1\nb\n3\n");
writeTrashFile("d", "1\nd\n3\n");
@ -725,11 +729,11 @@ public void testSingleDeletion() throws Exception {
read(new File(db.getWorkTree(), "c/c/c")));
assertEquals("1\nd\n3\n", read(new File(db.getWorkTree(), "d")));
}
}
@Test
public void testMultipleDeletions() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n");
git.add().addFilepattern("a").call();
RevCommit initialCommit = git.commit().setMessage("initial").call();
@ -754,11 +758,11 @@ public void testMultipleDeletions() throws Exception {
.setStrategy(MergeStrategy.RESOLVE).call();
assertEquals(MergeStatus.MERGED, result.getMergeStatus());
}
}
@Test
public void testDeletionAndConflict() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n");
writeTrashFile("b", "1\nb\n3\n");
writeTrashFile("d", "1\nd\n3\n");
@ -798,11 +802,11 @@ public void testDeletionAndConflict() throws Exception {
read(new File(db.getWorkTree(), "c/c/c")));
assertEquals("1\nd\n3\n", read(new File(db.getWorkTree(), "d")));
}
}
@Test
public void testDeletionOnMasterConflict() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n");
writeTrashFile("b", "1\nb\n3\n");
git.add().addFilepattern("a").addFilepattern("b").call();
@ -830,11 +834,11 @@ public void testDeletionOnMasterConflict() throws Exception {
assertEquals("1\na(side)\n3\n", read(new File(db.getWorkTree(), "a")));
assertEquals("1\nb\n3\n", read(new File(db.getWorkTree(), "b")));
}
}
@Test
public void testDeletionOnSideConflict() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n");
writeTrashFile("b", "1\nb\n3\n");
git.add().addFilepattern("a").addFilepattern("b").call();
@ -864,14 +868,14 @@ public void testDeletionOnSideConflict() throws Exception {
assertEquals(1, result.getConflicts().size());
assertEquals(3, result.getConflicts().get("a")[0].length);
}
}
@Test
public void testModifiedAndRenamed() throws Exception {
// this test is essentially the same as testDeletionOnSideConflict,
// however if once rename support is added this test should result in a
// successful merge instead of a conflict
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("x", "add x");
git.add().addFilepattern("x").call();
RevCommit initial = git.commit().setMessage("add x").call();
@ -903,11 +907,11 @@ public void testModifiedAndRenamed() throws Exception {
assertEquals(1, d2Merge.getConflicts().size());
assertEquals(3, d2Merge.getConflicts().get("x")[0].length);
}
}
@Test
public void testMergeFailingWithDirtyWorkingTree() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n");
writeTrashFile("b", "1\nb\n3\n");
git.add().addFilepattern("a").addFilepattern("b").call();
@ -942,11 +946,11 @@ public void testMergeFailingWithDirtyWorkingTree() throws Exception {
assertEquals(RepositoryState.SAFE, db.getRepositoryState());
}
}
@Test
public void testMergeConflictFileFolder() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n");
writeTrashFile("b", "1\nb\n3\n");
git.add().addFilepattern("a").addFilepattern("b").call();
@ -981,11 +985,11 @@ public void testMergeConflictFileFolder() throws Exception {
assertEquals(RepositoryState.MERGING, db.getRepositoryState());
}
}
@Test
public void testSuccessfulMergeFailsDueToDirtyIndex() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
File fileA = writeTrashFile("a", "a");
RevCommit initialCommit = addAllAndCommit(git);
@ -1017,11 +1021,11 @@ public void testSuccessfulMergeFailsDueToDirtyIndex() throws Exception {
checkMergeFailedResult(result, MergeFailureReason.DIRTY_INDEX,
indexState, fileA);
}
}
@Test
public void testConflictingMergeFailsDueToDirtyIndex() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
File fileA = writeTrashFile("a", "a");
RevCommit initialCommit = addAllAndCommit(git);
@ -1055,11 +1059,11 @@ public void testConflictingMergeFailsDueToDirtyIndex() throws Exception {
checkMergeFailedResult(result, MergeFailureReason.DIRTY_INDEX,
indexState, fileA);
}
}
@Test
public void testSuccessfulMergeFailsDueToDirtyWorktree() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
File fileA = writeTrashFile("a", "a");
RevCommit initialCommit = addAllAndCommit(git);
@ -1090,11 +1094,11 @@ public void testSuccessfulMergeFailsDueToDirtyWorktree() throws Exception {
checkMergeFailedResult(result, MergeFailureReason.DIRTY_WORKTREE,
indexState, fileA);
}
}
@Test
public void testConflictingMergeFailsDueToDirtyWorktree() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
File fileA = writeTrashFile("a", "a");
RevCommit initialCommit = addAllAndCommit(git);
@ -1127,6 +1131,7 @@ public void testConflictingMergeFailsDueToDirtyWorktree() throws Exception {
checkMergeFailedResult(result, MergeFailureReason.DIRTY_WORKTREE,
indexState, fileA);
}
}
@Test
public void testMergeRemovingFolders() throws Exception {
@ -1143,7 +1148,7 @@ public void testMergeRemovingFolders() throws Exception {
file = new File(folder2, "file2.txt");
write(file, "folder2--file2.txt");
Git git = new Git(db);
try (Git git = new Git(db)) {
git.add().addFilepattern(folder1.getName())
.addFilepattern(folder2.getName()).call();
RevCommit commit1 = git.commit().setMessage("adding folders").call();
@ -1167,6 +1172,7 @@ public void testMergeRemovingFolders() throws Exception {
assertFalse(folder1.exists());
assertFalse(folder2.exists());
}
}
@Test
public void testMergeRemovingFoldersWithoutFastForward() throws Exception {
@ -1183,7 +1189,7 @@ public void testMergeRemovingFoldersWithoutFastForward() throws Exception {
file = new File(folder2, "file2.txt");
write(file, "folder2--file2.txt");
Git git = new Git(db);
try (Git git = new Git(db)) {
git.add().addFilepattern(folder1.getName())
.addFilepattern(folder2.getName()).call();
RevCommit base = git.commit().setMessage("adding folders").call();
@ -1212,14 +1218,13 @@ public void testMergeRemovingFoldersWithoutFastForward() throws Exception {
result.getMergeStatus());
assertFalse(folder1.exists());
}
}
@Test
public void testFileModeMerge() throws Exception {
if (!FS.DETECTED.supportsExecute())
return;
// Only Java6
Git git = new Git(db);
assumeTrue(FS.DETECTED.supportsExecute());
try (Git git = new Git(db)) {
writeTrashFile("mergeableMode", "a");
setExecutable(git, "mergeableMode", false);
writeTrashFile("conflictingModeWithBase", "a");
@ -1251,15 +1256,14 @@ public void testFileModeMerge() throws Exception {
assertTrue(canExecute(git, "mergeableMode"));
assertFalse(canExecute(git, "conflictingModeNoBase"));
}
}
@Test
public void testFileModeMergeWithDirtyWorkTree() throws Exception {
if (!FS.DETECTED.supportsExecute())
return;
// Only Java6 (or set x bit in index)
assumeTrue(FS.DETECTED.supportsExecute());
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("mergeableButDirty", "a");
setExecutable(git, "mergeableButDirty", false);
RevCommit initialCommit = addAllAndCommit(git);
@ -1284,11 +1288,11 @@ public void testFileModeMergeWithDirtyWorkTree() throws Exception {
assertEquals(MergeStatus.FAILED, result.getMergeStatus());
assertFalse(canExecute(git, "mergeableButDirty"));
}
}
@Test
public void testSquashFastForward() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("file1", "file1");
git.add().addFilepattern("file1").call();
RevCommit first = git.commit().setMessage("initial commit").call();
@ -1350,11 +1354,11 @@ public void testSquashFastForward() throws Exception {
Status stat = git.status().call();
assertEquals(Sets.of("file2", "file3"), stat.getAdded());
}
}
@Test
public void testSquashMerge() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("file1", "file1");
git.add().addFilepattern("file1").call();
RevCommit first = git.commit().setMessage("initial commit").call();
@ -1408,11 +1412,11 @@ public void testSquashMerge() throws Exception {
Status stat = git.status().call();
assertEquals(Sets.of("file3"), stat.getAdded());
}
}
@Test
public void testSquashMergeConflict() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("file1", "file1");
git.add().addFilepattern("file1").call();
RevCommit first = git.commit().setMessage("initial commit").call();
@ -1464,10 +1468,11 @@ public void testSquashMergeConflict() throws Exception {
Status stat = git.status().call();
assertEquals(Sets.of("file2"), stat.getConflicting());
}
}
@Test
public void testFastForwardOnly() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
RevCommit initialCommit = git.commit().setMessage("initial commit")
.call();
createBranch(initialCommit, "refs/heads/branch1");
@ -1481,10 +1486,11 @@ public void testFastForwardOnly() throws Exception {
assertEquals(MergeStatus.FAST_FORWARD, result.getMergeStatus());
}
}
@Test
public void testNoFastForward() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
RevCommit initialCommit = git.commit().setMessage("initial commit")
.call();
createBranch(initialCommit, "refs/heads/branch1");
@ -1498,11 +1504,12 @@ public void testNoFastForward() throws Exception {
assertEquals(MergeStatus.MERGED, result.getMergeStatus());
}
}
@Test
public void testNoFastForwardNoCommit() throws Exception {
// given
Git git = new Git(db);
try (Git git = new Git(db)) {
RevCommit initialCommit = git.commit().setMessage("initial commit")
.call();
createBranch(initialCommit, "refs/heads/branch1");
@ -1525,10 +1532,11 @@ public void testNoFastForwardNoCommit() throws Exception {
assertNull(result.getNewHead());
assertEquals(RepositoryState.MERGING_RESOLVED, db.getRepositoryState());
}
}
@Test
public void testFastForwardOnlyNotPossible() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
RevCommit initialCommit = git.commit().setMessage("initial commit")
.call();
createBranch(initialCommit, "refs/heads/branch1");
@ -1544,6 +1552,7 @@ public void testFastForwardOnlyNotPossible() throws Exception {
assertEquals(MergeStatus.ABORTED, result.getMergeStatus());
}
}
@Test
public void testRecursiveMergeWithConflict() throws Exception {
@ -1577,8 +1586,7 @@ public void testRecursiveMergeWithConflict() throws Exception {
@Test
public void testMergeWithMessageOption() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n");
git.add().addFilepattern("a").call();
RevCommit initialCommit = git.commit().setMessage("initial").call();
@ -1607,11 +1615,11 @@ public void testMergeWithMessageOption() throws Exception {
RevCommit newHead = it.next();
assertEquals("user message", newHead.getFullMessage());
}
}
@Test
public void testMergeConflictWithMessageOption() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n");
git.add().addFilepattern("a").call();
RevCommit initialCommit = git.commit().setMessage("initial").call();
@ -1637,6 +1645,7 @@ public void testMergeConflictWithMessageOption() throws Exception {
assertEquals("user message\n\nConflicts:\n\ta\n",
db.readMergeCommitMsg());
}
}
private static void setExecutable(Git git, String path, boolean executable) {
FS.DETECTED.setExecute(

View File

@ -255,9 +255,11 @@ public void testRejectInvalidWindowsPaths() throws Exception {
DirCacheBuilder b = dc.builder();
DirCacheEntry e = new DirCacheEntry(path);
e.setFileMode(FileMode.REGULAR_FILE);
e.setObjectId(new ObjectInserter.Formatter().idFor(
try (ObjectInserter.Formatter formatter = new ObjectInserter.Formatter()) {
e.setObjectId(formatter.idFor(
Constants.OBJ_BLOB,
Constants.encode(path)));
}
b.add(e);
b.commit();
db.readDirCache();

View File

@ -78,7 +78,7 @@ public void testPathFilterGroup_DoesNotSkipTail() throws Exception {
final int expIdx = 2;
final DirCacheBuilder b = dc.builder();
final TreeWalk tw = new TreeWalk(db);
try (final TreeWalk tw = new TreeWalk(db)) {
tw.addTree(new DirCacheBuildIterator(b));
tw.setRecursive(true);
tw.setFilter(PathFilterGroup.createFromStrings(Collections
@ -95,6 +95,7 @@ public void testPathFilterGroup_DoesNotSkipTail() throws Exception {
b.add(c.getDirCacheEntry());
assertFalse("no more entries", tw.next());
}
b.finish();
assertEquals(ents.length, dc.getEntryCount());

View File

@ -98,7 +98,7 @@ public void testTreeWalk_LsFiles() throws Exception {
assertEquals(ls.size(), dc.getEntryCount());
{
final Iterator<CGitIndexRecord> rItr = ls.values().iterator();
final TreeWalk tw = new TreeWalk(db);
try (final TreeWalk tw = new TreeWalk(db)) {
tw.setRecursive(true);
tw.addTree(new DirCacheIterator(dc));
while (rItr.hasNext()) {
@ -112,6 +112,7 @@ public void testTreeWalk_LsFiles() throws Exception {
}
}
}
}
@Test
public void testUnsupportedOptionalExtension() throws Exception {

View File

@ -76,10 +76,11 @@ public void testEmptyTree_WithTreeWalk() throws Exception {
final DirCache dc = DirCache.newInCore();
assertEquals(0, dc.getEntryCount());
final TreeWalk tw = new TreeWalk(db);
try (final TreeWalk tw = new TreeWalk(db)) {
tw.addTree(new DirCacheIterator(dc));
assertFalse(tw.next());
}
}
@Test
public void testNoSubtree_NoTreeWalk() throws Exception {
@ -125,7 +126,7 @@ public void testNoSubtree_WithTreeWalk() throws Exception {
b.finish();
final DirCacheIterator i = new DirCacheIterator(dc);
final TreeWalk tw = new TreeWalk(db);
try (final TreeWalk tw = new TreeWalk(db)) {
tw.addTree(i);
int pathIdx = 0;
while (tw.next()) {
@ -139,6 +140,7 @@ public void testNoSubtree_WithTreeWalk() throws Exception {
}
assertEquals(paths.length, pathIdx);
}
}
@Test
public void testSingleSubtree_NoRecursion() throws Exception {
@ -162,7 +164,7 @@ public void testSingleSubtree_NoRecursion() throws Exception {
final int expPos[] = { 0, -1, 4 };
final DirCacheIterator i = new DirCacheIterator(dc);
final TreeWalk tw = new TreeWalk(db);
try (final TreeWalk tw = new TreeWalk(db)) {
tw.addTree(i);
tw.setRecursive(false);
int pathIdx = 0;
@ -183,6 +185,7 @@ public void testSingleSubtree_NoRecursion() throws Exception {
}
assertEquals(expPaths.length, pathIdx);
}
}
@Test
public void testSingleSubtree_Recursive() throws Exception {
@ -202,7 +205,7 @@ public void testSingleSubtree_Recursive() throws Exception {
b.finish();
final DirCacheIterator i = new DirCacheIterator(dc);
final TreeWalk tw = new TreeWalk(db);
try (final TreeWalk tw = new TreeWalk(db)) {
tw.addTree(i);
tw.setRecursive(true);
int pathIdx = 0;
@ -218,6 +221,7 @@ public void testSingleSubtree_Recursive() throws Exception {
}
assertEquals(paths.length, pathIdx);
}
}
@Test
public void testTwoLevelSubtree_Recursive() throws Exception {
@ -236,7 +240,7 @@ public void testTwoLevelSubtree_Recursive() throws Exception {
b.add(ents[i]);
b.finish();
final TreeWalk tw = new TreeWalk(db);
try (final TreeWalk tw = new TreeWalk(db)) {
tw.addTree(new DirCacheIterator(dc));
tw.setRecursive(true);
int pathIdx = 0;
@ -252,6 +256,7 @@ public void testTwoLevelSubtree_Recursive() throws Exception {
}
assertEquals(paths.length, pathIdx);
}
}
@Test
public void testReset() throws Exception {
@ -397,7 +402,7 @@ public void testTwoLevelSubtree_FilterPath() throws Exception {
b.add(ents[i]);
b.finish();
final TreeWalk tw = new TreeWalk(db);
try (final TreeWalk tw = new TreeWalk(db)) {
for (int victimIdx = 0; victimIdx < paths.length; victimIdx++) {
tw.reset();
tw.addTree(new DirCacheIterator(dc));
@ -415,6 +420,7 @@ public void testTwoLevelSubtree_FilterPath() throws Exception {
assertFalse(tw.next());
}
}
}
@Test
public void testRemovedSubtree() throws Exception {
@ -424,7 +430,7 @@ public void testRemovedSubtree() throws Exception {
final DirCache dc = DirCache.read(path, FS.DETECTED);
assertEquals(2, dc.getEntryCount());
final TreeWalk tw = new TreeWalk(db);
try (final TreeWalk tw = new TreeWalk(db)) {
tw.setRecursive(true);
tw.addTree(new DirCacheIterator(dc));
@ -439,3 +445,4 @@ public void testRemovedSubtree() throws Exception {
assertFalse(tw.next());
}
}
}

View File

@ -43,8 +43,9 @@
package org.eclipse.jgit.gitrepo;
import static org.junit.Assert.assertTrue;
import static java.nio.charset.StandardCharsets.UTF_8;
import java.io.StringBufferInputStream;
import java.io.ByteArrayInputStream;
import java.util.HashSet;
import java.util.Set;
@ -77,7 +78,7 @@ public void testManifestParser() throws Exception {
ManifestParser parser = new ManifestParser(
null, null, "master", baseUrl, null, null);
parser.read(new StringBufferInputStream(xmlContent.toString()));
parser.read(new ByteArrayInputStream(xmlContent.toString().getBytes(UTF_8)));
// Unfiltered projects should have them all.
results.clear();
results.add("foo");

View File

@ -118,7 +118,7 @@ public void whileRefLockedRefNotPackedNoError()
tr.lightweightTag("t1", a);
tr.lightweightTag("t2", a);
LockFile refLock = new LockFile(new File(repo.getDirectory(),
"refs/tags/t1"), repo.getFS());
"refs/tags/t1"));
try {
refLock.lock();
gc.packRefs();

View File

@ -61,7 +61,7 @@ public class LockFileTest extends RepositoryTestCase {
@Test
public void lockFailedExceptionRecovery() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("file.txt", "content");
git.add().addFilepattern("file.txt").call();
RevCommit commit1 = git.commit().setMessage("create file").call();
@ -71,7 +71,7 @@ public void lockFailedExceptionRecovery() throws Exception {
git.add().addFilepattern("file.txt").call();
assertNotNull(git.commit().setMessage("edit file").call());
LockFile lf = new LockFile(db.getIndexFile(), db.getFS());
LockFile lf = new LockFile(db.getIndexFile());
assertTrue(lf.lock());
try {
git.checkout().setName(commit1.name()).call();
@ -83,3 +83,4 @@ public void lockFailedExceptionRecovery() throws Exception {
}
}
}
}

View File

@ -597,14 +597,13 @@ public void testUpdateRefLockFailureLocked() throws IOException {
RefUpdate updateRef = db.updateRef("refs/heads/master");
updateRef.setNewObjectId(pid);
LockFile lockFile1 = new LockFile(new File(db.getDirectory(),
"refs/heads/master"), db.getFS());
"refs/heads/master"));
try {
assertTrue(lockFile1.lock()); // precondition to test
Result update = updateRef.update();
assertEquals(Result.LOCK_FAILURE, update);
assertEquals(opid, db.resolve("refs/heads/master"));
LockFile lockFile2 = new LockFile(new File(db.getDirectory(),"refs/heads/master"),
db.getFS());
LockFile lockFile2 = new LockFile(new File(db.getDirectory(),"refs/heads/master"));
assertFalse(lockFile2.lock()); // was locked, still is
} finally {
lockFile1.unlock();
@ -747,8 +746,7 @@ public void tryRenameWhenLocked(String toLock, String fromName,
"logs/" + fromName).exists());
// "someone" has branch X locked
LockFile lockFile = new LockFile(new File(db.getDirectory(), toLock),
db.getFS());
LockFile lockFile = new LockFile(new File(db.getDirectory(), toLock));
try {
assertTrue(lockFile.lock());

View File

@ -338,7 +338,8 @@ private void testMaliciousPathGoodSecondCheckout(String... paths) throws Excepti
*/
private void testMaliciousPath(boolean good, boolean secondCheckout,
String... path) throws GitAPIException, IOException {
Git git = new Git(db);
try (Git git = new Git(db);
RevWalk revWalk = new RevWalk(git.getRepository())) {
ObjectInserter newObjectInserter;
newObjectInserter = git.getRepository().newObjectInserter();
ObjectId blobId = newObjectInserter.insert(Constants.OBJ_BLOB,
@ -379,7 +380,6 @@ private void testMaliciousPath(boolean good, boolean secondCheckout,
commitBuilder.setParentId(firstCommitId);
ObjectId commitId = newObjectInserter.insert(commitBuilder);
RevWalk revWalk = new RevWalk(git.getRepository());
if (!secondCheckout)
git.checkout().setStartPoint(revWalk.parseCommit(firstCommitId))
.setName("refs/heads/master").setCreateBranch(true).call();
@ -402,5 +402,6 @@ private void testMaliciousPath(boolean good, boolean secondCheckout,
assertTrue(e.getMessage().startsWith("Invalid path"));
}
}
}
}

View File

@ -148,8 +148,9 @@ public void testModified() throws IOException, GitAPIException {
writeTrashFile("file2", "file2");
writeTrashFile("dir/file3", "dir/file3");
Git git = new Git(db);
try (Git git = new Git(db)) {
git.add().addFilepattern("file2").addFilepattern("dir/file3").call();
}
writeTrashFile("dir/file3", "changed");
@ -177,8 +178,7 @@ public void testModified() throws IOException, GitAPIException {
@Test
public void testConflicting() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n");
writeTrashFile("b", "1\nb\n3\n");
git.add().addFilepattern("a").addFilepattern("b").call();
@ -202,6 +202,7 @@ public void testConflicting() throws Exception {
MergeResult result = git.merge().include(secondCommit.getId())
.setStrategy(MergeStrategy.RESOLVE).call();
assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus());
}
FileTreeIterator iterator = new FileTreeIterator(db);
IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator);
@ -221,8 +222,7 @@ public void testConflicting() throws Exception {
@Test
public void testConflictingDeletedAndModified() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n");
writeTrashFile("b", "1\nb\n3\n");
git.add().addFilepattern("a").addFilepattern("b").call();
@ -244,6 +244,7 @@ public void testConflictingDeletedAndModified() throws Exception {
MergeResult result = git.merge().include(secondCommit.getId())
.setStrategy(MergeStrategy.RESOLVE).call();
assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus());
}
FileTreeIterator iterator = new FileTreeIterator(db);
IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator);
@ -262,8 +263,7 @@ public void testConflictingDeletedAndModified() throws Exception {
@Test
public void testConflictingFromMultipleCreations() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n");
git.add().addFilepattern("a").call();
RevCommit initialCommit = git.commit().setMessage("initial").call();
@ -284,6 +284,7 @@ public void testConflictingFromMultipleCreations() throws Exception {
MergeResult result = git.merge().include(secondCommit.getId())
.setStrategy(MergeStrategy.RESOLVE).call();
assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus());
}
FileTreeIterator iterator = new FileTreeIterator(db);
IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator);
@ -304,11 +305,12 @@ public void testUnchangedSimple() throws IOException, GitAPIException {
writeTrashFile("a.c", "a.c");
writeTrashFile("a=c", "a=c");
writeTrashFile("a=d", "a=d");
Git git = new Git(db);
try (Git git = new Git(db)) {
git.add().addFilepattern("a.b").call();
git.add().addFilepattern("a.c").call();
git.add().addFilepattern("a=c").call();
git.add().addFilepattern("a=d").call();
}
TreeFormatter tree = new TreeFormatter();
// got the hash id'd from the data using echo -n a.b|git hash-object -t blob --stdin
@ -338,7 +340,6 @@ public void testUnchangedSimple() throws IOException, GitAPIException {
*/
@Test
public void testUnchangedComplex() throws IOException, GitAPIException {
Git git = new Git(db);
writeTrashFile("a.b", "a.b");
writeTrashFile("a.c", "a.c");
writeTrashFile("a/b.b/b", "a/b.b/b");
@ -346,10 +347,12 @@ public void testUnchangedComplex() throws IOException, GitAPIException {
writeTrashFile("a/c", "a/c");
writeTrashFile("a=c", "a=c");
writeTrashFile("a=d", "a=d");
try (Git git = new Git(db)) {
git.add().addFilepattern("a.b").addFilepattern("a.c")
.addFilepattern("a/b.b/b").addFilepattern("a/b")
.addFilepattern("a/c").addFilepattern("a=c")
.addFilepattern("a=d").call();
}
// got the hash id'd from the data using echo -n a.b|git hash-object -t blob --stdin
@ -397,11 +400,12 @@ private ObjectId insertTree(TreeFormatter tree) throws IOException {
*/
@Test
public void testRemovedUntracked() throws Exception{
Git git = new Git(db);
String path = "file";
try (Git git = new Git(db)) {
writeTrashFile(path, "content");
git.add().addFilepattern(path).call();
git.commit().setMessage("commit").call();
}
removeFromIndex(path);
FileTreeIterator iterator = new FileTreeIterator(db);
IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator);
@ -417,8 +421,7 @@ public void testRemovedUntracked() throws Exception{
*/
@Test
public void testUntrackedFolders() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
IndexDiff diff = new IndexDiff(db, Constants.HEAD,
new FileTreeIterator(db));
diff.diff();
@ -463,6 +466,7 @@ public void testUntrackedFolders() throws Exception {
"target")),
diff.getUntrackedFolders());
}
}
/**
* Test that ignored folders aren't listed as untracked
@ -471,8 +475,7 @@ public void testUntrackedFolders() throws Exception {
*/
@Test
public void testUntrackedNotIgnoredFolders() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
IndexDiff diff = new IndexDiff(db, Constants.HEAD,
new FileTreeIterator(db));
diff.diff();
@ -510,10 +513,11 @@ public void testUntrackedNotIgnoredFolders() throws Exception {
"target")),
diff.getUntrackedFolders());
}
}
@Test
public void testAssumeUnchanged() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
String path = "file";
writeTrashFile(path, "content");
git.add().addFilepattern(path).call();
@ -551,6 +555,7 @@ public void testAssumeUnchanged() throws Exception {
assertTrue(diff.getChanged().contains("file"));
assertEquals(Collections.EMPTY_SET, diff.getUntrackedFolders());
}
}
@Test
public void testStageState() throws IOException {
@ -575,8 +580,7 @@ public void testStageState() throws IOException {
@Test
public void testStageState_mergeAndReset_bug() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("a", "content");
git.add().addFilepattern("a").call();
RevCommit initialCommit = git.commit().setMessage("initial commit")
@ -635,11 +639,11 @@ public void testStageState_mergeAndReset_bug() throws Exception {
.get("b"));
assertTrue(diff.getUntrackedFolders().isEmpty());
}
}
@Test
public void testStageState_simulated_bug() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("a", "content");
git.add().addFilepattern("a").call();
RevCommit initialCommit = git.commit().setMessage("initial commit")
@ -688,10 +692,11 @@ public void testStageState_simulated_bug() throws Exception {
.get("b"));
assertTrue(diff.getUntrackedFolders().isEmpty());
}
}
@Test
public void testAutoCRLFInput() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
FileBasedConfig config = db.getConfig();
// Make sure core.autocrlf is false before adding
@ -717,6 +722,7 @@ public void testAutoCRLFInput() throws Exception {
"Expected no modified files, but there were: "
+ diff.getModified(), diff.getModified().isEmpty());
}
}
private void verifyStageState(StageState expected, int... stages)
throws IOException {

View File

@ -49,7 +49,7 @@ public class IndexModificationTimesTest extends RepositoryTestCase {
@Test
public void testLastModifiedTimes() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
String path = "file";
writeTrashFile(path, "content");
String path2 = "file2";
@ -83,10 +83,11 @@ public void testLastModifiedTimes() throws Exception {
assertTrue("last modified shall not be zero!",
entry2.getLastModified() != 0);
}
}
@Test
public void testModify() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
String path = "file";
writeTrashFile(path, "content");
@ -122,7 +123,7 @@ public void testModify() throws Exception {
assertTrue("shall have equal mod time!", masterLastMod == sideLastMode);
assertTrue("shall not equal master timestamp!",
entry.getLastModified() == masterLastMod);
}
}
}

View File

@ -259,7 +259,7 @@ public void testEmptyTexts() throws IOException {
}
private String merge(String commonBase, String ours, String theirs) throws IOException {
MergeResult r = new MergeAlgorithm().merge(RawTextComparator.DEFAULT,
MergeResult<RawText> r = new MergeAlgorithm().merge(RawTextComparator.DEFAULT,
T(commonBase), T(ours), T(theirs));
ByteArrayOutputStream bo=new ByteArrayOutputStream(50);
fmt.formatMerge(bo, r, "B", "O", "T", Constants.CHARACTER_ENCODING);

View File

@ -84,10 +84,10 @@ public void testFindObjects() throws Exception {
ObjectId tree = tree0.writeTree(oi);
// Find the directories that were implicitly created above.
TreeWalk tw = new TreeWalk(or);
tw.addTree(tree);
ObjectId a = null;
ObjectId aSlashC = null;
try (TreeWalk tw = new TreeWalk(or)) {
tw.addTree(tree);
while (tw.next()) {
if (tw.getPathString().equals("a")) {
a = tw.getObjectId(0);
@ -101,6 +101,7 @@ public void testFindObjects() throws Exception {
break;
}
}
}
assertEquals(a, TreeWalk.forPath(or, "a", tree).getObjectId(0));
assertEquals(a, TreeWalk.forPath(or, "a/", tree).getObjectId(0));

View File

@ -76,11 +76,12 @@ public void setUp() throws Exception {
public void testEmpty() throws IOException {
DirCache dc1 = DirCache.newInCore();
DirCache dc2 = DirCache.newInCore();
TreeWalk tw = new TreeWalk(db);
try (TreeWalk tw = new TreeWalk(db)) {
tw.addTree(new DirCacheIterator(dc1));
tw.addTree(new DirCacheIterator(dc2));
assertFalse(tw.next());
}
}
static final class AddEdit extends PathEdit {
@ -124,7 +125,7 @@ public void testOneOnly() throws IOException {
editor.add(new AddEdit("a/a", FileMode.REGULAR_FILE, id("a"), 1, false));
editor.finish();
TreeWalk tw = new TreeWalk(db);
try (TreeWalk tw = new TreeWalk(db)) {
tw.setRecursive(true);
tw.addTree(new DirCacheIterator(dc1));
tw.addTree(new DirCacheIterator(dc2));
@ -133,6 +134,7 @@ public void testOneOnly() throws IOException {
assertEquals("a/a", tw.getPathString());
assertFalse(tw.next());
}
}
@Test
public void testTwoSame() throws IOException {
@ -145,7 +147,7 @@ public void testTwoSame() throws IOException {
ed2.add(new AddEdit("a/a", FileMode.REGULAR_FILE, id("a"), 1, false));
ed2.finish();
TreeWalk tw = new TreeWalk(db);
try (TreeWalk tw = new TreeWalk(db)) {
tw.setRecursive(true);
tw.addTree(new DirCacheIterator(dc1));
tw.addTree(new DirCacheIterator(dc2));
@ -153,6 +155,7 @@ public void testTwoSame() throws IOException {
assertFalse(tw.next());
}
}
@Test
public void testTwoSameDifferByAssumeValid() throws IOException {
@ -165,7 +168,7 @@ public void testTwoSameDifferByAssumeValid() throws IOException {
ed2.add(new AddEdit("a/a", FileMode.REGULAR_FILE, id("a"), 1, true));
ed2.finish();
TreeWalk tw = new TreeWalk(db);
try (TreeWalk tw = new TreeWalk(db)) {
tw.setRecursive(true);
tw.addTree(new DirCacheIterator(dc1));
tw.addTree(new DirCacheIterator(dc2));
@ -175,6 +178,7 @@ public void testTwoSameDifferByAssumeValid() throws IOException {
assertEquals("a/a", tw.getPathString());
assertFalse(tw.next());
}
}
@Test
public void testTwoSameSameAssumeValidDifferentContent()
@ -188,7 +192,7 @@ public void testTwoSameSameAssumeValidDifferentContent()
ed2.add(new AddEdit("a/a", FileMode.REGULAR_FILE, id("b"), 1, true));
ed2.finish();
TreeWalk tw = new TreeWalk(db);
try (TreeWalk tw = new TreeWalk(db)) {
tw.setRecursive(true);
tw.addTree(new DirCacheIterator(dc1));
tw.addTree(new DirCacheIterator(dc2));
@ -197,3 +201,4 @@ public void testTwoSameSameAssumeValidDifferentContent()
assertFalse(tw.next());
}
}
}

View File

@ -344,9 +344,6 @@ public static DirCache lock(final File indexLocation, final FS fs,
/** Our active lock (if we hold it); null if we don't have it locked. */
private LockFile myLock;
/** file system abstraction **/
private final FS fs;
/** Keep track of whether the index has changed or not */
private FileSnapshot snapshot;
@ -376,7 +373,6 @@ public static DirCache lock(final File indexLocation, final FS fs,
*/
public DirCache(final File indexLocation, final FS fs) {
liveFile = indexLocation;
this.fs = fs;
clear();
}
@ -611,7 +607,7 @@ private static boolean is_DIRC(final byte[] hdr) {
public boolean lock() throws IOException {
if (liveFile == null)
throw new IOException(JGitText.get().dirCacheDoesNotHaveABackingFile);
final LockFile tmp = new LockFile(liveFile, fs);
final LockFile tmp = new LockFile(liveFile);
if (tmp.lock()) {
tmp.setNeedStatInformation(true);
myLock = tmp;

View File

@ -274,7 +274,7 @@ public void execute(RevWalk walk, ProgressMonitor monitor)
if (performsAtomicTransactions()) {
try {
lock.writeLock().lock();
batch(walk, getCommands());
batch(getCommands());
} finally {
lock.writeLock().unlock();
}
@ -304,7 +304,7 @@ protected RefCache scanAllRefs() throws IOException {
return new RefCache(ids.toRefList(), sym.toRefList());
}
private void batch(RevWalk walk, List<ReceiveCommand> cmds) {
private void batch(List<ReceiveCommand> cmds) {
// Validate that the target exists in a new RevWalk, as the RevWalk
// from the RefUpdate might be reading back unflushed objects.
Map<ObjectId, ObjectId> peeled = new HashMap<>();

View File

@ -354,7 +354,7 @@ && getDirectory().getName().startsWith(".")) //$NON-NLS-1$
ConfigConstants.CONFIG_KEY_WORKTREE, getWorkTree()
.getAbsolutePath());
LockFile dotGitLockFile = new LockFile(new File(workTree,
Constants.DOT_GIT), getFS());
Constants.DOT_GIT));
try {
if (dotGitLockFile.lock()) {
dotGitLockFile.write(Constants.encode(Constants.GITDIR

View File

@ -53,7 +53,6 @@
/** Keeps track of a {@link PackFile}'s associated <code>.keep</code> file. */
public class PackLock {
private final File keepFile;
private final FS fs;
/**
* Create a new lock for a pack file.
@ -67,7 +66,6 @@ public PackLock(final File packFile, final FS fs) {
final File p = packFile.getParentFile();
final String n = packFile.getName();
keepFile = new File(p, n.substring(0, n.length() - 5) + ".keep"); //$NON-NLS-1$
this.fs = fs;
}
/**
@ -84,7 +82,7 @@ public boolean lock(String msg) throws IOException {
return false;
if (!msg.endsWith("\n")) //$NON-NLS-1$
msg += "\n"; //$NON-NLS-1$
final LockFile lf = new LockFile(keepFile, fs);
final LockFile lf = new LockFile(keepFile);
if (!lf.lock())
return false;
lf.write(Constants.encode(msg));

View File

@ -588,8 +588,7 @@ void delete(RefDirectoryUpdate update) throws IOException {
// we don't miss an edit made externally.
final PackedRefList packed = getPackedRefs();
if (packed.contains(name)) {
LockFile lck = new LockFile(packedRefsFile,
update.getRepository().getFS());
LockFile lck = new LockFile(packedRefsFile);
if (!lck.lock())
throw new LockFailedException(packedRefsFile);
try {
@ -639,7 +638,7 @@ public void pack(List<String> refs) throws IOException {
FS fs = parent.getFS();
// Lock the packed refs file and read the content
LockFile lck = new LockFile(packedRefsFile, fs);
LockFile lck = new LockFile(packedRefsFile);
if (!lck.lock())
throw new IOException(MessageFormat.format(
JGitText.get().cannotLock, packedRefsFile));
@ -670,8 +669,7 @@ public void pack(List<String> refs) throws IOException {
File refFile = fileFor(refName);
if (!fs.exists(refFile))
continue;
LockFile rLck = new LockFile(refFile,
parent.getFS());
LockFile rLck = new LockFile(refFile);
if (!rLck.lock())
continue;
try {

View File

@ -79,7 +79,7 @@ protected boolean tryLock(boolean deref) throws IOException {
if (deref)
dst = dst.getLeaf();
String name = dst.getName();
lock = new LockFile(database.fileFor(name), getRepository().getFS());
lock = new LockFile(database.fileFor(name));
if (lock.lock()) {
dst = database.getRef(name);
setOldObjectId(dst != null ? dst.getObjectId() : null);

View File

@ -102,7 +102,7 @@ public void formatMerge(OutputStream out, MergeResult<RawText> res,
* metadata
* @throws IOException
*/
public void formatMerge(OutputStream out, MergeResult res, String baseName,
public void formatMerge(OutputStream out, MergeResult<RawText> res, String baseName,
String oursName, String theirsName, String charsetName) throws IOException {
List<String> names = new ArrayList<String>(3);
names.add(baseName);

View File

@ -74,8 +74,6 @@
public class FileBasedConfig extends StoredConfig {
private final File configFile;
private final FS fs;
private boolean utf8Bom;
private volatile FileSnapshot snapshot;
@ -109,7 +107,6 @@ public FileBasedConfig(File cfgLocation, FS fs) {
public FileBasedConfig(Config base, File cfgLocation, FS fs) {
super(base);
configFile = cfgLocation;
this.fs = fs;
this.snapshot = FileSnapshot.DIRTY;
this.hash = ObjectId.zeroId();
}
@ -203,7 +200,7 @@ public void save() throws IOException {
out = Constants.encode(text);
}
final LockFile lf = new LockFile(getFile(), fs);
final LockFile lf = new LockFile(getFile());
if (!lf.lock())
throw new LockFailedException(getFile());
try {

View File

@ -314,8 +314,7 @@ private void updateFETCH_HEAD(final FetchResult result) throws IOException {
File meta = transport.local.getDirectory();
if (meta == null)
return;
final LockFile lock = new LockFile(new File(meta, "FETCH_HEAD"), //$NON-NLS-1$
transport.local.getFS());
final LockFile lock = new LockFile(new File(meta, "FETCH_HEAD")); //$NON-NLS-1$
try {
if (lock.lock()) {
final Writer w = new OutputStreamWriter(lock.getOutputStream());