Skip to content

Conversation

@deejgregor
Copy link
Contributor

@deejgregor deejgregor commented Nov 13, 2025

What Does This Do

This adds --no-prefix when ShellGitClient runs git diff, updates the regex in GitDiffParser, and adjusts test files.

Motivation

When diff.noprefix=true (or other git diff parameters that change the prefix format) used, it changes the output from git diff and and the test failure below is seen in GitClientTest.test git diff. I have used this git setting in my ~/.gitconfig file for years as it makes copying and pasting file names simpler.

java.lang.IllegalStateException: Line @@ -26 +26 @@ namespace Datadog.Trace.Logging contains changed lines information, but no changed file info is available
	at datadog.trace.civisibility.git.tree.GitDiffParser.parse(GitDiffParser.java:48)
	at datadog.trace.civisibility.utils.ShellCommandExecutor.executeCommand(ShellCommandExecutor.java:153)
	at datadog.trace.civisibility.utils.ShellCommandExecutor.executeCommand(ShellCommandExecutor.java:57)
	at datadog.trace.civisibility.git.tree.ShellGitClient.lambda$getGitDiff$18(ShellGitClient.java:926)
	at datadog.trace.civisibility.git.tree.ShellGitClient.executeCommand(ShellGitClient.java:980)
	at datadog.trace.civisibility.git.tree.ShellGitClient.getGitDiff(ShellGitClient.java:923)
	at datadog.trace.civisibility.git.tree.GitClientTest.test git diff(GitClientTest.groovy:264)

Additional Notes

Setting diff.noprefix=true changes the file name pattern and it fails to match GitDiffParser.CHANGED_FILE_PATTERN.

$ git diff | grep ^diff
diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/ShellGitClient.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/ShellGitClient.java

$ GIT_CONFIG_PARAMETERS="'diff.noprefix=true'" git diff | grep ^diff diff --git dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/ShellGitClient.java dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/ShellGitClient.java

Notice the lack of a/ and b/ on the latter output, but you'll see that the pattern expects that:

  private static final Pattern CHANGED_FILE_PATTERN =
      Pattern.compile("^diff --git a/(?<oldfilename>.+) b/(?<newfilename>.+)$");

The simple workaround is to pass --default-prefix to git diff, however this option has only been present since 2023: git/git@b39a569

A safer option would be to use --no-prefix, which has existed since 2007: git/git@eab9a40

To reproduce this error, you can run the test this way:

GIT_CONFIG_PARAMETERS="'diff.noprefix=true'" ./gradlew \
    --no-build-cache \
    :dd-java-agent:agent-ci-visibility:cleanTest \
    :dd-java-agent:agent-ci-visibility:test \
    --tests datadog.trace.civisibility.git.tree.GitClientTest

Contributor Checklist

Jira ticket: [PROJ-IDENT]

When diff.noprefix=true (or other git diff parameters that change
the prefix format) used, it changes the output from "git diff" and
and the test failure below is seen in GitClientTest.test git diff.
I have used this git setting in my ~/.gitconfig file for years as
it makes copying and pasting file names simpler.

java.lang.IllegalStateException: Line @@ -26 +26 @@ namespace Datadog.Trace.Logging contains changed lines information, but no changed file info is available
	at datadog.trace.civisibility.git.tree.GitDiffParser.parse(GitDiffParser.java:48)
	at datadog.trace.civisibility.utils.ShellCommandExecutor.executeCommand(ShellCommandExecutor.java:153)
	at datadog.trace.civisibility.utils.ShellCommandExecutor.executeCommand(ShellCommandExecutor.java:57)
	at datadog.trace.civisibility.git.tree.ShellGitClient.lambda$getGitDiff$18(ShellGitClient.java:926)
	at datadog.trace.civisibility.git.tree.ShellGitClient.executeCommand(ShellGitClient.java:980)
	at datadog.trace.civisibility.git.tree.ShellGitClient.getGitDiff(ShellGitClient.java:923)
	at datadog.trace.civisibility.git.tree.GitClientTest.test git diff(GitClientTest.groovy:264)

Setting diff.noprefix=true changes the file name pattern and it
fails to match GitDiffParser.CHANGED_FILE_PATTERN.

$ git diff | grep ^diff
diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/ShellGitClient.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/ShellGitClient.java

$ GIT_CONFIG_PARAMETERS="'diff.noprefix=true'" git diff | grep ^diff
diff --git dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/ShellGitClient.java dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/ShellGitClient.java

Notice the lack of "a/" and "b/" on the latter output, but you'll see
that the pattern expects that:

  private static final Pattern CHANGED_FILE_PATTERN =
      Pattern.compile("^diff --git a/(?<oldfilename>.+) b/(?<newfilename>.+)$");

The simple workaround is to pass "--default-prefix" to "git diff",
however this option has only been present since 2023:

git/git@b39a569

A safer option would be to use "--no-prefix", which has existed since
2007:

git/git@eab9a40

This adds "--no-prefix", updates the regex, and adjusts test files.
@deejgregor deejgregor requested a review from a team as a code owner November 13, 2025 03:36
@deejgregor deejgregor requested a review from Mariovido November 13, 2025 03:36
@PerfectSlayer PerfectSlayer changed the title Nit: Fix GitClientTest.test git diff when diff.noprefix=true is used Fix GitClientTest.test git diff when diff.noprefix=true is used Nov 13, 2025
@PerfectSlayer PerfectSlayer added type: enhancement Enhancements and improvements tag: no release notes Changes to exclude from release notes comp: ci visibility Continuous Integration Visibility labels Nov 13, 2025
@mcculls mcculls added the tag: community Community contribution label Nov 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp: ci visibility Continuous Integration Visibility tag: community Community contribution tag: no release notes Changes to exclude from release notes type: enhancement Enhancements and improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants