From faefa90f990858db7bec199501cb37f2631c43d0 Mon Sep 17 00:00:00 2001 From: Thomas Wolf Date: Thu, 15 Jun 2023 22:08:06 +0200 Subject: 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 --- .../src/org/eclipse/jgit/junit/ssh/SshTestHarness.java | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) (limited to 'org.eclipse.jgit.junit.ssh') diff --git a/org.eclipse.jgit.junit.ssh/src/org/eclipse/jgit/junit/ssh/SshTestHarness.java b/org.eclipse.jgit.junit.ssh/src/org/eclipse/jgit/junit/ssh/SshTestHarness.java index 6fa30d7e1e..b183b22603 100644 --- a/org.eclipse.jgit.junit.ssh/src/org/eclipse/jgit/junit/ssh/SshTestHarness.java +++ b/org.eclipse.jgit.junit.ssh/src/org/eclipse/jgit/junit/ssh/SshTestHarness.java @@ -89,8 +89,6 @@ public abstract class SshTestHarness extends RepositoryTestCase { protected File knownHosts; - private File homeDir; - @Override public void setUp() throws Exception { super.setUp(); @@ -99,13 +97,8 @@ public abstract class SshTestHarness extends RepositoryTestCase { git.add().addFilepattern("file.txt").call(); git.commit().setMessage("Initial commit").call(); } - mockSystemReader.setProperty("user.home", - getTemporaryDirectory().getAbsolutePath()); - mockSystemReader.setProperty("HOME", - getTemporaryDirectory().getAbsolutePath()); - homeDir = FS.DETECTED.userHome(); - FS.DETECTED.setUserHome(getTemporaryDirectory().getAbsoluteFile()); - sshDir = new File(getTemporaryDirectory(), ".ssh"); + // The home directory is mocked here + sshDir = new File(FS.DETECTED.userHome(), ".ssh"); assertTrue(sshDir.mkdir()); File serverDir = new File(getTemporaryDirectory(), "srv"); assertTrue(serverDir.mkdir()); @@ -236,7 +229,6 @@ public abstract class SshTestHarness extends RepositoryTestCase { server.stop(); server = null; } - FS.DETECTED.setUserHome(homeDir); SshSessionFactory.setInstance(null); factory = null; } -- cgit v1.2.3