mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-04 12:19:09 -04:00
refactor(merge)!: add MergeAnalysis class containing analysis result and merge preference (#49)
BREAKING CHANGE: Return value of Merge.analysis(...) changed from List<Object> to MergeAnalysis.
This commit is contained in:
parent
9d61584165
commit
6d1ccd5c12
2 changed files with 26 additions and 21 deletions
|
@ -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<Object> 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 <Object>[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<GitMergeAnalysis> result;
|
||||
|
||||
/// The user's stated preference for merges.
|
||||
final GitMergePreference mergePreference;
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue