From 366ed7f972c74e6bcd6d2d14156c1b60350191bd Mon Sep 17 00:00:00 2001 From: Jim Graham Date: Mon, 13 Jan 2025 15:49:03 -0800 Subject: [PATCH] Fix paths when running clang-tidy on git diffs (#161496) The working directory was `engine/src/flutter` but all of the file names already had those parent directories on them so we'd be trying to find build commands for `engine/src/flutter/engine/src/flutter`. This change tells the git commands to make the file names relative to the working directory (which is already `engine/src/flutter`). Someone more familiar with the `--lint-head` option should double check its operation since I wasn't sure exactly what it was supposed to do, but the list of files it generated looked correct. --- .../pkg/git_repo_tools/lib/git_repo_tools.dart | 4 +++- .../git_repo_tools/test/git_repo_tools_test.dart | 13 ++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/engine/src/flutter/tools/pkg/git_repo_tools/lib/git_repo_tools.dart b/engine/src/flutter/tools/pkg/git_repo_tools/lib/git_repo_tools.dart index 34f5bd462d..47b7d74b07 100644 --- a/engine/src/flutter/tools/pkg/git_repo_tools/lib/git_repo_tools.dart +++ b/engine/src/flutter/tools/pkg/git_repo_tools/lib/git_repo_tools.dart @@ -86,7 +86,8 @@ final class GitRepo { 'git', 'diff', '--name-only', - '--diff-filter=ACMRT', + '--diff-filter=ACMRT', // Added, copied, modified, renamed, or type-changed. + '--relative', // _gitOutputToList will prepend the CWD so we don't want duplicate sub-paths mergeBase, ]); return _gitOutputToList(masterResult); @@ -111,6 +112,7 @@ final class GitRepo { '--no-commit-id', '--name-only', '--diff-filter=ACMRT', // Added, copied, modified, renamed, or type-changed. + '--relative', // _gitOutputToList will prepend the CWD so we don't want duplicate sub-paths '-r', 'HEAD', ]); diff --git a/engine/src/flutter/tools/pkg/git_repo_tools/test/git_repo_tools_test.dart b/engine/src/flutter/tools/pkg/git_repo_tools/test/git_repo_tools_test.dart index 7b17d9c46a..a5d4bbc508 100644 --- a/engine/src/flutter/tools/pkg/git_repo_tools/test/git_repo_tools_test.dart +++ b/engine/src/flutter/tools/pkg/git_repo_tools/test/git_repo_tools_test.dart @@ -26,7 +26,8 @@ void main() { } // Succeed calling "git diff --name-only --diff-filter=ACMRT fake-sha-hash". - if (command.join(' ') == 'git diff --name-only --diff-filter=ACMRT $fakeShaHash') { + if (command.join(' ') == + 'git diff --name-only --diff-filter=ACMRT --relative $fakeShaHash') { return FakeProcess(stdout: 'file1\nfile2'); } @@ -62,7 +63,8 @@ void main() { return FakeProcess(); } - if (command.join(' ') == 'git diff --name-only --diff-filter=ACMRT $fakeShaHash') { + if (command.join(' ') == + 'git diff --name-only --diff-filter=ACMRT --relative $fakeShaHash') { return FakeProcess(stdout: 'file1\nfile2'); } @@ -91,7 +93,7 @@ void main() { } if (command.join(' ') == - 'git diff-tree --no-commit-id --name-only --diff-filter=ACMRT -r HEAD') { + 'git diff-tree --no-commit-id --name-only --diff-filter=ACMRT --relative -r HEAD') { return FakeProcess(stdout: 'file1\nfile2'); } @@ -120,7 +122,7 @@ void main() { } if (command.join(' ') == - 'git diff-tree --no-commit-id --name-only --diff-filter=ACMRT -r HEAD') { + 'git diff-tree --no-commit-id --name-only --diff-filter=ACMRT --relative -r HEAD') { return FakeProcess(stdout: 'file1\nfile2'); } @@ -164,7 +166,8 @@ void main() { return FakeProcess(); } - if (command.join(' ') == 'git diff --name-only --diff-filter=ACMRT $fakeShaHash') { + if (command.join(' ') == + 'git diff --name-only --diff-filter=ACMRT --relative $fakeShaHash') { return FakeProcess(stdout: 'file1\nfile2'); }