mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-05 04:39:07 -04:00
refactor(merge)!: add MergeAnalysis class containing analysis result and merge preference
BREAKING CHANGE: Return value of Merge.analysis(...) changed from List<Object> to MergeAnalysis.
This commit is contained in:
parent
9d61584165
commit
68c95cb54f
2 changed files with 26 additions and 21 deletions
|
@ -46,11 +46,10 @@ class Merge {
|
||||||
/// opportunities for merging them into [ourRef] reference (default is
|
/// opportunities for merging them into [ourRef] reference (default is
|
||||||
/// 'HEAD').
|
/// 'HEAD').
|
||||||
///
|
///
|
||||||
/// Returns list with analysis result and preference for fast forward merge
|
/// Returns analysis result and preference for fast forward merge.
|
||||||
/// values respectively.
|
|
||||||
///
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
static List<Object> analysis({
|
static MergeAnalysis analysis({
|
||||||
required Repository repo,
|
required Repository repo,
|
||||||
required Oid theirHead,
|
required Oid theirHead,
|
||||||
String ourRef = 'HEAD',
|
String ourRef = 'HEAD',
|
||||||
|
@ -67,14 +66,14 @@ class Merge {
|
||||||
theirHeadsLen: 1,
|
theirHeadsLen: 1,
|
||||||
);
|
);
|
||||||
|
|
||||||
final analysisSet = GitMergeAnalysis.values
|
final result = GitMergeAnalysis.values
|
||||||
.where((e) => analysisInt[0] & e.value == e.value)
|
.where((e) => analysisInt[0] & e.value == e.value)
|
||||||
.toSet();
|
.toSet();
|
||||||
final mergePreference = GitMergePreference.values.singleWhere(
|
final preference = GitMergePreference.values.singleWhere(
|
||||||
(e) => analysisInt[1] == e.value,
|
(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
|
/// 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('Merge', () {
|
||||||
group('analysis', () {
|
group('analysis', () {
|
||||||
test('is up to date when no reference is provided', () {
|
test('is up to date when no reference is provided', () {
|
||||||
expect(
|
final analysis = Merge.analysis(repo: repo, theirHead: repo['c68ff54']);
|
||||||
Merge.analysis(repo: repo, theirHead: repo['c68ff54']),
|
expect(analysis.result, {GitMergeAnalysis.upToDate});
|
||||||
[
|
expect(analysis.mergePreference, GitMergePreference.none);
|
||||||
{GitMergeAnalysis.upToDate},
|
|
||||||
GitMergePreference.none,
|
|
||||||
],
|
|
||||||
);
|
|
||||||
expect(repo.status, isEmpty);
|
expect(repo.status, isEmpty);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('is up to date for provided ref', () {
|
test('is up to date for provided ref', () {
|
||||||
final result = Merge.analysis(
|
final analysis = Merge.analysis(
|
||||||
repo: repo,
|
repo: repo,
|
||||||
theirHead: repo['c68ff54'],
|
theirHead: repo['c68ff54'],
|
||||||
ourRef: 'refs/tags/v0.1',
|
ourRef: 'refs/tags/v0.1',
|
||||||
);
|
);
|
||||||
expect(result[0], {GitMergeAnalysis.upToDate});
|
expect(analysis.result, {GitMergeAnalysis.upToDate});
|
||||||
expect(repo.status, isEmpty);
|
expect(repo.status, isEmpty);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -53,21 +49,21 @@ void main() {
|
||||||
target: Commit.lookup(repo: repo, oid: repo['f17d0d4']),
|
target: Commit.lookup(repo: repo, oid: repo['f17d0d4']),
|
||||||
);
|
);
|
||||||
|
|
||||||
final result = Merge.analysis(
|
final analysis = Merge.analysis(
|
||||||
repo: repo,
|
repo: repo,
|
||||||
theirHead: repo['6cbc22e'],
|
theirHead: repo['6cbc22e'],
|
||||||
ourRef: 'refs/heads/${ffBranch.name}',
|
ourRef: 'refs/heads/${ffBranch.name}',
|
||||||
);
|
);
|
||||||
expect(
|
expect(
|
||||||
result[0],
|
analysis.result,
|
||||||
{GitMergeAnalysis.fastForward, GitMergeAnalysis.normal},
|
{GitMergeAnalysis.fastForward, GitMergeAnalysis.normal},
|
||||||
);
|
);
|
||||||
expect(repo.status, isEmpty);
|
expect(repo.status, isEmpty);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('is not fast forward and there is no conflicts', () {
|
test('is not fast forward and there is no conflicts', () {
|
||||||
final result = Merge.analysis(repo: repo, theirHead: repo['5aecfa0']);
|
final analysis = Merge.analysis(repo: repo, theirHead: repo['5aecfa0']);
|
||||||
expect(result[0], {GitMergeAnalysis.normal});
|
expect(analysis.result, {GitMergeAnalysis.normal});
|
||||||
expect(repo.status, isEmpty);
|
expect(repo.status, isEmpty);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -76,11 +72,11 @@ void main() {
|
||||||
final conflictBranch = Branch.lookup(repo: repo, name: 'conflict-branch');
|
final conflictBranch = Branch.lookup(repo: repo, name: 'conflict-branch');
|
||||||
final index = repo.index;
|
final index = repo.index;
|
||||||
|
|
||||||
final result = Merge.analysis(
|
final analysis = Merge.analysis(
|
||||||
repo: repo,
|
repo: repo,
|
||||||
theirHead: conflictBranch.target,
|
theirHead: conflictBranch.target,
|
||||||
);
|
);
|
||||||
expect(result[0], {GitMergeAnalysis.normal});
|
expect(analysis.result, {GitMergeAnalysis.normal});
|
||||||
|
|
||||||
Merge.commit(
|
Merge.commit(
|
||||||
repo: repo,
|
repo: repo,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue