mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-05 04:39:07 -04:00
refactor!: return sets of git type flags instead of integers
This commit is contained in:
parent
050c0eb57a
commit
7618f944c0
12 changed files with 459 additions and 191 deletions
|
@ -29,7 +29,7 @@ void main() {
|
|||
File('${tmpDir}feature_file').writeAsStringSync('edit');
|
||||
expect(repo.status, contains('feature_file'));
|
||||
|
||||
repo.checkout(refName: 'HEAD', strategy: [GitCheckout.force]);
|
||||
repo.checkout(refName: 'HEAD', strategy: {GitCheckout.force});
|
||||
expect(repo.status, isEmpty);
|
||||
});
|
||||
|
||||
|
@ -37,7 +37,10 @@ void main() {
|
|||
File('${repo.workdir}feature_file').writeAsStringSync('edit');
|
||||
expect(repo.status, contains('feature_file'));
|
||||
|
||||
repo.checkout(strategy: [GitCheckout.force]);
|
||||
repo.checkout(strategy: {
|
||||
GitCheckout.force,
|
||||
GitCheckout.conflictStyleMerge,
|
||||
});
|
||||
expect(repo.status, isEmpty);
|
||||
});
|
||||
|
||||
|
@ -90,7 +93,12 @@ void main() {
|
|||
refName: 'refs/heads/feature',
|
||||
paths: ['another_feature_file'],
|
||||
);
|
||||
expect(repo.status, {'another_feature_file': GitStatus.indexNew.value});
|
||||
expect(
|
||||
repo.status,
|
||||
{
|
||||
'another_feature_file': {GitStatus.indexNew}
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -31,7 +31,8 @@ void main() {
|
|||
repo['c68ff54aabf660fcdd9a2838d401583fe31249e3'] as Commit;
|
||||
|
||||
final result = repo.mergeAnalysis(commit.id);
|
||||
expect(result[0], GitMergeAnalysis.upToDate.value);
|
||||
expect(result[0], {GitMergeAnalysis.upToDate});
|
||||
expect(result[1], {GitMergePreference.none});
|
||||
expect(repo.status, isEmpty);
|
||||
|
||||
commit.free();
|
||||
|
@ -42,7 +43,7 @@ void main() {
|
|||
repo['c68ff54aabf660fcdd9a2838d401583fe31249e3'] as Commit;
|
||||
|
||||
final result = repo.mergeAnalysis(commit.id, 'refs/tags/v0.1');
|
||||
expect(result[0], GitMergeAnalysis.upToDate.value);
|
||||
expect(result[0], {GitMergeAnalysis.upToDate});
|
||||
expect(repo.status, isEmpty);
|
||||
|
||||
commit.free();
|
||||
|
@ -61,7 +62,7 @@ void main() {
|
|||
final result = repo.mergeAnalysis(theirHead.id, ffBranch.name);
|
||||
expect(
|
||||
result[0],
|
||||
GitMergeAnalysis.fastForward.value + GitMergeAnalysis.normal.value,
|
||||
{GitMergeAnalysis.fastForward, GitMergeAnalysis.normal},
|
||||
);
|
||||
expect(repo.status, isEmpty);
|
||||
|
||||
|
@ -75,7 +76,7 @@ void main() {
|
|||
repo['5aecfa0fb97eadaac050ccb99f03c3fb65460ad4'] as Commit;
|
||||
|
||||
final result = repo.mergeAnalysis(commit.id);
|
||||
expect(result[0], GitMergeAnalysis.normal.value);
|
||||
expect(result[0], {GitMergeAnalysis.normal});
|
||||
expect(repo.status, isEmpty);
|
||||
|
||||
commit.free();
|
||||
|
@ -87,13 +88,18 @@ void main() {
|
|||
final index = repo.index;
|
||||
|
||||
final result = repo.mergeAnalysis(conflictBranch.target);
|
||||
expect(result[0], GitMergeAnalysis.normal.value);
|
||||
expect(result[0], {GitMergeAnalysis.normal});
|
||||
|
||||
repo.merge(conflictBranch.target);
|
||||
expect(index.hasConflicts, true);
|
||||
expect(index.conflicts.length, 1);
|
||||
expect(repo.state, GitRepositoryState.merge.value);
|
||||
expect(repo.status, {'conflict_file': GitStatus.conflicted.value});
|
||||
expect(repo.state, GitRepositoryState.merge);
|
||||
expect(
|
||||
repo.status,
|
||||
{
|
||||
'conflict_file': {GitStatus.conflicted}
|
||||
},
|
||||
);
|
||||
|
||||
final conflictedFile = index.conflicts['conflict_file']!;
|
||||
expect(conflictedFile.ancestor, null);
|
||||
|
@ -104,7 +110,12 @@ void main() {
|
|||
index.write();
|
||||
expect(index.hasConflicts, false);
|
||||
expect(index.conflicts, isEmpty);
|
||||
expect(repo.status, {'conflict_file': GitStatus.indexModified.value});
|
||||
expect(
|
||||
repo.status,
|
||||
{
|
||||
'conflict_file': {GitStatus.indexModified}
|
||||
},
|
||||
);
|
||||
|
||||
index.free();
|
||||
conflictBranch.free();
|
||||
|
@ -172,6 +183,32 @@ void main() {
|
|||
ourCommit.free();
|
||||
theirCommit.free();
|
||||
});
|
||||
|
||||
test('successfully merges with provided merge and file flags', () {
|
||||
final theirCommit =
|
||||
repo['5aecfa0fb97eadaac050ccb99f03c3fb65460ad4'] as Commit;
|
||||
final ourCommit =
|
||||
repo['14905459d775f3f56a39ebc2ff081163f7da3529'] as Commit;
|
||||
|
||||
final mergeIndex = repo.mergeCommits(
|
||||
ourCommit: ourCommit,
|
||||
theirCommit: theirCommit,
|
||||
mergeFlags: {
|
||||
GitMergeFlag.findRenames,
|
||||
GitMergeFlag.noRecursive,
|
||||
},
|
||||
fileFlags: {
|
||||
GitMergeFileFlag.ignoreWhitespace,
|
||||
GitMergeFileFlag.ignoreWhitespaceEOL,
|
||||
GitMergeFileFlag.styleMerge,
|
||||
},
|
||||
);
|
||||
expect(mergeIndex.conflicts, isEmpty);
|
||||
|
||||
mergeIndex.free();
|
||||
ourCommit.free();
|
||||
theirCommit.free();
|
||||
});
|
||||
});
|
||||
|
||||
group('merge trees', () {
|
||||
|
@ -246,7 +283,7 @@ void main() {
|
|||
test('successfully cherry-picks commit', () {
|
||||
final cherry = repo['5aecfa0fb97eadaac050ccb99f03c3fb65460ad4'] as Commit;
|
||||
repo.cherryPick(cherry);
|
||||
expect(repo.state, GitRepositoryState.cherrypick.value);
|
||||
expect(repo.state, GitRepositoryState.cherrypick);
|
||||
expect(repo.message, 'add another feature file\n');
|
||||
final index = repo.index;
|
||||
expect(index.conflicts, isEmpty);
|
||||
|
|
|
@ -343,7 +343,13 @@ void main() {
|
|||
final index = repo.index;
|
||||
index.remove('file');
|
||||
index.add('new_file.txt');
|
||||
expect(repo.status, {'file': 132, 'new_file.txt': 1});
|
||||
expect(
|
||||
repo.status,
|
||||
{
|
||||
'file': {GitStatus.indexDeleted, GitStatus.wtNew},
|
||||
'new_file.txt': {GitStatus.indexNew}
|
||||
},
|
||||
);
|
||||
|
||||
index.free();
|
||||
});
|
||||
|
@ -351,7 +357,11 @@ void main() {
|
|||
test('returns status of a single file for provided path', () {
|
||||
final index = repo.index;
|
||||
index.remove('file');
|
||||
expect(repo.statusFile('file'), 132);
|
||||
expect(
|
||||
repo.statusFile('file'),
|
||||
{GitStatus.indexDeleted, GitStatus.wtNew},
|
||||
);
|
||||
expect(repo.statusFile('.gitignore'), {GitStatus.current});
|
||||
|
||||
index.free();
|
||||
});
|
||||
|
|
|
@ -81,7 +81,7 @@ void main() {
|
|||
|
||||
expect(revspec.from.id.sha, headSHA);
|
||||
expect(revspec.to, isNull);
|
||||
expect(revspec.flags, GitRevParse.single);
|
||||
expect(revspec.flags, {GitRevParse.single});
|
||||
|
||||
revspec.from.free();
|
||||
|
||||
|
@ -89,7 +89,7 @@ void main() {
|
|||
|
||||
expect(revspec.from.id.sha, parentSHA);
|
||||
expect(revspec.to?.id.sha, '5aecfa0fb97eadaac050ccb99f03c3fb65460ad4');
|
||||
expect(revspec.flags, GitRevParse.range);
|
||||
expect(revspec.flags, {GitRevParse.range});
|
||||
|
||||
revspec.from.free();
|
||||
revspec.to?.free();
|
||||
|
@ -98,7 +98,7 @@ void main() {
|
|||
|
||||
expect(revspec.from.id.sha, headSHA);
|
||||
expect(revspec.to?.id.sha, '5aecfa0fb97eadaac050ccb99f03c3fb65460ad4');
|
||||
expect(revspec.flags, GitRevParse.mergeBase);
|
||||
expect(revspec.flags, {GitRevParse.range, GitRevParse.mergeBase});
|
||||
expect(
|
||||
repo.mergeBase(revspec.from.id.sha, revspec.to!.id.sha),
|
||||
isA<Oid>(),
|
||||
|
|
|
@ -53,7 +53,7 @@ void main() {
|
|||
final start = Oid.fromSHA(repo, log.first);
|
||||
|
||||
walker.push(start);
|
||||
walker.sorting([GitSort.reverse]);
|
||||
walker.sorting({GitSort.reverse});
|
||||
final commits = walker.walk();
|
||||
|
||||
for (var i = 0; i < commits.length; i++) {
|
||||
|
@ -77,7 +77,7 @@ void main() {
|
|||
expect(timeSortedCommits[i].id.sha, log[i]);
|
||||
}
|
||||
|
||||
walker.sorting([GitSort.time, GitSort.reverse]);
|
||||
walker.sorting({GitSort.time, GitSort.reverse});
|
||||
final reverseSortedCommits = walker.walk();
|
||||
for (var i = 0; i < reverseSortedCommits.length; i++) {
|
||||
expect(reverseSortedCommits[i].id.sha, log.reversed.toList()[i]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue