Skip to content

Commit 2ba6591

Browse files
[camera_android_camerax] Check Git hooks configuration in check-readiness skill (#12628)
This came up as part of #12624 I noticed that the pre-push skill passed my code but linux analyze failed. It was because I didnt realize that this checkout (I have 2) didnt have git hooks installed. - @reidbaker --- Agent authored description Updates the `check-readiness` skill to verify that Git pre-commit hooks (`script/githooks`) are configured in the repository (`core.hooksPath`). If unconfigured or pointing to an unexpected path, it provides actionable instructions to run `script/githooks/bin/install_hooks.dart`. Includes unit test coverage in `check_test.dart`. Part of flutter/flutter#188870 ## Pre-Review Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [x] I read the [Tree Hygiene] page, which explains my responsibilities. - [x] I read and followed the [relevant style guides] and ran [the auto-formatter]. - [x] I signed the [CLA]. - [x] The title of the PR starts with the name of the package surrounded by square brackets, e.g. `[shared_preferences]` - [x] I [linked to at least one issue that this PR fixes] in the description above. - [x] I followed [the version and CHANGELOG instructions], using [semantic versioning] and the [repository CHANGELOG style], or I have commented below to indicate which documented exception this PR falls under[^1]. - [x] I updated/added any relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or I have commented below to indicate which [test exemption] this PR falls under[^1]. - [x] All existing and new tests are passing. <!-- Links --> [Contributor Guide]: https://github.com/flutter/packages/blob/main/CONTRIBUTING.md [AI contribution guidelines]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines [Tree Hygiene]: https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md [relevant style guides]: https://github.com/flutter/packages/blob/main/CONTRIBUTING.md#style [the auto-formatter]: https://github.com/flutter/packages/blob/main/script/tool/README.md#format-code [CLA]: https://cla.developers.google.com/ [Discord]: https://github.com/flutter/flutter/blob/master/docs/contributing/Chat.md [linked to at least one issue that this PR fixes]: https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md#overview [the version and CHANGELOG instructions]: https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#version-and-changelog-updates [semantic versioning]: https://dart.dev/tools/pub/versioning#semantic-versions [repository CHANGELOG style]: https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changelog-style [test exemption]: https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md#tests --------- Co-authored-by: Reid Baker <[email protected]>
1 parent 1414e79 commit 2ba6591

2 files changed

Lines changed: 85 additions & 5 deletions

File tree

‎packages/camera/camera_android_camerax/.agents/skills/check-readiness/lib/check_readiness.dart‎

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ class ReadinessChecker {
3737
if (!await _checkGitState(workspaceRoot)) {
3838
isReady = false;
3939
}
40+
if (!await _checkGitHooks(workspaceRoot)) {
41+
isReady = false;
42+
}
4043

4144
final bool hasTools = await _checkFlutterAndDart();
4245
if (!hasTools) {
@@ -91,7 +94,7 @@ class ReadinessChecker {
9194
final ProcessResult result;
9295
try {
9396
result = await _processManager.run(
94-
['git', 'status', '--porcelain'],
97+
<String>['git', 'status', '--porcelain'],
9598
workingDirectory: workspaceRoot,
9699
);
97100
} on ProcessException catch (e) {
@@ -113,8 +116,42 @@ class ReadinessChecker {
113116
return true;
114117
}
115118

119+
Future<bool> _checkGitHooks(String workspaceRoot) async {
120+
_log('3. Checking Git hooks configuration...');
121+
final ProcessResult result;
122+
try {
123+
result = await _processManager.run(
124+
<String>['git', 'config', '--get', 'core.hooksPath'],
125+
workingDirectory: workspaceRoot,
126+
);
127+
} on ProcessException catch (e) {
128+
_log('Error: Failed to check git config. Is git installed and on the PATH?');
129+
_log(e.toString());
130+
return false;
131+
}
132+
133+
final String hooksPath = (result.stdout as String).trim();
134+
if (result.exitCode != 0 || !_fileSystem.path.equals(hooksPath, 'script/githooks')) {
135+
_log(
136+
'Error: Git hooks are not configured correctly (core.hooksPath is "$hooksPath", expected "script/githooks").',
137+
);
138+
final String? repoRoot = _findRepoRoot(workspaceRoot);
139+
final String githooksDir = repoRoot != null
140+
? _fileSystem.path.join(repoRoot, 'script', 'githooks')
141+
: 'script/githooks';
142+
_log(
143+
'To install git hooks, run:\n'
144+
' (cd $githooksDir && dart pub get && dart run bin/install_hooks.dart)',
145+
);
146+
return false;
147+
}
148+
149+
_log('Git hooks are configured correctly.');
150+
return true;
151+
}
152+
116153
Future<bool> _checkFlutterAndDart() async {
117-
_log('3. Checking Flutter and Dart...');
154+
_log('4. Checking Flutter and Dart...');
118155
if (!_processManager.canRun('flutter')) {
119156
_log("Error: 'flutter' is not on the PATH.");
120157
return false;
@@ -128,9 +165,9 @@ class ReadinessChecker {
128165
}
129166

130167
Future<bool> _checkDependencies(String workspaceRoot) async {
131-
_log('4. Checking dependencies in camera_android_camerax...');
168+
_log('5. Checking dependencies in camera_android_camerax...');
132169
final ProcessResult result = await _processManager.run(
133-
['flutter', 'pub', 'get'],
170+
<String>['flutter', 'pub', 'get'],
134171
workingDirectory: workspaceRoot,
135172
);
136173
if (result.exitCode != 0) {
@@ -142,7 +179,7 @@ class ReadinessChecker {
142179
}
143180

144181
Future<bool> _activateFlutterPluginTools(String workspaceRoot) async {
145-
_log('5. Activating flutter_plugin_tools...');
182+
_log('6. Activating flutter_plugin_tools...');
146183
final String? repoRoot = _findRepoRoot(workspaceRoot);
147184
if (repoRoot == null) {
148185
_log('Error: Failed to find repository root (no .git directory found).');

‎packages/camera/camera_android_camerax/.agents/skills/check-readiness/test/check_test.dart‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ void main() {
6868
);
6969
workspaceRoot = fileSystem.path.absolute('workspace');
7070
fileSystem.file(fileSystem.path.join(workspaceRoot, '.git')).createSync(recursive: true);
71+
processManager.runMock['git config --get core.hooksPath'] =
72+
ProcessResult(0, 0, 'script/githooks\n', '');
7173
printLogs.clear();
7274
});
7375

@@ -120,6 +122,37 @@ void main() {
120122
'Error: Git working directory is not clean. Please commit or stash your changes before starting new work.'));
121123
});
122124

125+
test('fails when git hooks are not configured', () async {
126+
fileSystem
127+
.directory(fileSystem.path.join(workspaceRoot, '.agents', 'skills'))
128+
.createSync(recursive: true);
129+
130+
processManager.runMock['git config --get core.hooksPath'] = ProcessResult(0, 1, '', '');
131+
132+
final bool result = await runChecker();
133+
expect(result, isFalse);
134+
expect(
135+
printLogs.any((line) => line.contains('Git hooks are not configured correctly')),
136+
isTrue,
137+
);
138+
});
139+
140+
test('fails when git hooks point to incorrect path', () async {
141+
fileSystem
142+
.directory(fileSystem.path.join(workspaceRoot, '.agents', 'skills'))
143+
.createSync(recursive: true);
144+
145+
processManager.runMock['git config --get core.hooksPath'] =
146+
ProcessResult(0, 0, 'other/hooks\n', '');
147+
148+
final bool result = await runChecker();
149+
expect(result, isFalse);
150+
expect(
151+
printLogs.any((line) => line.contains('Git hooks are not configured correctly')),
152+
isTrue,
153+
);
154+
});
155+
123156
test('fails when flutter is missing', () async {
124157
fileSystem
125158
.directory(fileSystem.path.join(workspaceRoot, '.agents', 'skills'))
@@ -208,6 +241,16 @@ void main() {
208241
expect(printLogs.any((line) => line.contains('Found broken symlinks in .agents/skills:')),
209242
isTrue);
210243
});
244+
245+
test('passes when git hooks use Windows backslashes', () async {
246+
processManager.runMock['git config --get core.hooksPath'] =
247+
ProcessResult(0, 0, r'script\githooks' '\n', '');
248+
processManager.runMock['git status --porcelain'] = ProcessResult(0, 0, '', '');
249+
250+
final bool result = await winChecker.checkReadiness(winWorkspaceRoot);
251+
expect(result, isTrue);
252+
expect(printLogs, contains('Git hooks are configured correctly.'));
253+
});
211254
});
212255

213256
group('findPackageDir', () {

0 commit comments

Comments
 (0)