feat(repository): add ability to lookup different types of git objects with []

This commit is contained in:
Aleksey Kulikov 2021-09-04 12:04:28 +03:00
parent f19a34a768
commit 2cf974c624
14 changed files with 124 additions and 67 deletions

View file

@ -93,21 +93,21 @@ class Index {
/// Updates the contents of an existing index object in memory by reading from the
/// specified tree.
void readTree(Object target) {
late final Oid oid;
late final Tree tree;
if (target is Oid) {
final repo = Repository(bindings.owner(_indexPointer));
tree = Tree.lookup(repo, target);
tree = Tree.lookup(repo, target.sha);
} else if (target is Tree) {
tree = target;
} else if (isValidShaHex(target as String)) {
} else if (target is String) {
final repo = Repository(bindings.owner(_indexPointer));
oid = Oid.fromSHA(repo, target);
tree = Tree.lookup(repo, oid);
tree = Tree.lookup(repo, target);
} else {
throw ArgumentError.value(
'$target should be either Oid object, SHA hex string or Tree object');
}
bindings.readTree(_indexPointer, tree.pointer);
tree.free();
}