Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,23 @@ public LineDiff getGitDiff(String baseCommit, String targetCommit)
}
}

private void makeRepoRootSafeDirectory() {
// Some CI envs check out the repo as a different user than the one running the command
// This will avoid the "dubious ownership" error
try {
commandExecutor.executeCommand(
ShellCommandExecutor.OutputParser.IGNORE,
"git",
"config",
"--global",
"--add",
"safe.directory",
repoRoot);
} catch (IOException | TimeoutException | InterruptedException e) {
LOGGER.debug("Failed to add safe directory", e);
}
}

@Override
public String toString() {
return "GitClient{" + repoRoot + "}";
Expand Down Expand Up @@ -1025,8 +1042,11 @@ public Factory(Config config, CiVisibilityMetricCollector metricCollector) {
public GitClient create(@Nullable String repoRoot) {
long commandTimeoutMillis = config.getCiVisibilityGitCommandTimeoutMillis();
if (repoRoot != null) {
return new ShellGitClient(
metricCollector, repoRoot, "1 month ago", 1000, commandTimeoutMillis);
ShellGitClient client =
new ShellGitClient(
metricCollector, repoRoot, "1 month ago", 1000, commandTimeoutMillis);
client.makeRepoRootSafeDirectory();
return client;
} else {
LOGGER.debug("Could not determine repository root, using no-op git client");
return NoOpGitClient.INSTANCE;
Expand Down