diff --git a/lib/src/merge.dart b/lib/src/merge.dart index c3c2583..b7b3efb 100644 --- a/lib/src/merge.dart +++ b/lib/src/merge.dart @@ -46,11 +46,10 @@ class Merge { /// opportunities for merging them into [ourRef] reference (default is /// 'HEAD'). /// - /// Returns list with analysis result and preference for fast forward merge - /// values respectively. + /// Returns analysis result and preference for fast forward merge. /// /// Throws a [LibGit2Error] if error occured. - static List analysis({ + static MergeAnalysis analysis({ required Repository repo, required Oid theirHead, String ourRef = 'HEAD', @@ -67,14 +66,14 @@ class Merge { theirHeadsLen: 1, ); - final analysisSet = GitMergeAnalysis.values + final result = GitMergeAnalysis.values .where((e) => analysisInt[0] & e.value == e.value) .toSet(); - final mergePreference = GitMergePreference.values.singleWhere( + final preference = GitMergePreference.values.singleWhere( (e) => analysisInt[1] == e.value, ); - return [analysisSet, mergePreference]; + return MergeAnalysis._(result: result, mergePreference: preference); } /// Merges the given [commit] into HEAD, writing the results into the @@ -296,3 +295,13 @@ class Merge { ); } } + +class MergeAnalysis { + const MergeAnalysis._({required this.result, required this.mergePreference}); + + /// Merge opportunities. + final Set result; + + /// The user's stated preference for merges. + final GitMergePreference mergePreference; +} diff --git a/test/merge_test.dart b/test/merge_test.dart index 8102d9d..7991982 100644 --- a/test/merge_test.dart +++ b/test/merge_test.dart @@ -26,23 +26,19 @@ void main() { group('Merge', () { group('analysis', () { test('is up to date when no reference is provided', () { - expect( - Merge.analysis(repo: repo, theirHead: repo['c68ff54']), - [ - {GitMergeAnalysis.upToDate}, - GitMergePreference.none, - ], - ); + final analysis = Merge.analysis(repo: repo, theirHead: repo['c68ff54']); + expect(analysis.result, {GitMergeAnalysis.upToDate}); + expect(analysis.mergePreference, GitMergePreference.none); expect(repo.status, isEmpty); }); test('is up to date for provided ref', () { - final result = Merge.analysis( + final analysis = Merge.analysis( repo: repo, theirHead: repo['c68ff54'], ourRef: 'refs/tags/v0.1', ); - expect(result[0], {GitMergeAnalysis.upToDate}); + expect(analysis.result, {GitMergeAnalysis.upToDate}); expect(repo.status, isEmpty); }); @@ -53,21 +49,21 @@ void main() { target: Commit.lookup(repo: repo, oid: repo['f17d0d4']), ); - final result = Merge.analysis( + final analysis = Merge.analysis( repo: repo, theirHead: repo['6cbc22e'], ourRef: 'refs/heads/${ffBranch.name}', ); expect( - result[0], + analysis.result, {GitMergeAnalysis.fastForward, GitMergeAnalysis.normal}, ); expect(repo.status, isEmpty); }); test('is not fast forward and there is no conflicts', () { - final result = Merge.analysis(repo: repo, theirHead: repo['5aecfa0']); - expect(result[0], {GitMergeAnalysis.normal}); + final analysis = Merge.analysis(repo: repo, theirHead: repo['5aecfa0']); + expect(analysis.result, {GitMergeAnalysis.normal}); expect(repo.status, isEmpty); }); }); @@ -76,11 +72,11 @@ void main() { final conflictBranch = Branch.lookup(repo: repo, name: 'conflict-branch'); final index = repo.index; - final result = Merge.analysis( + final analysis = Merge.analysis( repo: repo, theirHead: conflictBranch.target, ); - expect(result[0], {GitMergeAnalysis.normal}); + expect(analysis.result, {GitMergeAnalysis.normal}); Merge.commit( repo: repo,