Skip to content

Commit 7df3be0

Browse files
Merge branch 'master' into sezen.leblay/APPSEC-57259-extract-schema-spring
2 parents 50bda1b + 0f9b46c commit 7df3be0

File tree

1 file changed

+22
-2
lines changed
  • dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree

1 file changed

+22
-2
lines changed

dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/ShellGitClient.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,23 @@ public LineDiff getGitDiff(String baseCommit, String targetCommit)
980980
}
981981
}
982982

983+
private void makeRepoRootSafeDirectory() {
984+
// Some CI envs check out the repo as a different user than the one running the command
985+
// This will avoid the "dubious ownership" error
986+
try {
987+
commandExecutor.executeCommand(
988+
ShellCommandExecutor.OutputParser.IGNORE,
989+
"git",
990+
"config",
991+
"--global",
992+
"--add",
993+
"safe.directory",
994+
repoRoot);
995+
} catch (IOException | TimeoutException | InterruptedException e) {
996+
LOGGER.debug("Failed to add safe directory", e);
997+
}
998+
}
999+
9831000
@Override
9841001
public String toString() {
9851002
return "GitClient{" + repoRoot + "}";
@@ -1025,8 +1042,11 @@ public Factory(Config config, CiVisibilityMetricCollector metricCollector) {
10251042
public GitClient create(@Nullable String repoRoot) {
10261043
long commandTimeoutMillis = config.getCiVisibilityGitCommandTimeoutMillis();
10271044
if (repoRoot != null) {
1028-
return new ShellGitClient(
1029-
metricCollector, repoRoot, "1 month ago", 1000, commandTimeoutMillis);
1045+
ShellGitClient client =
1046+
new ShellGitClient(
1047+
metricCollector, repoRoot, "1 month ago", 1000, commandTimeoutMillis);
1048+
client.makeRepoRootSafeDirectory();
1049+
return client;
10301050
} else {
10311051
LOGGER.debug("Could not determine repository root, using no-op git client");
10321052
return NoOpGitClient.INSTANCE;

0 commit comments

Comments
 (0)