diff options
author | Thomas Wolf <twolf@apache.org> | 2023-06-15 22:08:06 +0200 |
---|---|---|
committer | Thomas Wolf <twolf@apache.org> | 2023-06-19 08:19:29 +0200 |
commit | faefa90f990858db7bec199501cb37f2631c43d0 (patch) | |
tree | 0a0500f2e2cd11b8582ee01a4582f5dcaa756bc2 /org.eclipse.jgit.junit | |
parent | 7b955048eb86e1c12114554beacb27b329252b15 (diff) | |
download | jgit-faefa90f990858db7bec199501cb37f2631c43d0.tar.gz jgit-faefa90f990858db7bec199501cb37f2631c43d0.zip |
Default for global (user) git ignore file
C git has a default for git config core.excludesfile: "Its default
value is $XDG_CONFIG_HOME/git/ignore. If $XDG_CONFIG_HOME is either
not set or empty, $HOME/.config/git/ignore is used instead." [1]
Implement this in the WorkingTreeIterator$RootIgnoreNode.
To make this testable, mock the "user.home" directory for all JGit
tests, otherwise tests might pick up a real user's git ignore file.
Also ensure that JGit code always reads "user.home" via the
SystemReader.
Add tests for both locations.
[1] https://git-scm.com/docs/gitignore#_description
Bug: 436127
Change-Id: Ie510259320286c3c13a6464a37da1bd9ca1e373a
Signed-off-by: Thomas Wolf <twolf@apache.org>
Diffstat (limited to 'org.eclipse.jgit.junit')
-rw-r--r-- | org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java index 0945327ab3..f816158b10 100644 --- a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java +++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java @@ -85,6 +85,8 @@ public abstract class LocalDiskRepositoryTestCase { private final Set<Repository> toClose = new HashSet<>(); private File tmp; + private File homeDir; + /** * The current test name. * @@ -119,6 +121,14 @@ public abstract class LocalDiskRepositoryTestCase { mockSystemReader = new MockSystemReader(); SystemReader.setInstance(mockSystemReader); + // Mock the home directory. We don't want to pick up the real user's git + // config, or global git ignore. + // XDG_CONFIG_HOME isn't set in the MockSystemReader. + mockSystemReader.setProperty("user.home", tmp.getAbsolutePath()); + mockSystemReader.setProperty("HOME", tmp.getAbsolutePath()); + homeDir = FS.DETECTED.userHome(); + FS.DETECTED.setUserHome(tmp.getAbsoluteFile()); + // Measure timer resolution before the test to avoid time critical tests // are affected by time needed for measurement. // The MockSystemReader must be configured first since we need to use @@ -195,21 +205,25 @@ public abstract class LocalDiskRepositoryTestCase { @After public void tearDown() throws Exception { RepositoryCache.clear(); - for (Repository r : toClose) + for (Repository r : toClose) { r.close(); + } toClose.clear(); // Since memory mapping is controlled by the GC we need to // tell it this is a good time to clean up and unlock // memory mapped files. // - if (useMMAP) + if (useMMAP) { System.gc(); - if (tmp != null) + } + FS.DETECTED.setUserHome(homeDir); + if (tmp != null) { recursiveDelete(tmp, false, true); - if (tmp != null && !tmp.exists()) + } + if (tmp != null && !tmp.exists()) { CleanupThread.removed(tmp); - + } SystemReader.setInstance(null); } |