Matan Lurey 6fd30fd25a
Wraps all git executions in a Git(...).*, use *=noglob on Windows (#172495)
Closes https://github.com/flutter/flutter/issues/74165.

The original issue called for, on Windows, telling `CYGWIN` to use
`=noglob`, to work around some git operation errors that happen when
using non-native Git. There ... was no great way to do this with the
existing codebase without, IMO, adding lots of confusing code.

So, I refactored all the calls of:
- before: `processUtils.<method>(['git', ...args], ...params)` 
- after: `git.<method>([...args], ...params)`

... and implicitly add the new environment variables, if
`Platform.isWindows`.

Did some minor test cleanup and process execution cleanup while I was at
it.
2025-07-23 00:03:32 +00:00

86 lines
2.8 KiB
Dart

// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/base/process.dart';
import 'package:flutter_tools/src/git.dart';
import '../src/common.dart';
import '../src/fake_process_manager.dart';
void main() {
late BufferLogger logger;
late Git git;
late FakeProcessManager processManager;
setUp(() {
logger = BufferLogger.test();
processManager = FakeProcessManager.empty();
});
// Regression test for https://github.com/flutter/flutter/issues/74165.
group('on Windows', () {
const expectedCygwinEnvVars = {'MSYS': 'noglob', 'CYGWIN': 'noglob'};
setUp(() {
git = Git(
currentPlatform: FakePlatform(operatingSystem: 'windows'),
runProcessWith: ProcessUtils(processManager: processManager, logger: logger),
);
});
test('git.runSync passes ENV=noglob if environment is omitted', () {
processManager.addCommand(
const FakeCommand(command: ['git', 'foo', 'bar'], environment: expectedCygwinEnvVars),
);
git.runSync(['foo', 'bar']);
});
test('git.runSync passes ENV=noglob if environment is present', () {
processManager.addCommand(
const FakeCommand(
command: ['git', 'foo', 'bar'],
environment: {...expectedCygwinEnvVars, 'baz': 'BAZ'},
),
);
git.runSync(['foo', 'bar'], environment: {'baz': 'BAZ'});
});
test('git.run passes ENV=noglob if environment is omitted', () async {
processManager.addCommand(
const FakeCommand(command: ['git', 'foo', 'bar'], environment: expectedCygwinEnvVars),
);
await git.run(['foo', 'bar']);
});
test('git.run passes ENV=noglob if environment is present', () async {
processManager.addCommand(
const FakeCommand(
command: ['git', 'foo', 'bar'],
environment: {...expectedCygwinEnvVars, 'baz': 'BAZ'},
),
);
await git.run(['foo', 'bar'], environment: {'baz': 'BAZ'});
});
test('git.stream passes ENV=noglob if environment is omitted', () async {
processManager.addCommand(
const FakeCommand(command: ['git', 'foo', 'bar'], environment: expectedCygwinEnvVars),
);
await git.stream(['foo', 'bar']);
});
test('git.stream passes ENV=noglob if environment is present', () async {
processManager.addCommand(
const FakeCommand(
command: ['git', 'foo', 'bar'],
environment: {...expectedCygwinEnvVars, 'baz': 'BAZ'},
),
);
await git.stream(['foo', 'bar'], environment: {'baz': 'BAZ'});
});
});
}