chore: add post-checkout lefthook

This commit is contained in:
insleker 2026-04-13 22:45:35 +08:00
parent 81d56f999d
commit 035e44998f
2 changed files with 65 additions and 0 deletions

View File

@ -13,3 +13,11 @@ pre-push:
commands: commands:
require-latest-main: require-latest-main:
run: uv run scripts/check_branch_up_to_date.py run: uv run scripts/check_branch_up_to_date.py
post-checkout:
commands:
private-skills-sync:
run: uvx --from git+https://github.com/existedinnettw/inkr-harness-tools.git inkr-skill-sync .local .agents --recursive
continue: true #ignore fail
pub-get-on-pubspec-change:
run: dart tool/pub_get_on_pubspec_change.dart {1} {2} {3}

View File

@ -0,0 +1,57 @@
import 'dart:io';
Future<void> main(List<String> args) async {
if (args.length != 3) {
stderr.writeln(
'Usage: dart tool/pub_get_on_pubspec_change.dart '
'<previous-head> <new-head> <checkout-flag>',
);
exitCode = 64;
return;
}
final [previousHead, newHead, checkoutFlag] = args;
if (checkoutFlag != '1') {
return;
}
if (!await _isCommit(previousHead) || !await _isCommit(newHead)) {
return;
}
final diff = await Process.run('git', [
'diff',
'--quiet',
previousHead,
newHead,
'--',
'pubspec.yaml',
]);
switch (diff.exitCode) {
case 0:
return;
case 1:
break;
default:
stderr.write(diff.stderr);
exitCode = diff.exitCode;
return;
}
final pubGet = await Process.start('dart', ['pub', 'get']);
await stdout.addStream(pubGet.stdout);
await stderr.addStream(pubGet.stderr);
exitCode = await pubGet.exitCode;
}
Future<bool> _isCommit(String revision) async {
final result = await Process.run('git', [
'rev-parse',
'--verify',
'--quiet',
'$revision^{commit}',
]);
return result.exitCode == 0;
}