This repository was archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[flutter_plugin_tools] Restructure version-check #4111
Merged
stuartmorgan-g
merged 6 commits into
flutter:master
from
stuartmorgan-g:tool-package-looper-version-check
Jun 28, 2021
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
44daf78
Factor out some helpers
stuartmorgan-g d1f2eb1
Switch to package-based iteration, and use version from disk rather t…
stuartmorgan-g 5379e2b
Extract a helper for the version change check.
stuartmorgan-g 00fd1c5
Combine the loops
stuartmorgan-g 2ecd187
Migrate to new base command; simplify output
stuartmorgan-g 13ed3c9
Address review feedback
stuartmorgan-g File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,8 +20,8 @@ abstract class PluginCommand extends Command<void> { | |
PluginCommand( | ||
this.packagesDir, { | ||
this.processRunner = const ProcessRunner(), | ||
this.gitDir, | ||
}) { | ||
GitDir? gitDir, | ||
}) : _gitDir = gitDir { | ||
argParser.addMultiOption( | ||
_pluginsArg, | ||
splitCommas: true, | ||
|
@@ -76,10 +76,11 @@ abstract class PluginCommand extends Command<void> { | |
/// This can be overridden for testing. | ||
final ProcessRunner processRunner; | ||
|
||
/// The git directory to use. By default it uses the parent directory. | ||
/// The git directory to use. If unset, [getGitDir] uses the packages | ||
/// directory's enclosing repository. | ||
/// | ||
/// This can be mocked for testing. | ||
final GitDir? gitDir; | ||
GitDir? _gitDir; | ||
|
||
int? _shardIndex; | ||
int? _shardCount; | ||
|
@@ -100,6 +101,26 @@ abstract class PluginCommand extends Command<void> { | |
return _shardCount!; | ||
} | ||
|
||
/// Returns the [GitDir] containing [packagesDir]. | ||
Future<GitDir> getGitDir() async { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: This should be a property. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed. I wasn't aware that properties could be async. |
||
GitDir? gitDir = _gitDir; | ||
if (gitDir != null) { | ||
return gitDir; | ||
} | ||
|
||
// Ensure there are no symlinks in the path, as it can break | ||
// GitDir's allowSubdirectory:true. | ||
final String packagesPath = packagesDir.resolveSymbolicLinksSync(); | ||
if (!await GitDir.isGitDir(packagesPath)) { | ||
printError('$packagesPath is not a valid Git repository.'); | ||
throw ToolExit(2); | ||
} | ||
gitDir = | ||
await GitDir.fromExisting(packagesDir.path, allowSubdirectory: true); | ||
_gitDir = gitDir; | ||
return gitDir; | ||
} | ||
|
||
/// Convenience accessor for boolean arguments. | ||
bool getBoolArg(String key) { | ||
return (argResults![key] as bool?) ?? false; | ||
|
@@ -285,22 +306,10 @@ abstract class PluginCommand extends Command<void> { | |
/// | ||
/// Throws tool exit if [gitDir] nor root directory is a git directory. | ||
Future<GitVersionFinder> retrieveVersionFinder() async { | ||
final String rootDir = packagesDir.parent.absolute.path; | ||
final String baseSha = getStringArg(_kBaseSha); | ||
|
||
GitDir? baseGitDir = gitDir; | ||
if (baseGitDir == null) { | ||
if (!await GitDir.isGitDir(rootDir)) { | ||
printError( | ||
'$rootDir is not a valid Git repository.', | ||
); | ||
throw ToolExit(2); | ||
} | ||
baseGitDir = await GitDir.fromExisting(rootDir); | ||
} | ||
|
||
final GitVersionFinder gitVersionFinder = | ||
GitVersionFinder(baseGitDir, baseSha); | ||
GitVersionFinder(await getGitDir(), baseSha); | ||
return gitVersionFinder; | ||
} | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a late final non-null field, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's used as a cache, so cannot be late final.