Skip to content

Commit

Permalink
Clear git user config more reliably
Browse files Browse the repository at this point in the history
  • Loading branch information
yrodiere committed Nov 28, 2023
1 parent cb4afb9 commit 323de3b
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions src/test/java/io/quarkus/search/app/testsupport/GitTestUtils.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
package io.quarkus.search.app.testsupport;

import java.io.IOException;
import java.nio.file.CopyOption;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.Map;
import org.eclipse.jgit.lib.Config;
import org.eclipse.jgit.lib.StoredConfig;
import org.eclipse.jgit.util.SystemReader;

import org.jboss.logging.Logger;

import org.eclipse.jgit.util.SystemReader;

public final class GitTestUtils {

private static final Logger LOG = Logger.getLogger(GitTestUtils.class);
Expand All @@ -24,9 +15,23 @@ private GitTestUtils() {

public static void cleanGitUserConfig() {
try {
SystemReader.getInstance().getUserConfig().clear();
clearRecursively(SystemReader.getInstance().getUserConfig());
} catch (Exception e) {
LOG.warn("Unable to clear the Git user config");
LOG.warn("Unable to get Git user config");
}
}

private static void clearRecursively(Config config) {
if (config == null) {
return;
}
if (config instanceof StoredConfig) {
try {
((StoredConfig) config).clear();
} catch (Exception e) {
LOG.warnf("Unable to clear Git config %s", config);
}
}
clearRecursively(config.getBaseConfig());
}
}

0 comments on commit 323de3b

Please sign in to comment.