Merge branch 'stable-6.0'
* stable-6.0: [bazel] Skip ConfigTest#testCommitTemplatePathInHomeDirecory [errorprone] Fix InfiniteRecursion error in RecordingLogger [errorprone] Suppress Finally error in ObjectDownloadListener [errorprone] Fix implicit use of default charset in FileBasedConfigTest [errorprone] Suppress FutureReturnValueIgnored in FileRepository#autoGc Change-Id: I08d58c8f3f04e3a920da43b5fb252b1654c2b33c
This commit is contained in:
commit
5f556588a9
|
@ -180,11 +180,15 @@ public void warn(String msg) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void warn(String format, Object arg) {
|
public void warn(String format, Object arg) {
|
||||||
warn(format, Collections.singleton(arg));
|
addWarnings(format, Collections.singleton(arg));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void warn(String format, Object... arguments) {
|
public void warn(String format, Object... arguments) {
|
||||||
|
addWarnings(format, arguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addWarnings(String format, Object... arguments) {
|
||||||
synchronized (warnings) {
|
synchronized (warnings) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int index = format.indexOf("{}");
|
int index = format.indexOf("{}");
|
||||||
|
|
|
@ -81,6 +81,7 @@ public ObjectDownloadListener(FileLfsRepository repository,
|
||||||
*
|
*
|
||||||
* Write file content
|
* Write file content
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("Finally")
|
||||||
@Override
|
@Override
|
||||||
public void onWritePossible() throws IOException {
|
public void onWritePossible() throws IOException {
|
||||||
while (out.isReady()) {
|
while (out.isReady()) {
|
||||||
|
|
|
@ -42,6 +42,7 @@ DATA = [
|
||||||
EXCLUDED = [
|
EXCLUDED = [
|
||||||
PKG + "api/SecurityManagerTest.java",
|
PKG + "api/SecurityManagerTest.java",
|
||||||
PKG + "api/SecurityManagerMissingPermissionsTest.java",
|
PKG + "api/SecurityManagerMissingPermissionsTest.java",
|
||||||
|
PKG + "lib/CommitTemplateConfigTest.java",
|
||||||
]
|
]
|
||||||
|
|
||||||
tests(tests = glob(
|
tests(tests = glob(
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2021 SAP SE 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
|
||||||
|
* https://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.eclipse.jgit.lib;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.eclipse.jgit.errors.ConfigInvalidException;
|
||||||
|
import org.eclipse.jgit.junit.JGitTestUtil;
|
||||||
|
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
|
||||||
|
import org.junit.Rule;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.rules.TemporaryFolder;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This test was moved from ConfigTest to allow skipping it when running the
|
||||||
|
* test using bazel which doesn't allow tests to create files in the home
|
||||||
|
* directory
|
||||||
|
*/
|
||||||
|
public class CommitTemplateConfigTest {
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public TemporaryFolder tmp = new TemporaryFolder();
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCommitTemplatePathInHomeDirecory()
|
||||||
|
throws ConfigInvalidException, IOException {
|
||||||
|
Config config = new Config(null);
|
||||||
|
File tempFile = tmp.newFile("testCommitTemplate-");
|
||||||
|
File workTree = tmp.newFolder("dummy-worktree");
|
||||||
|
Repository repo = FileRepositoryBuilder.create(workTree);
|
||||||
|
String templateContent = "content of the template";
|
||||||
|
JGitTestUtil.write(tempFile, templateContent);
|
||||||
|
// proper evaluation of the ~/ directory
|
||||||
|
String homeDir = System.getProperty("user.home");
|
||||||
|
File tempFileInHomeDirectory = File.createTempFile("fileInHomeFolder",
|
||||||
|
".tmp", new File(homeDir));
|
||||||
|
tempFileInHomeDirectory.deleteOnExit();
|
||||||
|
JGitTestUtil.write(tempFileInHomeDirectory, templateContent);
|
||||||
|
String expectedTemplatePath = tempFileInHomeDirectory.getPath()
|
||||||
|
.replace(homeDir, "~");
|
||||||
|
config = ConfigTest
|
||||||
|
.parse("[commit]\n\ttemplate = " + expectedTemplatePath + "\n");
|
||||||
|
String templatePath = config.get(CommitConfig.KEY)
|
||||||
|
.getCommitTemplatePath();
|
||||||
|
assertEquals(expectedTemplatePath, templatePath);
|
||||||
|
assertEquals(templateContent,
|
||||||
|
config.get(CommitConfig.KEY).getCommitTemplateContent(repo));
|
||||||
|
}
|
||||||
|
}
|
|
@ -1177,7 +1177,7 @@ private static void assertReadLong(long exp, String act)
|
||||||
assertEquals(exp, c.getLong("s", null, "a", 0L));
|
assertEquals(exp, c.getLong("s", null, "a", 0L));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Config parse(String content)
|
static Config parse(String content)
|
||||||
throws ConfigInvalidException {
|
throws ConfigInvalidException {
|
||||||
return parse(content, null);
|
return parse(content, null);
|
||||||
}
|
}
|
||||||
|
@ -1546,31 +1546,6 @@ public void testCommitTemplateEncoding()
|
||||||
"utf-8", commitEncoding);
|
"utf-8", commitEncoding);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testCommitTemplatePathInHomeDirecory()
|
|
||||||
throws ConfigInvalidException, IOException {
|
|
||||||
Config config = new Config(null);
|
|
||||||
File tempFile = tmp.newFile("testCommitTemplate-");
|
|
||||||
File workTree = tmp.newFolder("dummy-worktree");
|
|
||||||
Repository repo = FileRepositoryBuilder.create(workTree);
|
|
||||||
String templateContent = "content of the template";
|
|
||||||
JGitTestUtil.write(tempFile, templateContent);
|
|
||||||
// proper evaluation of the ~/ directory
|
|
||||||
String homeDir = System.getProperty("user.home");
|
|
||||||
File tempFileInHomeDirectory = File.createTempFile("fileInHomeFolder",
|
|
||||||
".tmp", new File(homeDir));
|
|
||||||
tempFileInHomeDirectory.deleteOnExit();
|
|
||||||
JGitTestUtil.write(tempFileInHomeDirectory, templateContent);
|
|
||||||
String expectedTemplatePath = tempFileInHomeDirectory.getPath()
|
|
||||||
.replace(homeDir, "~");
|
|
||||||
config = parse("[commit]\n\ttemplate = " + expectedTemplatePath + "\n");
|
|
||||||
String templatePath = config.get(CommitConfig.KEY)
|
|
||||||
.getCommitTemplatePath();
|
|
||||||
assertEquals(expectedTemplatePath, templatePath);
|
|
||||||
assertEquals(templateContent,
|
|
||||||
config.get(CommitConfig.KEY).getCommitTemplateContent(repo));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expected = ConfigInvalidException.class)
|
@Test(expected = ConfigInvalidException.class)
|
||||||
public void testCommitTemplateWithInvalidEncoding()
|
public void testCommitTemplateWithInvalidEncoding()
|
||||||
throws ConfigInvalidException, IOException {
|
throws ConfigInvalidException, IOException {
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.StandardOpenOption;
|
import java.nio.file.StandardOpenOption;
|
||||||
|
@ -276,7 +277,8 @@ public void testSavedConfigFileShouldNotReadUserGitConfig()
|
||||||
throws IOException {
|
throws IOException {
|
||||||
AtomicBoolean userConfigTimeRead = new AtomicBoolean(false);
|
AtomicBoolean userConfigTimeRead = new AtomicBoolean(false);
|
||||||
|
|
||||||
Path userConfigFile = createFile(CONTENT1.getBytes(), "home");
|
Path userConfigFile = createFile(
|
||||||
|
CONTENT1.getBytes(StandardCharsets.UTF_8), "home");
|
||||||
mockSystemReader.setUserGitConfig(
|
mockSystemReader.setUserGitConfig(
|
||||||
new FileBasedConfig(userConfigFile.toFile(), FS.DETECTED) {
|
new FileBasedConfig(userConfigFile.toFile(), FS.DETECTED) {
|
||||||
|
|
||||||
|
@ -289,7 +291,8 @@ public long getTimeUnit(String section, String subsection,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Path file = createFile(CONTENT2.getBytes(), "repo");
|
Path file = createFile(CONTENT2.getBytes(StandardCharsets.UTF_8),
|
||||||
|
"repo");
|
||||||
FileBasedConfig fileBasedConfig = new FileBasedConfig(file.toFile(),
|
FileBasedConfig fileBasedConfig = new FileBasedConfig(file.toFile(),
|
||||||
FS.DETECTED);
|
FS.DETECTED);
|
||||||
fileBasedConfig.save();
|
fileBasedConfig.save();
|
||||||
|
|
|
@ -594,6 +594,7 @@ private boolean shouldAutoDetach() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
|
@SuppressWarnings("FutureReturnValueIgnored")
|
||||||
@Override
|
@Override
|
||||||
public void autoGC(ProgressMonitor monitor) {
|
public void autoGC(ProgressMonitor monitor) {
|
||||||
GC gc = new GC(this);
|
GC gc = new GC(this);
|
||||||
|
|
Loading…
Reference in New Issue