aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorThomas Wolf <thomas.wolf@paranor.ch>2020-07-11 15:29:04 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2020-07-17 00:50:24 +0200
commit533272372945e0e5ddbab1502f185c5afd582f19 (patch)
tree5c48124706d65e3bb010b6168826faa6e6cc3b90 /org.eclipse.jgit.test
parent6206a50a46e775df90afad7292d0d264df69bf01 (diff)
downloadjgit-533272372945e0e5ddbab1502f185c5afd582f19.tar.gz
jgit-533272372945e0e5ddbab1502f185c5afd582f19.zip
DiffFormatter: correctly deal with tracked files in ignored folders
In JGit 5.0, the FileTreeIterator was changed to skip ignored folders by default. To catch tracked files inside ignored folders, the tree walk needs to have a DirCacheIterator, and the FileTreeIterator has to know about that DirCacheIterator via setDirCacheIterator(). (Or the optimization has to be switched off explicitly via setWalkIgnoredDirectories(true).) Skipping ignored directories is an important optimization in some cases, for instance in node.js/npm projects, where we'd otherwise traverse the whole huge and deep hierarchy of the typically ignored node_modules folder. While all uses of WorkingTreeIterator in JGit had been adapted, DiffFormatter was forgotten. To make it work correctly (again) also for such cases, make it set up a WorkingTreeeIterator automatically, and make sure the WorkingTreeSource can find such files, too. Also pass the repository to the TreeWalks used inside the DiffFormatter to pick up the correct attributes, filters, and line-ending settings. Bug: 565081 Change-Id: Ie88ac81166dc396ba28b83313964c1712b6ca199 Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffFormatterTest.java56
1 files changed, 55 insertions, 1 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffFormatterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffFormatterTest.java
index a929def2ff..62824d3aec 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffFormatterTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffFormatterTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2010, 2013 Google Inc. and others
+ * Copyright (C) 2010, 2020 Google Inc. 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
@@ -13,12 +13,14 @@ package org.eclipse.jgit.diff;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import org.eclipse.jgit.api.Git;
+import org.eclipse.jgit.api.Status;
import org.eclipse.jgit.diff.DiffEntry.ChangeType;
import org.eclipse.jgit.dircache.DirCacheIterator;
import org.eclipse.jgit.junit.RepositoryTestCase;
@@ -468,6 +470,58 @@ public class DiffFormatterTest extends RepositoryTestCase {
}
@Test
+ public void testTrackedFileInIgnoredFolderUnchanged()
+ throws Exception {
+ commitFile("empty/empty/foo", "", "master");
+ commitFile(".gitignore", "empty/*", "master");
+ try (Git git = new Git(db)) {
+ Status status = git.status().call();
+ assertTrue(status.isClean());
+ }
+ try (ByteArrayOutputStream os = new ByteArrayOutputStream();
+ DiffFormatter dfmt = new DiffFormatter(os)) {
+ dfmt.setRepository(db);
+ dfmt.format(new DirCacheIterator(db.readDirCache()),
+ new FileTreeIterator(db));
+ dfmt.flush();
+
+ String actual = os.toString("UTF-8");
+
+ assertEquals("", actual);
+ }
+ }
+
+ @Test
+ public void testTrackedFileInIgnoredFolderChanged()
+ throws Exception {
+ String expectedDiff = "diff --git a/empty/empty/foo b/empty/empty/foo\n"
+ + "index e69de29..5ea2ed4 100644\n" //
+ + "--- a/empty/empty/foo\n" //
+ + "+++ b/empty/empty/foo\n" //
+ + "@@ -0,0 +1 @@\n" //
+ + "+changed\n";
+
+ commitFile("empty/empty/foo", "", "master");
+ commitFile(".gitignore", "empty/*", "master");
+ try (Git git = new Git(db)) {
+ Status status = git.status().call();
+ assertTrue(status.isClean());
+ }
+ try (ByteArrayOutputStream os = new ByteArrayOutputStream();
+ DiffFormatter dfmt = new DiffFormatter(os)) {
+ writeTrashFile("empty/empty/foo", "changed\n");
+ dfmt.setRepository(db);
+ dfmt.format(new DirCacheIterator(db.readDirCache()),
+ new FileTreeIterator(db));
+ dfmt.flush();
+
+ String actual = os.toString("UTF-8");
+
+ assertEquals(expectedDiff, actual);
+ }
+ }
+
+ @Test
public void testDiffAutoCrlfSmallFile() throws Exception {
String content = "01234\r\n01234\r\n01234\r\n";
String expectedDiff = "diff --git a/test.txt b/test.txt\n"