Support safe.bareRepository=explicit (#4776)
diff --git a/test/git_test.dart b/test/git_test.dart index 6404988..2ddf65b 100644 --- a/test/git_test.dart +++ b/test/git_test.dart
@@ -5,11 +5,15 @@ @TestOn('vm') library; +import 'dart:io'; import 'dart:typed_data'; import 'package:pub/src/git.dart'; import 'package:test/test.dart'; +import 'descriptor.dart'; +import 'test_pub.dart'; + void main() { test('splitZeroTerminated works', () { expect(splitZeroTerminated(Uint8List.fromList([])), <Uint8List>[]); @@ -47,4 +51,28 @@ throwsA(isA<FormatException>()), ); }); + + test('safe.bareRepository is enabled by default in test environment', () { + // Regression protection for https://github.com/dart-lang/pub/issues/4770. + final r = Process.runSync('git', [ + 'config', + '--get', + 'safe.bareRepository', + ], environment: getPubTestEnvironment()); + expect(r.stdout, contains('explicit')); + Process.runSync( + 'git', + ['init', '--bare'], + workingDirectory: sandbox, + environment: getPubTestEnvironment(), + ); + final r1 = Process.runSync( + 'git', + ['log'], + workingDirectory: sandbox, + environment: getPubTestEnvironment(), + ); + expect(r1.exitCode, isNot(0)); + expect(r1.stderr, contains('fatal: cannot use bare repository ')); + }); }
diff --git a/test/test_pub.dart b/test/test_pub.dart index a4adec3..9aa9343 100644 --- a/test/test_pub.dart +++ b/test/test_pub.dart
@@ -467,6 +467,9 @@ if (tokenEndpoint != null) '_PUB_TEST_TOKEN_ENDPOINT': tokenEndpoint, if (_globalServer?.port != null) 'PUB_HOSTED_URL': 'http://localhost:${_globalServer?.port}', + 'GIT_CONFIG_COUNT': '1', + 'GIT_CONFIG_KEY_0': 'safe.bareRepository', + 'GIT_CONFIG_VALUE_0': 'explicit', }; /// The path to the root of pub's sources in the pub repo.