Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 8832caa

Browse files
committed
Adds a post-merge githook that reminds to run gclient sync -D
1 parent 268d752 commit 8832caa

File tree

10 files changed

+248
-3
lines changed

10 files changed

+248
-3
lines changed

tools/githooks/lib/githooks.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,21 @@ import 'dart:io' as io;
77
import 'package:args/args.dart';
88
import 'package:args/command_runner.dart';
99

10+
import 'src/post_checkout_command.dart';
11+
import 'src/post_merge_command.dart';
1012
import 'src/pre_push_command.dart';
13+
import 'src/pre_rebase_command.dart';
1114

1215
/// Runs the githooks
1316
Future<int> run(List<String> args) async {
1417
final CommandRunner<bool> runner = CommandRunner<bool> (
1518
'githooks',
1619
'Githooks implementation for the flutter/engine repo.',
1720
)
18-
..addCommand(PrePushCommand());
21+
..addCommand(PostCheckoutCommand())
22+
..addCommand(PostMergeCommand())
23+
..addCommand(PrePushCommand())
24+
..addCommand(PreRebaseCommand());
1925

2026
// Add top-level arguments.
2127
runner.argParser
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'dart:io' as io;
6+
7+
const String _redBoldUnderline = '\x1B[31;1;4m';
8+
const String _reset = '\x1B[0m';
9+
10+
/// Prints a reminder to stdout to run `gclient sync -D`. Uses colors when
11+
/// stdout supports ANSI escape codes.
12+
void printGclientSyncReminder(String command) {
13+
final String prefix = io.stdout.supportsAnsiEscapes ? _redBoldUnderline : '';
14+
final String postfix = io.stdout.supportsAnsiEscapes ? _reset : '';
15+
io.stderr.writeln('$command: The engine source tree has been updated.');
16+
io.stderr.writeln(
17+
'\n${prefix}You man need to run "gclient sync -D"$postfix\n',
18+
);
19+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:args/command_runner.dart';
6+
7+
import 'messages.dart';
8+
9+
/// The command that implements the post-checkout githook
10+
class PostCheckoutCommand extends Command<bool> {
11+
@override
12+
final String name = 'post-checkout';
13+
14+
@override
15+
final String description = 'Checks that run after the worktree is updated';
16+
17+
@override
18+
Future<bool> run() async {
19+
printGclientSyncReminder(name);
20+
return true;
21+
}
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:args/command_runner.dart';
6+
7+
import 'messages.dart';
8+
9+
/// The command that implements the post-merge githook
10+
class PostMergeCommand extends Command<bool> {
11+
@override
12+
final String name = 'post-merge';
13+
14+
@override
15+
final String description = 'Checks to run after a "git merge"';
16+
17+
@override
18+
Future<bool> run() async {
19+
printGclientSyncReminder(name);
20+
return true;
21+
}
22+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:args/command_runner.dart';
6+
7+
import 'messages.dart';
8+
9+
/// The command that implements the pre-rebase githook
10+
class PreRebaseCommand extends Command<bool> {
11+
@override
12+
final String name = 'pre-rebase';
13+
14+
@override
15+
final String description = 'Checks to run before a "git rebase"';
16+
17+
@override
18+
Future<bool> run() async {
19+
printGclientSyncReminder(name);
20+
// Returning false here will block the rebase.
21+
return true;
22+
}
23+
}

tools/githooks/post-checkout

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env python3
2+
# Copyright 2013 The Flutter Authors. All rights reserved.
3+
# Use of this source code is governed by a BSD-style license that can be
4+
# found in the LICENSE file.
5+
6+
'''
7+
Runs the post-checkout githooks.
8+
'''
9+
10+
import os
11+
import subprocess
12+
import sys
13+
14+
SRC_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
15+
FLUTTER_DIR = os.path.join(SRC_ROOT, 'flutter')
16+
DART_BIN = os.path.join(SRC_ROOT, 'third_party', 'dart', 'tools', 'sdks', 'dart-sdk', 'bin')
17+
18+
def Main(argv):
19+
githook_args = [
20+
'--flutter',
21+
FLUTTER_DIR,
22+
]
23+
24+
result = subprocess.run([
25+
os.path.join(DART_BIN, 'dart'),
26+
'--disable-dart-dev',
27+
os.path.join(FLUTTER_DIR, 'tools', 'githooks', 'bin', 'main.dart'),
28+
] + githook_args + [
29+
'post-checkout',
30+
] + argv[1:], cwd=SRC_ROOT)
31+
return result.returncode
32+
33+
34+
if __name__ == '__main__':
35+
sys.exit(Main(sys.argv))

tools/githooks/post-merge

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env python3
2+
# Copyright 2013 The Flutter Authors. All rights reserved.
3+
# Use of this source code is governed by a BSD-style license that can be
4+
# found in the LICENSE file.
5+
6+
'''
7+
Runs the post-merge githooks.
8+
'''
9+
10+
import os
11+
import subprocess
12+
import sys
13+
14+
SRC_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
15+
FLUTTER_DIR = os.path.join(SRC_ROOT, 'flutter')
16+
DART_BIN = os.path.join(SRC_ROOT, 'third_party', 'dart', 'tools', 'sdks', 'dart-sdk', 'bin')
17+
18+
def Main(argv):
19+
githook_args = [
20+
'--flutter',
21+
FLUTTER_DIR,
22+
]
23+
24+
result = subprocess.run([
25+
os.path.join(DART_BIN, 'dart'),
26+
'--disable-dart-dev',
27+
os.path.join(FLUTTER_DIR, 'tools', 'githooks', 'bin', 'main.dart'),
28+
] + githook_args + [
29+
'post-merge',
30+
] + argv[1:], cwd=SRC_ROOT)
31+
return result.returncode
32+
33+
34+
if __name__ == '__main__':
35+
sys.exit(Main(sys.argv))

tools/githooks/pre-push

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env vpython3
1+
#!/usr/bin/env python3
22
# Copyright 2013 The Flutter Authors. All rights reserved.
33
# Use of this source code is governed by a BSD-style license that can be
44
# found in the LICENSE file.
@@ -34,7 +34,7 @@ def Main(argv):
3434
os.path.join(FLUTTER_DIR, 'tools', 'githooks', 'bin', 'main.dart'),
3535
] + githook_args + [
3636
'pre-push',
37-
], cwd=SRC_ROOT)
37+
] + argv[1:], cwd=SRC_ROOT)
3838
return result.returncode
3939

