@@ -11,15 +11,15 @@ import 'package:yaml/yaml.dart';
11
11
/// Finding diffs based on `baseGitDir` and `baseSha` .
12
12
class GitVersionFinder {
13
13
/// Constructor
14
- GitVersionFinder (this .baseGitDir, this . baseSha);
14
+ GitVersionFinder (this .baseGitDir, String ? baseSha) : _baseSha = baseSha ;
15
15
16
16
/// The top level directory of the git repo.
17
17
///
18
18
/// That is where the .git/ folder exists.
19
19
final GitDir baseGitDir;
20
20
21
21
/// The base sha used to get diff.
22
- final String ? baseSha ;
22
+ String ? _baseSha ;
23
23
24
24
static bool _isPubspec (String file) {
25
25
return file.trim ().endsWith ('pubspec.yaml' );
@@ -32,10 +32,9 @@ class GitVersionFinder {
32
32
33
33
/// Get a list of all the changed files.
34
34
Future <List <String >> getChangedFiles () async {
35
- final String baseSha = await _getBaseSha ();
35
+ final String baseSha = await getBaseSha ();
36
36
final io.ProcessResult changedFilesCommand = await baseGitDir
37
37
.runCommand (< String > ['diff' , '--name-only' , baseSha, 'HEAD' ]);
38
- print ('Determine diff with base sha: $baseSha ' );
39
38
final String changedFilesStdout = changedFilesCommand.stdout.toString ();
40
39
if (changedFilesStdout.isEmpty) {
41
40
return < String > [];
@@ -49,7 +48,7 @@ class GitVersionFinder {
49
48
/// at the revision of `gitRef` (defaulting to the base if not provided).
50
49
Future <Version ?> getPackageVersion (String pubspecPath,
51
50
{String ? gitRef}) async {
52
- final String ref = gitRef ?? (await _getBaseSha ());
51
+ final String ref = gitRef ?? (await getBaseSha ());
53
52
54
53
io.ProcessResult gitShow;
55
54
try {
@@ -63,9 +62,11 @@ class GitVersionFinder {
63
62
return versionString == null ? null : Version .parse (versionString);
64
63
}
65
64
66
- Future <String > _getBaseSha () async {
67
- if (baseSha != null && baseSha! .isNotEmpty) {
68
- return baseSha! ;
65
+ /// Returns the base used to diff against.
66
+ Future <String > getBaseSha () async {
67
+ String ? baseSha = _baseSha;
68
+ if (baseSha != null && baseSha.isNotEmpty) {
69
+ return baseSha;
69
70
}
70
71
71
72
io.ProcessResult baseShaFromMergeBase = await baseGitDir.runCommand (
@@ -76,6 +77,8 @@ class GitVersionFinder {
76
77
baseShaFromMergeBase = await baseGitDir
77
78
.runCommand (< String > ['merge-base' , 'FETCH_HEAD' , 'HEAD' ]);
78
79
}
79
- return (baseShaFromMergeBase.stdout as String ).trim ();
80
+ baseSha = (baseShaFromMergeBase.stdout as String ).trim ();
81
+ _baseSha = baseSha;
82
+ return baseSha;
80
83
}
81
84
}
0 commit comments