Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

913: Skara should honor .gitconfig and /etc/gitconfig #1049

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -81,7 +81,7 @@ public Iterator<Commit> iterator() {
cmd.add(range);
var pb = new ProcessBuilder(cmd);
pb.directory(dir.toFile());
pb.environment().putAll(GitRepository.NO_CONFIG_ENV);
pb.environment().putAll(GitRepository.currentEnv);
var command = pb.command();
try {
var p = pb.start();
@@ -38,17 +38,22 @@
import java.util.stream.Collectors;

public class GitRepository implements Repository {
public final static Map<String, String> NO_CONFIG_ENV = Map.of(
private final static Map<String, String> NO_CONFIG_ENV = Map.of(
"HOME", "/this-does-not-exist-and-if-you-create-it-you-are-in-trouble",
"XDG_CONFIG_HOME", "/this-does-not-exist-and-if-you-create-it-you-are-in-trouble",
"GIT_CONFIG_NOSYSTEM", "true"
);

public static Map<String, String> currentEnv = Collections.emptyMap();
private final Path dir;
private final Logger log = Logger.getLogger("org.openjdk.skara.vcs.git");
private Path cachedRoot = null;
private static final Hash EMPTY_TREE = new Hash("4b825dc642cb6eb9a060e54bf8d69288fbee4904");

public static void ignoreConfiguration() {
currentEnv = NO_CONFIG_ENV;
}

private java.lang.Process start(String... cmd) throws IOException {
return start(Arrays.asList(cmd));
}
@@ -57,7 +62,7 @@ private java.lang.Process start(List<String> cmd) throws IOException {
log.fine("Executing " + String.join(" ", cmd));
var pb = new ProcessBuilder(cmd);
pb.directory(dir.toFile());
pb.environment().putAll(NO_CONFIG_ENV);
pb.environment().putAll(currentEnv);
pb.redirectError(ProcessBuilder.Redirect.DISCARD);
return pb.start();
}
@@ -91,7 +96,7 @@ private Execution capture(String... cmd) {
}

public static Execution capture(Path cwd, String... cmd) {
return capture(cwd, NO_CONFIG_ENV, cmd);
return capture(cwd, currentEnv, cmd);
}

private static Execution capture(Path cwd, Map<String, String> env, String... cmd) {
@@ -734,7 +739,7 @@ public Hash commit(String message,
ZonedDateTime committerDate) throws IOException {
var cmd = Process.capture("git", "commit", "--message=" + message)
.workdir(dir)
.environ(NO_CONFIG_ENV)
.environ(currentEnv)
.environ("GIT_AUTHOR_NAME", authorName)
.environ("GIT_AUTHOR_EMAIL", authorEmail)
.environ("GIT_COMMITTER_NAME", committerName)
@@ -770,7 +775,7 @@ public Hash commit(String message, String authorName, String authorEmail, ZonedD
}
var cmd = Process.capture(cmdLine.toArray(new String[0]))
.workdir(dir)
.environ(NO_CONFIG_ENV)
.environ(currentEnv)
.environ("GIT_AUTHOR_NAME", authorName)
.environ("GIT_AUTHOR_EMAIL", authorEmail)
.environ("GIT_COMMITTER_NAME", committerName)
@@ -823,7 +828,7 @@ public Hash amend(String message, String authorName, String authorEmail, String
}
var cmd = Process.capture("git", "commit", "--amend", "--reset-author", "--message=" + message)
.workdir(dir)
.environ(NO_CONFIG_ENV)
.environ(currentEnv)
.environ("GIT_AUTHOR_NAME", authorName)
.environ("GIT_AUTHOR_EMAIL", authorEmail)
.environ("GIT_COMMITTER_NAME", committerName)
@@ -838,7 +843,7 @@ public Hash amend(String message, String authorName, String authorEmail, String
public Tag tag(Hash hash, String name, String message, String authorName, String authorEmail, ZonedDateTime date) throws IOException {
var cmd = Process.capture("git", "tag", "--annotate", "--message=" + message, name, hash.hex())
.workdir(dir)
.environ(NO_CONFIG_ENV)
.environ(currentEnv)
.environ("GIT_AUTHOR_NAME", authorName)
.environ("GIT_AUTHOR_EMAIL", authorEmail)
.environ("GIT_COMMITTER_NAME", authorName)
@@ -898,7 +903,7 @@ public void rebase(Hash hash, String committerName, String committerEmail) throw
.environ("GIT_COMMITTER_NAME", committerName)
.environ("GIT_COMMITTER_EMAIL", committerEmail)
.workdir(dir)
.environ(NO_CONFIG_ENV)
.environ(currentEnv)
.execute()) {
await(p);
}
@@ -37,18 +37,23 @@
import java.net.URI;

public class HgRepository implements Repository {
public final static Map<String, String> NO_CONFIG_ENV = Map.of(
private final static Map<String, String> NO_CONFIG_ENV = Map.of(
"HGRCPATH", "",
"HGPLAIN", "",
"HGEDITOR", "",
"EDITOR", "",
"VISUAL", ""
);
private static Map<String, String> currentEnv = Collections.emptyMap();

private static final String EXT_PY = "ext.py";
private final Path dir;
private final Logger log = Logger.getLogger("org.openjdk.skara.vcs.hg");

public static void ignoreConfiguration() {
currentEnv = NO_CONFIG_ENV;
}

private void copyResource(String name, Path p) throws IOException {
Files.copy(this.getClass().getResourceAsStream("/" + name), p, StandardCopyOption.REPLACE_EXISTING);
}
@@ -62,7 +67,7 @@ private java.lang.Process start(List<String> cmd) throws IOException {
var pb = new ProcessBuilder(cmd);
pb.directory(dir.toFile());
pb.redirectError(ProcessBuilder.Redirect.DISCARD);
pb.environment().putAll(NO_CONFIG_ENV);
pb.environment().putAll(currentEnv);
return pb.start();
}

@@ -95,7 +100,7 @@ private static Execution capture(Path cwd, List<String> cmd) {
}
public static Execution capture(Path cwd, String... cmd) {
return Process.capture(cmd)
.environ(NO_CONFIG_ENV)
.environ(currentEnv)
.workdir(cwd)
.execute();
}
@@ -595,7 +600,7 @@ private void export(String revset, Path to) throws IOException {
pb.directory(dir.toFile());
pb.redirectError(ProcessBuilder.Redirect.DISCARD);
pb.redirectOutput(to.toFile());
pb.environment().putAll(NO_CONFIG_ENV);
pb.environment().putAll(currentEnv);
var p = pb.start();
try {
await(p);
@@ -22,7 +22,7 @@
*/
package org.openjdk.skara.vcs;

import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.BeforeAll;
import org.openjdk.skara.test.TemporaryDirectory;

import org.junit.jupiter.api.Test;
@@ -45,6 +45,12 @@

public class RepositoryTests {

@BeforeAll
static void setup() {
GitRepository.ignoreConfiguration();
HgRepository.ignoreConfiguration();
}

@ParameterizedTest
@EnumSource(VCS.class)
void testExistsOnMissingDirectory(VCS vcs) throws IOException {
@@ -1655,7 +1661,7 @@ void testSingleEmptyCommit() throws IOException, InterruptedException {
pb.environment().put("GIT_COMMITTER_NAME", "duke");
pb.environment().put("GIT_COMMITTER_EMAIL", "duke@openjdk.org");
pb.directory(dir.path().toFile());
pb.environment().putAll(GitRepository.NO_CONFIG_ENV);
pb.environment().putAll(GitRepository.currentEnv);

var res = pb.start().waitFor();
assertEquals(0, res);
@@ -1689,7 +1695,7 @@ void testEmptyCommitWithParent() throws IOException, InterruptedException {
pb.environment().put("GIT_COMMITTER_NAME", "duke");
pb.environment().put("GIT_COMMITTER_EMAIL", "duke@openjdk.org");
pb.directory(dir.path().toFile());
pb.environment().putAll(GitRepository.NO_CONFIG_ENV);
pb.environment().putAll(GitRepository.currentEnv);

var res = pb.start().waitFor();
assertEquals(0, res);
@@ -2488,7 +2494,7 @@ void testLightweightTags() throws IOException, InterruptedException {
// so use a ProcessBuilder and invoke git directly here
var pb = new ProcessBuilder("git", "tag", "test-tag", head.hex());
pb.directory(repo.root().toFile());
pb.environment().putAll(GitRepository.NO_CONFIG_ENV);
pb.environment().putAll(GitRepository.currentEnv);
assertEquals(0, pb.start().waitFor());

var tags = repo.tags();