4040

tools/githooks/pre-rebase

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env python3
2+
# Copyright 2013 The Flutter Authors. All rights reserved.
3+
# Use of this source code is governed by a BSD-style license that can be
4+
# found in the LICENSE file.
5+
6+
'''
7+
Runs the pre-rebase githooks.
8+
'''
9+
10+
import os
11+
import subprocess
12+
import sys
13+
14+
SRC_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
15+
FLUTTER_DIR = os.path.join(SRC_ROOT, 'flutter')
16+
DART_BIN = os.path.join(SRC_ROOT, 'third_party', 'dart', 'tools', 'sdks', 'dart-sdk', 'bin')
17+
18+
def Main(argv):
19+
githook_args = [
20+
'--flutter',
21+
FLUTTER_DIR,
22+
]
23+
24+
result = subprocess.run([
25+
os.path.join(DART_BIN, 'dart'),
26+
'--disable-dart-dev',
27+
os.path.join(FLUTTER_DIR, 'tools', 'githooks', 'bin', 'main.dart'),
28+
] + githook_args + [
29+
'pre-rebase',
30+
] + argv[1:], cwd=SRC_ROOT)
31+
return result.returncode
32+
33+
34+
if __name__ == '__main__':
35+
sys.exit(Main(sys.argv))

tools/githooks/test/githooks_test.dart

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,52 @@ void main() {
6666
}
6767
expect(result, equals(1));
6868
});
69+
70+
test('post-merge runs successfully', () async {
71+
int? result;
72+
try {
73+
final io.Directory flutterPath = io.File(io.Platform.script.path)
74+
.parent.parent.parent;
75+
result = await run(<String>[
76+
'post-merge',
77+
'--flutter',
78+
flutterPath.path,
79+
]);
80+
} catch (e, st) {
81+
fail('Unexpected exception: $e\n$st');
82+
}
83+
expect(result, equals(0));
84+
});
85+
86+
test('pre-rebase runs successfully', () async {
87+
int? result;
88+
try {
89+
final io.Directory flutterPath = io.File(io.Platform.script.path)
90+
.parent.parent.parent;
91+
result = await run(<String>[
92+
'pre-rebase',
93+
'--flutter',
94+
flutterPath.path,
95+
]);
96+
} catch (e, st) {
97+
fail('Unexpected exception: $e\n$st');
98+
}
99+
expect(result, equals(0));
100+
});
101+
102+
test('post-checkout runs successfully', () async {
103+
int? result;
104+
try {
105+
final io.Directory flutterPath = io.File(io.Platform.script.path)
106+
.parent.parent.parent;
107+
result = await run(<String>[
108+
'post-checkout',
109+
'--flutter',
110+
flutterPath.path,
111+
]);
112+
} catch (e, st) {
113+
fail('Unexpected exception: $e\n$st');
114+
}
115+
expect(result, equals(0));
116+
});
69117
}

0 commit comments

Comments
 (0)