mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-05 04:39:07 -04:00
refactor(checkout)!: move checkout related methods into Checkout class (#42)
This commit is contained in:
parent
570c696269
commit
9918ab0905
10 changed files with 238 additions and 135 deletions
|
@ -134,7 +134,7 @@ void main() {
|
|||
});
|
||||
|
||||
test('filters content of a blob with provided commit for attributes', () {
|
||||
repo.checkout(target: 'refs/tags/v0.2');
|
||||
Checkout.reference(repo: repo, name: 'refs/tags/v0.2');
|
||||
|
||||
final blobOid = Blob.create(repo: repo, content: 'clrf\nclrf\n');
|
||||
final blob = Blob.lookup(repo: repo, oid: blobOid);
|
||||
|
|
|
@ -27,8 +27,8 @@ void main() {
|
|||
File(p.join(tmpDir.path, 'feature_file')).writeAsStringSync('edit');
|
||||
expect(repo.status, contains('feature_file'));
|
||||
|
||||
repo.checkout(
|
||||
target: 'HEAD',
|
||||
Checkout.head(
|
||||
repo: repo,
|
||||
strategy: {GitCheckout.force},
|
||||
paths: ['feature_file'],
|
||||
);
|
||||
|
@ -39,8 +39,8 @@ void main() {
|
|||
'throws when trying to checkout head with invalid alternative '
|
||||
'directory', () {
|
||||
expect(
|
||||
() => repo.checkout(
|
||||
target: 'HEAD',
|
||||
() => Checkout.head(
|
||||
repo: repo,
|
||||
directory: 'not/there',
|
||||
),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
|
@ -51,7 +51,8 @@ void main() {
|
|||
File(p.join(repo.workdir, 'feature_file')).writeAsStringSync('edit');
|
||||
expect(repo.status, contains('feature_file'));
|
||||
|
||||
repo.checkout(
|
||||
Checkout.index(
|
||||
repo: repo,
|
||||
strategy: {
|
||||
GitCheckout.force,
|
||||
GitCheckout.conflictStyleMerge,
|
||||
|
@ -65,7 +66,7 @@ void main() {
|
|||
'throws when trying to checkout index with invalid alternative '
|
||||
'directory', () {
|
||||
expect(
|
||||
() => repo.checkout(directory: 'not/there'),
|
||||
() => Checkout.index(repo: repo, directory: 'not/there'),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
@ -78,12 +79,12 @@ void main() {
|
|||
false,
|
||||
);
|
||||
|
||||
repo.checkout(target: 'refs/heads/feature');
|
||||
Checkout.reference(repo: repo, name: 'refs/heads/feature');
|
||||
final featureHead = Commit.lookup(repo: repo, oid: repo['5aecfa0']);
|
||||
final featureTree = featureHead.tree;
|
||||
final repoHead = repo.head;
|
||||
expect(repoHead.target, featureHead.oid);
|
||||
expect(repo.status, isEmpty);
|
||||
// does not change HEAD
|
||||
expect(repoHead.target, isNot(featureHead.oid));
|
||||
expect(
|
||||
featureTree.entries.any((e) => e.name == 'another_feature_file'),
|
||||
true,
|
||||
|
@ -100,8 +101,9 @@ void main() {
|
|||
'throws when trying to checkout reference with invalid alternative '
|
||||
'directory', () {
|
||||
expect(
|
||||
() => repo.checkout(
|
||||
target: 'refs/heads/feature',
|
||||
() => Checkout.reference(
|
||||
repo: repo,
|
||||
name: 'refs/heads/feature',
|
||||
directory: 'not/there',
|
||||
),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
|
@ -113,11 +115,11 @@ void main() {
|
|||
expect(index.find('another_feature_file'), equals(false));
|
||||
|
||||
final featureHead = Commit.lookup(repo: repo, oid: repo['5aecfa0']);
|
||||
repo.checkout(target: featureHead.oid);
|
||||
Checkout.commit(repo: repo, commit: featureHead);
|
||||
|
||||
final repoHead = repo.head;
|
||||
expect(repoHead.target, featureHead.oid);
|
||||
expect(repo.status, isEmpty);
|
||||
// does not change HEAD
|
||||
expect(repoHead.target, isNot(featureHead.oid));
|
||||
expect(index.find('another_feature_file'), equals(true));
|
||||
|
||||
repoHead.free();
|
||||
|
@ -127,10 +129,14 @@ void main() {
|
|||
|
||||
test('checkouts commit with provided path', () {
|
||||
final featureHead = Commit.lookup(repo: repo, oid: repo['5aecfa0']);
|
||||
repo.checkout(target: featureHead.oid, paths: ['another_feature_file']);
|
||||
Checkout.commit(
|
||||
repo: repo,
|
||||
commit: featureHead,
|
||||
paths: ['another_feature_file'],
|
||||
);
|
||||
|
||||
final repoHead = repo.head;
|
||||
// When path is provided HEAD will not be set to target;
|
||||
// does not change HEAD
|
||||
expect(repoHead.target, isNot(featureHead.oid));
|
||||
expect(
|
||||
repo.status,
|
||||
|
@ -143,6 +149,23 @@ void main() {
|
|||
featureHead.free();
|
||||
});
|
||||
|
||||
test(
|
||||
'throws when trying to checkout commit with invalid alternative '
|
||||
'directory', () {
|
||||
final commit = Commit.lookup(repo: repo, oid: repo['5aecfa0']);
|
||||
|
||||
expect(
|
||||
() => Checkout.commit(
|
||||
repo: repo,
|
||||
commit: commit,
|
||||
directory: 'not/there',
|
||||
),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
|
||||
commit.free();
|
||||
});
|
||||
|
||||
test('checkouts with alrenative directory', () {
|
||||
final altDir = Directory(p.join(Directory.systemTemp.path, 'alt_dir'));
|
||||
// making sure there is no directory
|
||||
|
@ -152,7 +175,11 @@ void main() {
|
|||
altDir.createSync();
|
||||
expect(altDir.listSync().length, 0);
|
||||
|
||||
repo.checkout(target: 'refs/heads/feature', directory: altDir.path);
|
||||
Checkout.reference(
|
||||
repo: repo,
|
||||
name: 'refs/heads/feature',
|
||||
directory: altDir.path,
|
||||
);
|
||||
expect(altDir.listSync().length, isNot(0));
|
||||
|
||||
altDir.deleteSync(recursive: true);
|
||||
|
@ -165,8 +192,9 @@ void main() {
|
|||
).target;
|
||||
|
||||
expect(repo.status, isEmpty);
|
||||
repo.checkout(
|
||||
target: 'refs/heads/feature',
|
||||
Checkout.reference(
|
||||
repo: repo,
|
||||
name: 'refs/heads/feature',
|
||||
paths: ['another_feature_file'],
|
||||
);
|
||||
expect(
|
||||
|
@ -175,7 +203,7 @@ void main() {
|
|||
'another_feature_file': {GitStatus.indexNew}
|
||||
},
|
||||
);
|
||||
// When path is provided HEAD will not be set to target;
|
||||
// does not change HEAD
|
||||
expect(repo.head.target, isNot(featureTip));
|
||||
});
|
||||
|
||||
|
@ -185,8 +213,9 @@ void main() {
|
|||
final file = File(p.join(repo.workdir, 'another_feature_file'));
|
||||
expect(file.existsSync(), false);
|
||||
|
||||
repo.checkout(
|
||||
target: 'refs/heads/feature',
|
||||
Checkout.reference(
|
||||
repo: repo,
|
||||
name: 'refs/heads/feature',
|
||||
strategy: {GitCheckout.dryRun},
|
||||
);
|
||||
expect(index.length, 4);
|
||||
|
@ -194,9 +223,5 @@ void main() {
|
|||
|
||||
index.free();
|
||||
});
|
||||
|
||||
test('throws when provided target is not String or Oid', () {
|
||||
expect(() => repo.checkout(target: 1), throwsA(isA<ArgumentError>()));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -323,7 +323,7 @@ index e69de29..c217c63 100644
|
|||
);
|
||||
|
||||
final diff2 = Diff.parse(patchText);
|
||||
repo.checkout(target: 'HEAD', strategy: {GitCheckout.force});
|
||||
Checkout.head(repo: repo, strategy: {GitCheckout.force});
|
||||
expect(
|
||||
diff2.applies(repo: repo, location: GitApplyLocation.both),
|
||||
true,
|
||||
|
@ -345,7 +345,7 @@ index e69de29..c217c63 100644
|
|||
|
||||
final diff2 = Diff.parse(patchText);
|
||||
final hunk = diff2.patches.first.hunks.first;
|
||||
repo.checkout(target: 'HEAD', strategy: {GitCheckout.force});
|
||||
Checkout.head(repo: repo, strategy: {GitCheckout.force});
|
||||
expect(
|
||||
diff2.applies(
|
||||
repo: repo,
|
||||
|
@ -364,7 +364,7 @@ index e69de29..c217c63 100644
|
|||
final diff = Diff.parse(patchText);
|
||||
final file = File(p.join(tmpDir.path, 'subdir', 'modified_file'));
|
||||
|
||||
repo.checkout(target: 'HEAD', strategy: {GitCheckout.force});
|
||||
Checkout.head(repo: repo, strategy: {GitCheckout.force});
|
||||
expect(file.readAsStringSync(), '');
|
||||
|
||||
diff.apply(repo: repo);
|
||||
|
@ -396,7 +396,7 @@ index e69de29..c217c63 100644
|
|||
final hunk = diff.patches.first.hunks.first;
|
||||
final file = File(p.join(tmpDir.path, 'subdir', 'modified_file'));
|
||||
|
||||
repo.checkout(target: 'HEAD', strategy: {GitCheckout.force});
|
||||
Checkout.head(repo: repo, strategy: {GitCheckout.force});
|
||||
expect(file.readAsStringSync(), '');
|
||||
|
||||
diff.apply(repo: repo, hunkIndex: hunk.index);
|
||||
|
@ -408,7 +408,7 @@ index e69de29..c217c63 100644
|
|||
test('applies diff to tree', () {
|
||||
final diff = Diff.parse(patchText);
|
||||
|
||||
repo.checkout(target: 'HEAD', strategy: {GitCheckout.force});
|
||||
Checkout.head(repo: repo, strategy: {GitCheckout.force});
|
||||
final head = repo.head;
|
||||
final commit = Commit.lookup(repo: repo, oid: head.target);
|
||||
final tree = commit.tree;
|
||||
|
@ -441,7 +441,7 @@ index e69de29..c217c63 100644
|
|||
final diff = Diff.parse(patchText);
|
||||
final hunk = diff.patches.first.hunks.first;
|
||||
|
||||
repo.checkout(target: 'HEAD', strategy: {GitCheckout.force});
|
||||
Checkout.head(repo: repo, strategy: {GitCheckout.force});
|
||||
final head = repo.head;
|
||||
final commit = Commit.lookup(repo: repo, oid: head.target);
|
||||
final tree = commit.tree;
|
||||
|
|
|
@ -364,7 +364,8 @@ void main() {
|
|||
oid: conflictBranch.target,
|
||||
);
|
||||
|
||||
conflictRepo.checkout(target: 'refs/heads/feature');
|
||||
Checkout.reference(repo: conflictRepo, name: 'refs/heads/feature');
|
||||
conflictRepo.setHead('refs/heads/feature');
|
||||
|
||||
Merge.commit(repo: conflictRepo, commit: commit);
|
||||
|
||||
|
@ -424,7 +425,8 @@ void main() {
|
|||
oid: conflictBranch.target,
|
||||
);
|
||||
|
||||
conflictRepo.checkout(target: 'refs/heads/our-conflict');
|
||||
Checkout.reference(repo: conflictRepo, name: 'refs/heads/our-conflict');
|
||||
conflictRepo.setHead('refs/heads/our-conflict');
|
||||
|
||||
Merge.commit(repo: conflictRepo, commit: commit);
|
||||
|
||||
|
@ -455,7 +457,8 @@ void main() {
|
|||
oid: conflictBranch.target,
|
||||
);
|
||||
|
||||
conflictRepo.checkout(target: 'refs/heads/feature');
|
||||
Checkout.reference(repo: conflictRepo, name: 'refs/heads/feature');
|
||||
conflictRepo.setHead('refs/heads/feature');
|
||||
|
||||
Merge.commit(repo: conflictRepo, commit: commit);
|
||||
|
||||
|
|
|
@ -172,7 +172,8 @@ Another feature edit
|
|||
repo: repo,
|
||||
oid: conflictBranch.target,
|
||||
);
|
||||
repo.checkout(target: 'refs/heads/feature');
|
||||
Checkout.reference(repo: repo, name: 'refs/heads/feature');
|
||||
repo.setHead('refs/heads/feature');
|
||||
final index = repo.index;
|
||||
|
||||
Merge.commit(repo: repo, commit: commit);
|
||||
|
|
|
@ -43,7 +43,8 @@ void main() {
|
|||
reference: feature,
|
||||
);
|
||||
|
||||
repo.checkout(target: feature.name);
|
||||
Checkout.reference(repo: repo, name: feature.name);
|
||||
repo.setHead(feature.name);
|
||||
expect(() => repo.index['.gitignore'], throwsA(isA<ArgumentError>()));
|
||||
|
||||
final rebase = Rebase.init(
|
||||
|
@ -141,7 +142,8 @@ void main() {
|
|||
final feature = Reference.lookup(repo: repo, name: 'refs/heads/feature');
|
||||
final upstream = AnnotatedCommit.lookup(repo: repo, oid: repo[shas[1]]);
|
||||
|
||||
repo.checkout(target: feature.name);
|
||||
Checkout.reference(repo: repo, name: feature.name);
|
||||
repo.setHead(feature.name);
|
||||
expect(() => repo.index['conflict_file'], throwsA(isA<ArgumentError>()));
|
||||
|
||||
final rebase = Rebase.init(
|
||||
|
@ -197,7 +199,8 @@ void main() {
|
|||
);
|
||||
final ontoHead = AnnotatedCommit.lookup(repo: repo, oid: conflict.target);
|
||||
|
||||
repo.checkout(target: conflict.name);
|
||||
Checkout.reference(repo: repo, name: conflict.name);
|
||||
repo.setHead(conflict.name);
|
||||
|
||||
final rebase = Rebase.init(
|
||||
repo: repo,
|
||||
|
@ -237,7 +240,8 @@ void main() {
|
|||
);
|
||||
final ontoHead = AnnotatedCommit.lookup(repo: repo, oid: conflict.target);
|
||||
|
||||
repo.checkout(target: conflict.name);
|
||||
Checkout.reference(repo: repo, name: conflict.name);
|
||||
repo.setHead(conflict.name);
|
||||
|
||||
final rebase = Rebase.init(
|
||||
repo: repo,
|
||||
|
@ -266,7 +270,8 @@ void main() {
|
|||
);
|
||||
final ontoHead = AnnotatedCommit.lookup(repo: repo, oid: conflict.target);
|
||||
|
||||
repo.checkout(target: conflict.name);
|
||||
Checkout.reference(repo: repo, name: conflict.name);
|
||||
repo.setHead(conflict.name);
|
||||
|
||||
final rebase = Rebase.init(
|
||||
repo: repo,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue