From 1972c6d1ab9d75538a19cf945ff998b1435efcb1 Mon Sep 17 00:00:00 2001 From: Aleksey Kulikov Date: Wed, 13 Oct 2021 15:31:20 +0300 Subject: [PATCH] refactor!: use Oid instead of String for arguments --- lib/src/bindings/note.dart | 14 ++--- lib/src/bindings/reference.dart | 2 +- lib/src/blame.dart | 12 ++--- lib/src/blob.dart | 10 ++-- lib/src/branch.dart | 2 +- lib/src/commit.dart | 14 ++--- lib/src/diff.dart | 8 ++- lib/src/index.dart | 14 ++--- lib/src/note.dart | 34 ++++++------ lib/src/odb.dart | 8 +-- lib/src/oid.dart | 2 +- lib/src/rebase.dart | 4 +- lib/src/reference.dart | 44 +++++++-------- lib/src/repository.dart | 95 +++++++++++++++++---------------- lib/src/revwalk.dart | 6 +-- lib/src/submodule.dart | 10 ++-- lib/src/tag.dart | 10 ++-- lib/src/tree.dart | 16 +++--- test/blame_test.dart | 26 ++++----- test/blob_test.dart | 6 +-- test/checkout_test.dart | 2 +- test/commit_test.dart | 16 +++--- test/diff_test.dart | 6 +-- test/index_test.dart | 6 +-- test/merge_test.dart | 18 +++---- test/note_test.dart | 24 ++++----- test/odb_test.dart | 2 +- test/packbuilder_test.dart | 4 +- test/rebase_test.dart | 4 +- test/reference_test.dart | 21 +++----- test/remote_test.dart | 2 +- test/repository_test.dart | 40 ++++---------- test/reset_test.dart | 6 +-- test/revparse_test.dart | 26 ++++----- test/revwalk_test.dart | 8 +-- test/submodule_test.dart | 6 +-- test/tag_test.dart | 12 ++--- test/tree_test.dart | 10 ++-- test/treebuilder_test.dart | 4 +- 39 files changed, 264 insertions(+), 290 deletions(-) diff --git a/lib/src/bindings/note.dart b/lib/src/bindings/note.dart index b2146f6..cb75213 100644 --- a/lib/src/bindings/note.dart +++ b/lib/src/bindings/note.dart @@ -23,22 +23,22 @@ List> list(Pointer repo) { var nextError = 0; while (nextError >= 0) { - final noteId = calloc(); - var annotatedId = calloc(); - nextError = libgit2.git_note_next(noteId, annotatedId, iterator.value); + final noteOid = calloc(); + var annotatedOid = calloc(); + nextError = libgit2.git_note_next(noteOid, annotatedOid, iterator.value); if (nextError >= 0) { final out = calloc>(); - final error = libgit2.git_note_read(out, repo, notesRef, annotatedId); + final error = libgit2.git_note_read(out, repo, notesRef, annotatedOid); - calloc.free(noteId); + calloc.free(noteOid); if (error < 0) { calloc.free(out); - calloc.free(annotatedId); + calloc.free(annotatedOid); calloc.free(iterator); throw LibGit2Error(libgit2.git_error_last()); } else { - result.add({'note': out.value, 'annotatedId': annotatedId}); + result.add({'note': out.value, 'annotatedOid': annotatedOid}); } } else { break; diff --git a/lib/src/bindings/reference.dart b/lib/src/bindings/reference.dart index 41ac3cf..f35b5d5 100644 --- a/lib/src/bindings/reference.dart +++ b/lib/src/bindings/reference.dart @@ -19,7 +19,7 @@ Pointer target(Pointer ref) { final result = libgit2.git_reference_target(ref); if (result == nullptr) { - throw Exception('OID for reference isn\'t available'); + throw Exception('Oid for reference isn\'t available'); } else { return result; } diff --git a/lib/src/blame.dart b/lib/src/blame.dart index 4dbb495..1681277 100644 --- a/lib/src/blame.dart +++ b/lib/src/blame.dart @@ -106,30 +106,30 @@ class BlameHunk { /// version of the file. int get finalStartLineNumber => _blameHunkPointer.ref.final_start_line_number; - /// Returns the author of [finalCommitId]. If [GitBlameFlag.useMailmap] has been + /// Returns the author of [finalCommitOid]. If [GitBlameFlag.useMailmap] has been /// specified, it will contain the canonical real name and email address. Signature get finalCommitter => Signature(_blameHunkPointer.ref.final_signature); /// Returns the [Oid] of the commit where this line was last changed. - Oid get finalCommitId => Oid.fromRaw(_blameHunkPointer.ref.final_commit_id); + Oid get finalCommitOid => Oid.fromRaw(_blameHunkPointer.ref.final_commit_id); /// Returns the 1-based line number where this hunk begins, in the file /// named by [originPath] in the commit specified by [originCommitId]. int get originStartLineNumber => _blameHunkPointer.ref.orig_start_line_number; - /// Returns the author of [originCommitId]. If [GitBlameFlag.useMailmap] has been + /// Returns the author of [originCommitOid]. If [GitBlameFlag.useMailmap] has been /// specified, it will contain the canonical real name and email address. Signature get originCommitter => Signature(_blameHunkPointer.ref.orig_signature); /// Returns the [Oid] of the commit where this hunk was found. This will usually be - /// the same as [finalCommitId], except when [GitBlameFlag.trackCopiesAnyCommitCopies] + /// the same as [finalCommitOid], except when [GitBlameFlag.trackCopiesAnyCommitCopies] /// been specified. - Oid get originCommitId => Oid.fromRaw(_blameHunkPointer.ref.orig_commit_id); + Oid get originCommitOid => Oid.fromRaw(_blameHunkPointer.ref.orig_commit_id); /// Returns the path to the file where this hunk originated, as of the commit - /// specified by [originCommitId]. + /// specified by [originCommitOid]. String get originPath => _blameHunkPointer.ref.orig_path.cast().toDartString(); } diff --git a/lib/src/blob.dart b/lib/src/blob.dart index af352a7..d1a46a9 100644 --- a/lib/src/blob.dart +++ b/lib/src/blob.dart @@ -11,13 +11,13 @@ class Blob { /// Should be freed to release allocated memory. Blob(this._blobPointer); - /// Lookups a blob object for provided [id] in a [repo]sitory. + /// Lookups a blob object for provided [oid] in a [repo]sitory. /// /// Should be freed to release allocated memory. - Blob.lookup({required Repository repo, required Oid id}) { + Blob.lookup({required Repository repo, required Oid oid}) { _blobPointer = bindings.lookup( repoPointer: repo.pointer, - oidPointer: id.pointer, + oidPointer: oid.pointer, ); } @@ -58,8 +58,8 @@ class Blob { return Oid(bindings.createFromDisk(repoPointer: repo.pointer, path: path)); } - /// Returns the Oid of the blob. - Oid get id => Oid(bindings.id(_blobPointer)); + /// Returns the [Oid] of the blob. + Oid get oid => Oid(bindings.id(_blobPointer)); /// Determines if the blob content is most certainly binary or not. /// diff --git a/lib/src/branch.dart b/lib/src/branch.dart index 65ebab4..3b70dcc 100644 --- a/lib/src/branch.dart +++ b/lib/src/branch.dart @@ -119,7 +119,7 @@ class Branch { branch.free(); } - /// Returns the OID pointed to by a branch. + /// Returns the [Oid] pointed to by a branch. /// /// Throws an exception if error occured. Oid get target => Oid(reference_bindings.target(_branchPointer)); diff --git a/lib/src/commit.dart b/lib/src/commit.dart index 279ba58..0147cf7 100644 --- a/lib/src/commit.dart +++ b/lib/src/commit.dart @@ -11,13 +11,13 @@ class Commit { /// Should be freed to release allocated memory. Commit(this._commitPointer); - /// Lookups commit object for provided [id] in a [repo]sitory. + /// Lookups commit object for provided [oid] in a [repo]sitory. /// /// Should be freed to release allocated memory. - Commit.lookup({required Repository repo, required Oid id}) { + Commit.lookup({required Repository repo, required Oid oid}) { _commitPointer = bindings.lookup( repoPointer: repo.pointer, - oidPointer: id.pointer, + oidPointer: oid.pointer, ); } @@ -67,8 +67,8 @@ class Commit { /// The returned message will be slightly prettified by removing any potential leading newlines. String get message => bindings.message(_commitPointer); - /// Returns the id of a commit. - Oid get id => Oid(bindings.id(_commitPointer)); + /// Returns the [Oid] of a commit. + Oid get oid => Oid(bindings.id(_commitPointer)); /// Returns the commit time (i.e. committer time) of a commit. int get time => bindings.time(_commitPointer); @@ -79,7 +79,7 @@ class Commit { /// Returns the author of a commit. Signature get author => Signature(bindings.author(_commitPointer)); - /// Returns list of parent commits. + /// Returns list of parent commits [Oid]s. /// /// Throws a [LibGit2Error] if error occured. List get parents { @@ -109,5 +109,5 @@ class Commit { void free() => bindings.free(_commitPointer); @override - String toString() => 'Commit{id: $id}'; + String toString() => 'Commit{oid: $oid}'; } diff --git a/lib/src/diff.dart b/lib/src/diff.dart index 2e62434..7a14406 100644 --- a/lib/src/diff.dart +++ b/lib/src/diff.dart @@ -107,9 +107,7 @@ class Diff { ); } - /// Calculate the patch ID for the given patch. - /// - /// Calculate a stable patch ID for the given patch by summing the hash of the file diffs, + /// Calculates a stable patch [Oid] for the given patch by summing the hash of the file diffs, /// ignoring whitespace and line numbers. This can be used to derive whether two diffs are /// the same with a high probability. /// @@ -181,9 +179,9 @@ class DiffFile { final git_diff_file _diffFile; - /// Returns oid of the item. If the entry represents an absent side of a diff + /// Returns [Oid] of the item. If the entry represents an absent side of a diff /// then the oid will be zeroes. - Oid get id => Oid.fromRaw(_diffFile.id); + Oid get oid => Oid.fromRaw(_diffFile.id); /// Returns path to the entry relative to the working directory of the repository. String get path => _diffFile.path.cast().toDartString(); diff --git a/lib/src/index.dart b/lib/src/index.dart index 6da34fc..0849af3 100644 --- a/lib/src/index.dart +++ b/lib/src/index.dart @@ -153,7 +153,7 @@ class Index with IterableMixin { /// /// This method will scan the index and write a representation of its current state back to disk; /// it recursively creates tree objects for each of the subtrees stored in the index, but only - /// returns the OID of the root tree. This is the OID that can be used e.g. to create a commit. + /// returns the [Oid] of the root tree. This is the OID that can be used e.g. to create a commit. /// /// The index must not contain any file in conflict. /// @@ -233,18 +233,20 @@ class IndexEntry { /// Pointer to memory address for allocated index entry object. Pointer get pointer => _indexEntryPointer; - /// Unique identity of the index entry. - Oid get id => Oid.fromRaw(_indexEntryPointer.ref.id); + /// Returns inique identity of the index entry. + Oid get oid => Oid.fromRaw(_indexEntryPointer.ref.id); - set id(Oid oid) => _indexEntryPointer.ref.id = oid.pointer.ref; + /// Sets inique identity of the index entry. + set oid(Oid oid) => _indexEntryPointer.ref.id = oid.pointer.ref; - /// Path of the index entry. + /// Returns path of the index entry. String get path => _indexEntryPointer.ref.path.cast().toDartString(); + /// Sets path of the index entry. set path(String path) => _indexEntryPointer.ref.path = path.toNativeUtf8().cast(); - /// Returns id of the index entry as sha-1 hex. + /// Returns id of the index entry as sha hex. String get sha => _oidToHex(_indexEntryPointer.ref.id); /// Returns the UNIX file attributes of a index entry. diff --git a/lib/src/note.dart b/lib/src/note.dart index b424d76..d29d4ff 100644 --- a/lib/src/note.dart +++ b/lib/src/note.dart @@ -5,10 +5,10 @@ import 'bindings/note.dart' as bindings; class Note { /// Initializes a new instance of the [Note] class from provided - /// pointer to note and annotatedId objects in memory. - Note(this._notePointer, this._annotatedIdPointer); + /// pointer to note and annotatedOid objects in memory. + Note(this._notePointer, this._annotatedOidPointer); - /// Reads the note for an [annotatedId]. + /// Reads the note for an [annotatedOid]. /// /// IMPORTANT: Notes must be freed manually when no longer needed to prevent /// memory leak. @@ -16,31 +16,31 @@ class Note { /// Throws a [LibGit2Error] if error occured. Note.lookup({ required Repository repo, - required Oid annotatedId, + required Oid annotatedOid, String notesRef = 'refs/notes/commits', }) { _notePointer = bindings.lookup( repoPointer: repo.pointer, - oidPointer: annotatedId.pointer, + oidPointer: annotatedOid.pointer, notesRef: notesRef, ); - _annotatedIdPointer = annotatedId.pointer; + _annotatedOidPointer = annotatedOid.pointer; } /// Pointer to memory address for allocated note object. late final Pointer _notePointer; - /// Pointer to memory address for allocated annotetedId object. - late final Pointer _annotatedIdPointer; + /// Pointer to memory address for allocated annotetedOid object. + late final Pointer _annotatedOidPointer; - /// Adds a note for an [annotatedId]. + /// Adds a note for an [annotatedOid]. /// /// Throws a [LibGit2Error] if error occured. static Oid create({ required Repository repo, required Signature author, required Signature committer, - required Oid annotatedId, + required Oid annotatedOid, required String note, String notesRef = 'refs/notes/commits', bool force = false, @@ -49,19 +49,19 @@ class Note { repoPointer: repo.pointer, authorPointer: author.pointer, committerPointer: committer.pointer, - oidPointer: annotatedId.pointer, + oidPointer: annotatedOid.pointer, note: note, notesRef: notesRef, force: force, )); } - /// Deletes the note for an [annotatedId]. + /// Deletes the note for an [annotatedOid]. /// /// Throws a [LibGit2Error] if error occured. static void delete({ required Repository repo, - required Oid annotatedId, + required Oid annotatedOid, required Signature author, required Signature committer, String notesRef = 'refs/notes/commits', @@ -70,7 +70,7 @@ class Note { repoPointer: repo.pointer, authorPointer: author.pointer, committerPointer: committer.pointer, - oidPointer: annotatedId.pointer, + oidPointer: annotatedOid.pointer, ); } @@ -85,19 +85,19 @@ class Note { return notesPointers .map((e) => Note( e['note'] as Pointer, - e['annotatedId'] as Pointer, + e['annotatedOid'] as Pointer, )) .toList(); } /// Returns the note object's [Oid]. - Oid get id => Oid(bindings.id(_notePointer)); + Oid get oid => Oid(bindings.id(_notePointer)); /// Returns the note message. String get message => bindings.message(_notePointer); /// Returns the [Oid] of the git object being annotated. - Oid get annotatedId => Oid(_annotatedIdPointer); + Oid get annotatedOid => Oid(_annotatedOidPointer); /// Releases memory allocated for note object. void free() => bindings.free(_notePointer); diff --git a/lib/src/odb.dart b/lib/src/odb.dart index 938c92c..2660259 100644 --- a/lib/src/odb.dart +++ b/lib/src/odb.dart @@ -45,7 +45,7 @@ class Odb { ); } - /// Returns list of all objects available in the database. + /// Returns list of all objects [Oid]s available in the database. /// /// Throws a [LibGit2Error] if error occured. List get objects => bindings.objects(_odbPointer); @@ -102,10 +102,10 @@ class OdbObject { /// Pointer to memory address for allocated odbObject object. final Pointer _odbObjectPointer; - /// Returns the OID of an ODB object. + /// Returns the [Oid] of an ODB object. /// - /// This is the OID from which the object was read from. - Oid get id => Oid(bindings.objectId(_odbObjectPointer)); + /// This is the [Oid] from which the object was read from. + Oid get oid => Oid(bindings.objectId(_odbObjectPointer)); /// Returns the type of an ODB object. GitObject get type { diff --git a/lib/src/oid.dart b/lib/src/oid.dart index b814818..636855c 100644 --- a/lib/src/oid.dart +++ b/lib/src/oid.dart @@ -45,7 +45,7 @@ class Oid { /// Pointer to memory address for allocated oid object. Pointer get pointer => _oidPointer; - /// Returns hexadecimal SHA-1 string. + /// Returns hexadecimal SHA string. String get sha => bindings.toSHA(_oidPointer); @override diff --git a/lib/src/rebase.dart b/lib/src/rebase.dart index 7c2c795..c10b300 100644 --- a/lib/src/rebase.dart +++ b/lib/src/rebase.dart @@ -126,9 +126,9 @@ class RebaseOperation { ); } - /// The commit ID being cherry-picked. This will be populated for + /// Returns the commit [Oid] being cherry-picked. This will be populated for /// all operations except those of type [GitRebaseOperation.exec]. - Oid get id => Oid.fromRaw(_rebaseOperationPointer.ref.id); + Oid get oid => Oid.fromRaw(_rebaseOperationPointer.ref.id); /// The executable the user has requested be run. This will only /// be populated for operations of type [GitRebaseOperation.exec]. diff --git a/lib/src/reference.dart b/lib/src/reference.dart index b961084..c07e6ed 100644 --- a/lib/src/reference.dart +++ b/lib/src/reference.dart @@ -149,9 +149,9 @@ class Reference { : ReferenceType.symbolic; } - /// Returns the OID pointed to by a reference. + /// Returns the [Oid] pointed to by a reference. /// - /// Throws an exception if error occured. + /// Throws an [Exception] if error occured. Oid get target { late final Pointer oidPointer; @@ -163,37 +163,33 @@ class Reference { return Oid(oidPointer); } - /// Conditionally creates a new reference with the same name as the given reference - /// but a different OID target. + /// Updates the [target] of this reference. /// - /// The new reference will be written to disk, overwriting the given reference. + /// [target] being either Oid for direct reference or String reference name for symbolic + /// reference. /// - /// Throws a [LibGit2Error] if error occured. - void setTarget({required String target, String? logMessage}) { - late final Oid oid; - final owner = bindings.owner(_refPointer); - - if (isValidShaHex(target)) { - final repo = Repository(owner); - oid = Oid.fromSHA(repo: repo, sha: target); - } else { - final ref = Reference(bindings.lookup(repoPointer: owner, name: target)); - oid = ref.target; - ref.free(); - } - - if (type == ReferenceType.direct) { - _refPointer = bindings.setTarget( + /// Throws a [LibGit2Error] if error occured or [ArgumentError] if [target] is not + /// [Oid] or String. + void setTarget({required Object target, String? logMessage}) { + if (target is Oid) { + final newPointer = bindings.setTarget( refPointer: _refPointer, - oidPointer: oid.pointer, + oidPointer: target.pointer, logMessage: logMessage, ); - } else { - _refPointer = bindings.setTargetSymbolic( + free(); + _refPointer = newPointer; + } else if (target is String) { + final newPointer = bindings.setTargetSymbolic( refPointer: _refPointer, target: target, logMessage: logMessage, ); + free(); + _refPointer = newPointer; + } else { + throw ArgumentError.value( + '$target must be either Oid or String reference name'); } } diff --git a/lib/src/repository.dart b/lib/src/repository.dart index e23e4a5..e9ff5f2 100644 --- a/lib/src/repository.dart +++ b/lib/src/repository.dart @@ -204,15 +204,19 @@ class Repository { /// /// Otherwise, the HEAD will be detached and will directly point to the Commit. /// - /// Throws a [LibGit2Error] if error occured. - void setHead(String target) { - if (isValidShaHex(target)) { + /// Throws a [LibGit2Error] if error occured or [ArgumentError] if provided [target] + /// is not Oid or String. + void setHead(Object target) { + if (target is Oid) { bindings.setHeadDetached( repoPointer: _repoPointer, - commitishPointer: this[target].pointer, + commitishPointer: target.pointer, ); - } else { + } else if (target is String) { bindings.setHead(repoPointer: _repoPointer, refname: target); + } else { + throw ArgumentError.value( + '$target must be either Oid or String reference name'); } } @@ -267,8 +271,9 @@ class Repository { /// (merge, cherry-pick, etc) is in progress. GitRepositoryState get state { final stateInt = bindings.state(_repoPointer); - return GitRepositoryState.values - .singleWhere((state) => stateInt == state.value); + return GitRepositoryState.values.singleWhere( + (state) => stateInt == state.value, + ); } /// Removes all the metadata associated with an ongoing command like @@ -424,11 +429,11 @@ class Repository { /// Throws a [LibGit2Error] if error occured. Odb get odb => Odb(bindings.odb(_repoPointer)); - /// Lookups a tree object for provided [id]. + /// Lookups a tree object for provided [oid]. /// /// Should be freed to release allocated memory. - Tree lookupTree(Oid id) { - return Tree.lookup(repo: this, id: id); + Tree lookupTree(Oid oid) { + return Tree.lookup(repo: this, oid: oid); } /// Creates a new action signature with default user and now timestamp. @@ -439,17 +444,17 @@ class Repository { /// Throws a [LibGit2Error] if error occured. Signature get defaultSignature => Signature.defaultSignature(this); - /// Returns the list of commits starting from provided [sha] hex string. + /// Returns the list of commits starting from provided commit [oid]. /// /// If [sorting] isn't provided default will be used (reverse chronological order, like in git). List log({ - required String sha, + required Oid oid, Set sorting = const {GitSort.none}, }) { final walker = RevWalk(this); walker.sorting(sorting); - walker.push(this[sha]); + walker.push(oid); final result = walker.walk(); walker.free(); @@ -468,11 +473,11 @@ class Repository { return RevParse.single(repo: this, spec: spec); } - /// Lookups commit object for provided [id]. + /// Lookups commit object for provided [oid]. /// /// Should be freed to release allocated memory. - Commit lookupCommit(Oid id) { - return Commit.lookup(repo: this, id: id); + Commit lookupCommit(Oid oid) { + return Commit.lookup(repo: this, oid: oid); } /// Creates new commit in the repository. @@ -529,11 +534,11 @@ class Repository { return RevParse.range(repo: this, spec: spec); } - /// Lookups a blob object for provided [id]. + /// Lookups a blob object for provided [oid]. /// /// Should be freed to release allocated memory. - Blob lookupBlob(Oid id) { - return Blob.lookup(repo: this, id: id); + Blob lookupBlob(Oid oid) { + return Blob.lookup(repo: this, oid: oid); } /// Creates a new blob from a [content] string and writes it to ODB. @@ -564,10 +569,10 @@ class Repository { /// Throws a [LibGit2Error] if error occured. List get tags => Tag.list(this); - /// Lookups tag object for provided [id]. + /// Lookups tag object for provided [oid]. /// /// Should be freed to release allocated memory. - Tag lookupTag(Oid id) => Tag.lookup(repo: this, id: id); + Tag lookupTag(Oid oid) => Tag.lookup(repo: this, oid: oid); /// Creates a new tag in the repository for provided [target] object. /// @@ -753,11 +758,11 @@ class Repository { /// Finds a merge base between two commits. /// /// Throws a [LibGit2Error] if error occured. - Oid mergeBase({required String a, required String b}) { + Oid mergeBase({required Oid a, required Oid b}) { return Oid(merge_bindings.mergeBase( repoPointer: _repoPointer, - aPointer: this[a].pointer, - bPointer: this[b].pointer, + aPointer: a.pointer, + bPointer: b.pointer, )); } @@ -797,7 +802,7 @@ class Repository { return [analysisSet, mergePreference]; } - /// Merges the given commit(s) oid into HEAD, writing the results into the working directory. + /// Merges the given commit [oid] into HEAD, writing the results into the working directory. /// Any changes are staged for commit and any conflicts are written to the index. Callers /// should inspect the repository's index after this completes, resolve any conflicts and /// prepare a commit. @@ -909,7 +914,7 @@ class Repository { )); } - /// Cherry-picks the provided commit, producing changes in the index and working directory. + /// Cherry-picks the provided [commit], producing changes in the index and working directory. /// /// Any changes are staged for commit and any conflicts are written to the index. Callers /// should inspect the repository's index after this completes, resolve any conflicts and @@ -982,14 +987,14 @@ class Repository { } } - /// Sets the current head to the specified commit and optionally resets the index + /// Sets the current head to the specified commit [oid] and optionally resets the index /// and working tree to match. /// /// Throws a [LibGit2Error] if error occured. - void reset({required String target, required GitReset resetType}) { + void reset({required Oid oid, required GitReset resetType}) { final object = object_bindings.lookup( repoPointer: _repoPointer, - oidPointer: this[target].pointer, + oidPointer: oid.pointer, type: GitObject.any.value, ); @@ -1296,30 +1301,30 @@ class Repository { /// Throws a [LibGit2Error] if error occured. List get notes => Note.list(this); - /// Reads the note for an [annotatedId]. + /// Reads the note for an [annotatedOid]. /// /// IMPORTANT: Notes must be freed manually when no longer needed to prevent /// memory leak. /// /// Throws a [LibGit2Error] if error occured. Note lookupNote({ - required Oid annotatedId, + required Oid annotatedOid, String notesRef = 'refs/notes/commits', }) { return Note.lookup( repo: this, - annotatedId: annotatedId, + annotatedOid: annotatedOid, notesRef: notesRef, ); } - /// Adds a note for an [annotatedId]. + /// Adds a note for an [annotatedOid]. /// /// Throws a [LibGit2Error] if error occured. Oid createNote({ required Signature author, required Signature committer, - required Oid annotatedId, + required Oid annotatedOid, required String note, String notesRef = 'refs/notes/commits', bool force = false, @@ -1328,25 +1333,25 @@ class Repository { repo: this, author: author, committer: committer, - annotatedId: annotatedId, + annotatedOid: annotatedOid, note: note, notesRef: notesRef, force: force, ); } - /// Deletes the note for an [annotatedId]. + /// Deletes the note for an [annotatedOid]. /// /// Throws a [LibGit2Error] if error occured. void deleteNote({ - required Oid annotatedId, + required Oid annotatedOid, required Signature author, required Signature committer, String notesRef = 'refs/notes/commits', }) { Note.delete( repo: this, - annotatedId: annotatedId, + annotatedOid: annotatedOid, author: author, committer: committer, notesRef: notesRef, @@ -1359,11 +1364,11 @@ class Repository { /// `git merge-base --is-ancestor`. /// /// Throws a [LibGit2Error] if error occured. - bool descendantOf({required String commitSHA, required String ancestorSHA}) { + bool descendantOf({required Oid commit, required Oid ancestor}) { return graph_bindings.descendantOf( repoPointer: _repoPointer, - commitPointer: this[commitSHA].pointer, - ancestorPointer: this[ancestorSHA].pointer, + commitPointer: commit.pointer, + ancestorPointer: ancestor.pointer, ); } @@ -1373,13 +1378,13 @@ class Repository { /// but it helps to think of one as a branch and the other as its upstream, the ahead and /// behind values will be what git would report for the branches. List aheadBehind({ - required String localSHA, - required String upstreamSHA, + required Oid local, + required Oid upstream, }) { return graph_bindings.aheadBehind( repoPointer: _repoPointer, - localPointer: this[localSHA].pointer, - upstreamPointer: this[upstreamSHA].pointer, + localPointer: local.pointer, + upstreamPointer: upstream.pointer, ); } diff --git a/lib/src/revwalk.dart b/lib/src/revwalk.dart index d6a7a9b..c4714bc 100644 --- a/lib/src/revwalk.dart +++ b/lib/src/revwalk.dart @@ -37,14 +37,14 @@ class RevWalk { ); } - /// Adds a new root for the traversal. + /// Adds a new root commit [oid] for the traversal. /// /// The pushed commit will be marked as one of the roots from which to start the walk. /// This commit may not be walked if it or a child is hidden. /// /// At least one commit must be pushed onto the walker before a walk can be started. /// - /// The given id must belong to a committish on the walked repository. + /// The given [oid] must belong to a committish on the walked repository. /// /// Throws a [LibGit2Error] if error occured. void push(Oid oid) { @@ -54,7 +54,7 @@ class RevWalk { ); } - /// Marks a commit (and its ancestors) uninteresting for the output. + /// Marks a commit [oid] (and its ancestors) uninteresting for the output. /// /// The given id must belong to a committish on the walked repository. /// diff --git a/lib/src/submodule.dart b/lib/src/submodule.dart index 33ee694..a853ca2 100644 --- a/lib/src/submodule.dart +++ b/lib/src/submodule.dart @@ -216,26 +216,26 @@ class Submodule { /// Returns the [Oid] for the submodule in the current HEAD tree or /// null if submodule is not in the HEAD. - Oid? get headId { + Oid? get headOid { final result = bindings.headId(_submodulePointer); return result == null ? null : Oid(result); } /// Returns the [Oid] for the submodule in the index or null if submodule /// is not in the index. - Oid? get indexId { + Oid? get indexOid { final result = bindings.indexId(_submodulePointer); return result == null ? null : Oid(result); } - /// Returns the OID for the submodule in the current working directory or null if + /// Returns the [Oid] for the submodule in the current working directory or null if /// submodule is not checked out. /// - /// This returns the OID that corresponds to looking up `HEAD` in the checked out + /// This returns the [Oid] that corresponds to looking up `HEAD` in the checked out /// submodule. If there are pending changes in the index or anything else, this /// won't notice that. You should call [status] for a more complete picture about /// the state of the working directory. - Oid? get workdirId { + Oid? get workdirOid { final result = bindings.workdirId(_submodulePointer); return result == null ? null : Oid(result); } diff --git a/lib/src/tag.dart b/lib/src/tag.dart index c015283..3e16fe3 100644 --- a/lib/src/tag.dart +++ b/lib/src/tag.dart @@ -11,13 +11,13 @@ class Tag { /// Should be freed to release allocated memory. Tag(this._tagPointer); - /// Lookups tag object for provided [id] in a [repo]sitory. + /// Lookups tag object for provided [oid] in a [repo]sitory. /// /// Should be freed to release allocated memory. - Tag.lookup({required Repository repo, required Oid id}) { + Tag.lookup({required Repository repo, required Oid oid}) { _tagPointer = bindings.lookup( repoPointer: repo.pointer, - oidPointer: id.pointer, + oidPointer: oid.pointer, ); } @@ -112,8 +112,8 @@ class Tag { } } - /// Get the id of a tag. - Oid get id => Oid(bindings.id(_tagPointer)); + /// Returns the [Oid] of a tag. + Oid get oid => Oid(bindings.id(_tagPointer)); /// Returns the name of a tag. String get name => bindings.name(_tagPointer); diff --git a/lib/src/tree.dart b/lib/src/tree.dart index c5bbb16..fd35143 100644 --- a/lib/src/tree.dart +++ b/lib/src/tree.dart @@ -11,13 +11,13 @@ class Tree { /// Should be freed to release allocated memory. Tree(this._treePointer); - /// Lookups a tree object for provided [id] in a [repo]sitory. + /// Lookups a tree object for provided [oid] in a [repo]sitory. /// /// Should be freed to release allocated memory. - Tree.lookup({required Repository repo, required Oid id}) { + Tree.lookup({required Repository repo, required Oid oid}) { _treePointer = bindings.lookup( repoPointer: repo.pointer, - oidPointer: id.pointer, + oidPointer: oid.pointer, ); } @@ -69,8 +69,8 @@ class Tree { } } - /// Returns the Oid of a tree. - Oid get id => Oid(bindings.id(_treePointer)); + /// Returns the [Oid] of a tree. + Oid get oid => Oid(bindings.id(_treePointer)); /// Get the number of entries listed in a tree. int get length => bindings.entryCount(_treePointer); @@ -141,8 +141,8 @@ class TreeEntry { /// Pointer to memory address for allocated tree entry object. final Pointer _treeEntryPointer; - /// Returns the Oid of the object pointed by the entry. - Oid get id => Oid(bindings.entryId(_treeEntryPointer)); + /// Returns the [Oid] of the object pointed by the entry. + Oid get oid => Oid(bindings.entryId(_treeEntryPointer)); /// Returns the filename of a tree entry. String get name => bindings.entryName(_treeEntryPointer); @@ -201,5 +201,5 @@ class TreeEntry { void free() => bindings.entryFree(_treeEntryPointer); @override - String toString() => 'TreeEntry{id: $id, name: $name}'; + String toString() => 'TreeEntry{oid: $oid, name: $name}'; } diff --git a/test/blame_test.dart b/test/blame_test.dart index 8363b53..782f72d 100644 --- a/test/blame_test.dart +++ b/test/blame_test.dart @@ -28,19 +28,19 @@ void main() { hunks = [ { - 'finalCommitId': 'fc38877b2552ab554752d9a77e1f48f738cca79b', + 'finalCommitOid': 'fc38877b2552ab554752d9a77e1f48f738cca79b', 'finalStartLineNumber': 1, 'finalCommitter': sig1, - 'originCommitId': 'fc38877b2552ab554752d9a77e1f48f738cca79b', + 'originCommitOid': 'fc38877b2552ab554752d9a77e1f48f738cca79b', 'originStartLineNumber': 1, 'originCommitter': sig1, 'isBoundary': false, }, { - 'finalCommitId': 'a07a01e325c2c04e05d2450ad37785fbfe0a0014', + 'finalCommitOid': 'a07a01e325c2c04e05d2450ad37785fbfe0a0014', 'finalStartLineNumber': 2, 'finalCommitter': sig2, - 'originCommitId': 'a07a01e325c2c04e05d2450ad37785fbfe0a0014', + 'originCommitOid': 'a07a01e325c2c04e05d2450ad37785fbfe0a0014', 'originStartLineNumber': 2, 'originCommitter': sig2, 'isBoundary': false, @@ -63,10 +63,10 @@ void main() { for (var i = 0; i < blame.length; i++) { expect(blame[i].linesCount, 1); - expect(blame[i].finalCommitId.sha, hunks[i]['finalCommitId']); + expect(blame[i].finalCommitOid.sha, hunks[i]['finalCommitOid']); expect(blame[i].finalStartLineNumber, hunks[i]['finalStartLineNumber']); expect(blame[i].finalCommitter, hunks[i]['finalCommitter']); - expect(blame[i].originCommitId.sha, hunks[i]['originCommitId']); + expect(blame[i].originCommitOid.sha, hunks[i]['originCommitOid']); expect( blame[i].originStartLineNumber, hunks[i]['originStartLineNumber'], @@ -85,10 +85,10 @@ void main() { final hunk = blame.forLine(1); expect(hunk.linesCount, 1); - expect(hunk.finalCommitId.sha, hunks[0]['finalCommitId']); + expect(hunk.finalCommitOid.sha, hunks[0]['finalCommitOid']); expect(hunk.finalStartLineNumber, hunks[0]['finalStartLineNumber']); expect(hunk.finalCommitter, hunks[0]['finalCommitter']); - expect(hunk.originCommitId.sha, hunks[0]['originCommitId']); + expect(hunk.originCommitOid.sha, hunks[0]['originCommitOid']); expect( hunk.originStartLineNumber, hunks[0]['originStartLineNumber'], @@ -117,13 +117,9 @@ void main() { test( 'successfully gets the blame for provided file with newestCommit argument', () { - final newestCommit = Oid.fromSHA( - repo: repo, - sha: 'fc38877b2552ab554752d9a77e1f48f738cca79b', - ); final blame = repo.blame( path: 'feature_file', - newestCommit: newestCommit, + newestCommit: repo['fc38877b2552ab554752d9a77e1f48f738cca79b'], flags: {GitBlameFlag.ignoreWhitespace}, ); @@ -132,10 +128,10 @@ void main() { final hunk = blame.first; expect(hunk.linesCount, 1); - expect(hunk.finalCommitId.sha, hunks[0]['finalCommitId']); + expect(hunk.finalCommitOid.sha, hunks[0]['finalCommitOid']); expect(hunk.finalStartLineNumber, hunks[0]['finalStartLineNumber']); expect(hunk.finalCommitter, hunks[0]['finalCommitter']); - expect(hunk.originCommitId.sha, hunks[0]['originCommitId']); + expect(hunk.originCommitOid.sha, hunks[0]['originCommitOid']); expect( hunk.originStartLineNumber, hunks[0]['originStartLineNumber'], diff --git a/test/blob_test.dart b/test/blob_test.dart index fb5ae55..d7080e4 100644 --- a/test/blob_test.dart +++ b/test/blob_test.dart @@ -29,7 +29,7 @@ void main() { }); test('returns correct values', () { - expect(blob.id.sha, blobSHA); + expect(blob.oid.sha, blobSHA); expect(blob.isBinary, false); expect(blob.size, 13); expect(blob.content, blobContent); @@ -39,7 +39,7 @@ void main() { final oid = repo.createBlob(newBlobContent); final newBlob = repo.lookupBlob(oid); - expect(newBlob.id.sha, '18fdaeef018e57a92bcad2d4a35b577f34089af6'); + expect(newBlob.oid.sha, '18fdaeef018e57a92bcad2d4a35b577f34089af6'); expect(newBlob.isBinary, false); expect(newBlob.size, 9); expect(newBlob.content, newBlobContent); @@ -52,7 +52,7 @@ void main() { final oid = repo.createBlobFromWorkdir('feature_file'); final newBlob = repo.lookupBlob(oid); - expect(newBlob.id.sha, blobSHA); + expect(newBlob.oid.sha, blobSHA); expect(newBlob.isBinary, false); expect(newBlob.size, 13); expect(newBlob.content, blobContent); diff --git a/test/checkout_test.dart b/test/checkout_test.dart index 75a3670..730ce2b 100644 --- a/test/checkout_test.dart +++ b/test/checkout_test.dart @@ -54,7 +54,7 @@ void main() { ); final featureTree = featureHead.tree; final repoHead = repo.head; - expect(repoHead.target.sha, featureHead.id.sha); + expect(repoHead.target, featureHead.oid); expect(repo.status, isEmpty); expect( featureTree.entries.any((e) => e.name == 'another_feature_file'), diff --git a/test/commit_test.dart b/test/commit_test.dart index 3415d4e..da1fabf 100644 --- a/test/commit_test.dart +++ b/test/commit_test.dart @@ -28,7 +28,7 @@ void main() { mergeCommit = repo['78b8bf123e3952c970ae5c1ce0a3ea1d1336f6e8']; tree = Tree.lookup( repo: repo, - id: repo['7796359a96eb722939c24bafdb1afe9f07f2f628'], + oid: repo['7796359a96eb722939c24bafdb1afe9f07f2f628'], ); }); @@ -78,13 +78,13 @@ void main() { final commit = repo.lookupCommit(oid); - expect(commit.id.sha, oid.sha); + expect(commit.oid, oid); expect(commit.message, message); expect(commit.messageEncoding, 'utf-8'); expect(commit.author, author); expect(commit.committer, commiter); expect(commit.time, 124); - expect(commit.tree.id, tree.id); + expect(commit.tree.oid, tree.oid); expect(commit.parents.length, 1); expect(commit.parents[0], mergeCommit); @@ -103,13 +103,13 @@ void main() { final commit = repo.lookupCommit(oid); - expect(commit.id.sha, oid.sha); + expect(commit.oid, oid); expect(commit.message, message); expect(commit.messageEncoding, 'utf-8'); expect(commit.author, author); expect(commit.committer, commiter); expect(commit.time, 124); - expect(commit.tree.id, tree.id); + expect(commit.tree.oid, tree.oid); expect(commit.parents.length, 0); commit.free(); @@ -132,16 +132,16 @@ void main() { final commit = repo.lookupCommit(oid); - expect(commit.id.sha, oid.sha); + expect(commit.oid, oid); expect(commit.message, message); expect(commit.messageEncoding, 'utf-8'); expect(commit.author, author); expect(commit.committer, commiter); expect(commit.time, 124); - expect(commit.tree.id, tree.id); + expect(commit.tree.oid, tree.oid); expect(commit.parents.length, 2); expect(commit.parents[0], mergeCommit); - expect(commit.parents[1], parent2.id); + expect(commit.parents[1], parent2.oid); parent1.free(); parent2.free(); diff --git a/test/diff_test.dart b/test/diff_test.dart index 399cfda..c59c2e7 100644 --- a/test/diff_test.dart +++ b/test/diff_test.dart @@ -218,7 +218,7 @@ index e69de29..c217c63 100644 final file = File('${tmpDir.path}/subdir/modified_file'); repo.reset( - target: 'a763aa560953e7cfb87ccbc2f536d665aa4dff22', + oid: repo['a763aa560953e7cfb87ccbc2f536d665aa4dff22'], resetType: GitReset.hard, ); expect(file.readAsStringSync(), ''); @@ -280,11 +280,11 @@ index e69de29..c217c63 100644 expect(diff.deltas[0].oldFile.path, indexToWorkdir[0]); expect( - diff.deltas[0].oldFile.id.sha, + diff.deltas[0].oldFile.oid.sha, 'e69de29bb2d1d6434b8b29ae775ad8c2e48c5391', ); expect( - diff.deltas[0].newFile.id.sha, + diff.deltas[0].newFile.oid.sha, '0000000000000000000000000000000000000000', ); diff --git a/test/index_test.dart b/test/index_test.dart index c6d48da..45d9f62 100644 --- a/test/index_test.dart +++ b/test/index_test.dart @@ -54,15 +54,15 @@ void main() { final entry = index['file']; final otherEntry = index['feature_file']; - expect(entry.id == otherEntry.id, false); + expect(entry.oid == otherEntry.oid, false); expect(entry.mode, isNot(GitFilemode.blobExecutable)); entry.path = 'some.txt'; - entry.id = otherEntry.id; + entry.oid = otherEntry.oid; entry.mode = GitFilemode.blobExecutable; expect(entry.path, 'some.txt'); - expect(entry.id == otherEntry.id, true); + expect(entry.oid == otherEntry.oid, true); expect(entry.mode, GitFilemode.blobExecutable); }); diff --git a/test/merge_test.dart b/test/merge_test.dart index 257c003..215b62e 100644 --- a/test/merge_test.dart +++ b/test/merge_test.dart @@ -26,7 +26,7 @@ void main() { repo['c68ff54aabf660fcdd9a2838d401583fe31249e3'], ); - final result = repo.mergeAnalysis(theirHead: commit.id); + final result = repo.mergeAnalysis(theirHead: commit.oid); expect(result, [ {GitMergeAnalysis.upToDate}, GitMergePreference.none, @@ -42,7 +42,7 @@ void main() { ); final result = repo.mergeAnalysis( - theirHead: commit.id, + theirHead: commit.oid, ourRef: 'refs/tags/v0.1', ); expect(result[0], {GitMergeAnalysis.upToDate}); @@ -64,7 +64,7 @@ void main() { ); final result = repo.mergeAnalysis( - theirHead: theirHead.id, + theirHead: theirHead.oid, ourRef: 'refs/heads/${ffBranch.name}', ); expect( @@ -83,7 +83,7 @@ void main() { repo['5aecfa0fb97eadaac050ccb99f03c3fb65460ad4'], ); - final result = repo.mergeAnalysis(theirHead: commit.id); + final result = repo.mergeAnalysis(theirHead: commit.oid); expect(result[0], {GitMergeAnalysis.normal}); expect(repo.status, isEmpty); @@ -192,7 +192,7 @@ conflict branch edit expect(mergeIndex.conflicts, isEmpty); final mergeCommitsTree = mergeIndex.writeTree(repo); - repo.merge(theirCommit.id); + repo.merge(theirCommit.oid); final index = repo.index; expect(index.conflicts, isEmpty); final mergeTree = index.writeTree(); @@ -263,7 +263,7 @@ conflict branch edit repo['14905459d775f3f56a39ebc2ff081163f7da3529'], ); final baseCommit = repo.lookupCommit( - repo.mergeBase(a: ourCommit.id.sha, b: theirCommit.id.sha), + repo.mergeBase(a: ourCommit.oid, b: theirCommit.oid), ); final theirTree = theirCommit.tree; final ourTree = ourCommit.tree; @@ -277,8 +277,8 @@ conflict branch edit expect(mergeIndex.conflicts, isEmpty); final mergeTreesTree = mergeIndex.writeTree(repo); - repo.setHead('14905459d775f3f56a39ebc2ff081163f7da3529'); - repo.merge(theirCommit.id); + repo.setHead(ourCommit.oid); + repo.merge(theirCommit.oid); final index = repo.index; expect(index.conflicts, isEmpty); final mergeTree = index.writeTree(); @@ -303,7 +303,7 @@ conflict branch edit repo['14905459d775f3f56a39ebc2ff081163f7da3529'], ); final baseCommit = repo.lookupCommit( - repo.mergeBase(a: ourCommit.id.sha, b: theirCommit.id.sha), + repo.mergeBase(a: ourCommit.oid, b: theirCommit.oid), ); final theirTree = theirCommit.tree; final ourTree = ourCommit.tree; diff --git a/test/note_test.dart b/test/note_test.dart index e0669be..5413ab6 100644 --- a/test/note_test.dart +++ b/test/note_test.dart @@ -8,14 +8,14 @@ void main() { late Directory tmpDir; const notesExpected = [ { - 'id': 'd854ba919e1bb303f4d6bb4ca9a15c5cab2a2a50', + 'oid': 'd854ba919e1bb303f4d6bb4ca9a15c5cab2a2a50', 'message': 'Another note\n', - 'annotatedId': '78b8bf123e3952c970ae5c1ce0a3ea1d1336f6e8', + 'annotatedOid': '78b8bf123e3952c970ae5c1ce0a3ea1d1336f6e8', }, { - 'id': 'd2ffe6b06b11dd90c2ee3f15d2c6b62f018554ed', + 'oid': 'd2ffe6b06b11dd90c2ee3f15d2c6b62f018554ed', 'message': 'Note for HEAD\n', - 'annotatedId': '821ed6e80627b8769d170a293862f9fc60825226', + 'annotatedOid': '821ed6e80627b8769d170a293862f9fc60825226', }, ]; @@ -36,20 +36,20 @@ void main() { expect(notes.length, 2); for (var i = 0; i < notes.length; i++) { - expect(notes[i].id.sha, notesExpected[i]['id']); + expect(notes[i].oid.sha, notesExpected[i]['oid']); expect(notes[i].message, notesExpected[i]['message']); - expect(notes[i].annotatedId.sha, notesExpected[i]['annotatedId']); + expect(notes[i].annotatedOid.sha, notesExpected[i]['annotatedOid']); notes[i].free(); } }); test('successfully lookups note', () { final head = repo.head; - final note = repo.lookupNote(annotatedId: head.target); + final note = repo.lookupNote(annotatedOid: head.target); - expect(note.id.sha, notesExpected[1]['id']); + expect(note.oid.sha, notesExpected[1]['oid']); expect(note.message, notesExpected[1]['message']); - expect(note.annotatedId.sha, notesExpected[1]['annotatedId']); + expect(note.annotatedOid.sha, notesExpected[1]['annotatedOid']); note.free(); head.free(); @@ -61,7 +61,7 @@ void main() { final noteOid = repo.createNote( author: signature, committer: signature, - annotatedId: head.target, + annotatedOid: head.target, note: 'New note for HEAD', force: true, ); @@ -80,13 +80,13 @@ void main() { final head = repo.head; repo.deleteNote( - annotatedId: repo.head.target, + annotatedOid: repo.head.target, author: signature, committer: signature, ); expect( - () => repo.lookupNote(annotatedId: head.target), + () => repo.lookupNote(annotatedOid: head.target), throwsA(isA()), ); diff --git a/test/odb_test.dart b/test/odb_test.dart index 18f9a2b..a6c586c 100644 --- a/test/odb_test.dart +++ b/test/odb_test.dart @@ -48,7 +48,7 @@ void main() { final odb = repo.odb; final object = odb.read(oid); - expect(object.id, oid); + expect(object.oid, oid); expect(object.type, GitObject.blob); expect(object.data, blobContent); expect(object.size, 13); diff --git a/test/packbuilder_test.dart b/test/packbuilder_test.dart index 43a6d30..6dd3c34 100644 --- a/test/packbuilder_test.dart +++ b/test/packbuilder_test.dart @@ -89,8 +89,8 @@ void main() { final branches = repo.branches; for (final branch in branches) { final ref = repo.lookupReference('refs/heads/${branch.name}'); - for (final commit in repo.log(sha: ref.target.sha)) { - packBuilder.addRecursively(commit.id); + for (final commit in repo.log(oid: ref.target)) { + packBuilder.addRecursively(commit.oid); commit.free(); } ref.free(); diff --git a/test/rebase_test.dart b/test/rebase_test.dart index 3b5a358..8034440 100644 --- a/test/rebase_test.dart +++ b/test/rebase_test.dart @@ -43,7 +43,7 @@ void main() { for (var i = 0; i < operationsCount; i++) { final operation = rebase.next(); expect(operation.type, GitRebaseOperation.pick); - expect(operation.id.sha, shas[i]); + expect(operation.oid.sha, shas[i]); expect(operation.exec, ''); rebase.commit(committer: signature); @@ -74,7 +74,7 @@ void main() { repo: repo, branch: master.target, onto: feature.target, - upstream: startCommit.id, + upstream: startCommit.oid, ); final operationsCount = rebase.operationsCount; diff --git a/test/reference_test.dart b/test/reference_test.dart index 1a9933a..862dfd2 100644 --- a/test/reference_test.dart +++ b/test/reference_test.dart @@ -343,23 +343,16 @@ void main() { }); group('set target', () { - test('successfully sets with SHA hex', () { + test('successfully sets direct reference with provided Oid target', () { final ref = repo.lookupReference('refs/heads/master'); - ref.setTarget(target: newCommit); + ref.setTarget(target: repo[newCommit]); expect(ref.target.sha, newCommit); ref.free(); }); - test('successfully sets target with short SHA hex', () { - final ref = repo.lookupReference('refs/heads/master'); - ref.setTarget(target: newCommit.substring(0, 5)); - expect(ref.target.sha, newCommit); - - ref.free(); - }); - - test('successfully sets symbolic target', () { + test('successfully sets symbolic target with provided reference name', + () { final ref = repo.lookupReference('HEAD'); expect(ref.target.sha, lastCommit); @@ -474,7 +467,7 @@ void main() { final commit = repo.lookupCommit(ref.target); final peeled = ref.peel() as Commit; - expect(peeled.id, commit.id); + expect(peeled.oid, commit.oid); peeled.free(); commit.free(); @@ -488,8 +481,8 @@ void main() { final peeledCommit = ref.peel(GitObject.commit) as Commit; final peeledTree = ref.peel(GitObject.tree) as Tree; - expect(peeledCommit.id, commit.id); - expect(peeledTree.id, tree.id); + expect(peeledCommit.oid, commit.oid); + expect(peeledTree.oid, tree.oid); peeledCommit.free(); commit.free(); diff --git a/test/remote_test.dart b/test/remote_test.dart index b83799d..70a4162 100644 --- a/test/remote_test.dart +++ b/test/remote_test.dart @@ -356,7 +356,7 @@ Total 69 (delta 0), reused 1 (delta 0), pack-reused 68 remote.push(refspecs: ['refs/heads/master'], callbacks: callbacks); expect( - originRepo.lookupCommit(originRepo.head.target).id.sha, + originRepo.lookupCommit(originRepo.head.target).oid.sha, '821ed6e80627b8769d170a293862f9fc60825226', ); expect(updateRefOutput, {'refs/heads/master': ''}); diff --git a/test/repository_test.dart b/test/repository_test.dart index e09b119..2325495 100644 --- a/test/repository_test.dart +++ b/test/repository_test.dart @@ -39,10 +39,10 @@ void main() { '6cbc22e509d72758ab4c8d9f287ea846b90c448b', 'f17d0d48eae3aa08cecf29128a35e310c97b3521', ]; - final commits = repo.log(sha: lastCommit); + final commits = repo.log(oid: repo[lastCommit]); for (var i = 0; i < commits.length; i++) { - expect(commits[i].id.sha, log[i]); + expect(commits[i].oid.sha, log[i]); } for (final c in commits) { @@ -100,14 +100,7 @@ void main() { test('successfully sets head when target is sha hex', () { expect(repo.head.target.sha, lastCommit); - repo.setHead(featureCommit); - expect(repo.head.target.sha, featureCommit); - expect(repo.isHeadDetached, true); - }); - - test('successfully sets head when target is short sha hex', () { - expect(repo.head.target.sha, lastCommit); - repo.setHead(featureCommit.substring(0, 5)); + repo.setHead(repo[featureCommit]); expect(repo.head.target.sha, featureCommit); expect(repo.isHeadDetached, true); }); @@ -176,11 +169,11 @@ void main() { final tagger = newTag.tagger; final newTagTarget = newTag.target as Commit; - expect(newTag.id.sha, '131a5eb6b7a880b5096c550ee7351aeae7b95a42'); + expect(newTag.oid.sha, '131a5eb6b7a880b5096c550ee7351aeae7b95a42'); expect(newTag.name, tagName); expect(newTag.message, message); expect(tagger, signature); - expect(newTagTarget.id, target); + expect(newTagTarget.oid, target); newTag.free(); newTagTarget.free(); @@ -255,26 +248,15 @@ void main() { final commit2 = repo.lookupCommit(repo['78b8bf12']); expect( - repo.descendantOf( - commitSHA: commit1.id.sha, - ancestorSHA: commit2.id.sha, - ), + repo.descendantOf(commit: commit1.oid, ancestor: commit2.oid), true, ); - expect( - repo.descendantOf( - commitSHA: commit1.id.sha, - ancestorSHA: commit1.id.sha, - ), + repo.descendantOf(commit: commit1.oid, ancestor: commit1.oid), false, ); - expect( - repo.descendantOf( - commitSHA: commit2.id.sha, - ancestorSHA: commit1.id.sha, - ), + repo.descendantOf(commit: commit2.oid, ancestor: commit1.oid), false, ); @@ -287,15 +269,15 @@ void main() { final commit2 = repo.lookupCommit(repo['c68ff54a']); expect( - repo.aheadBehind(localSHA: commit1.id.sha, upstreamSHA: commit2.id.sha), + repo.aheadBehind(local: commit1.oid, upstream: commit2.oid), [4, 0], ); expect( - repo.aheadBehind(localSHA: commit2.id.sha, upstreamSHA: commit1.id.sha), + repo.aheadBehind(local: commit2.oid, upstream: commit1.oid), [0, 4], ); expect( - repo.aheadBehind(localSHA: commit1.id.sha, upstreamSHA: commit1.id.sha), + repo.aheadBehind(local: commit1.oid, upstream: commit1.oid), [0, 0], ); diff --git a/test/reset_test.dart b/test/reset_test.dart index 286b695..4c30164 100644 --- a/test/reset_test.dart +++ b/test/reset_test.dart @@ -25,7 +25,7 @@ void main() { var contents = file.readAsStringSync(); expect(contents, 'Feature edit\n'); - repo.reset(target: sha, resetType: GitReset.hard); + repo.reset(oid: repo[sha], resetType: GitReset.hard); contents = file.readAsStringSync(); expect(contents, isEmpty); }); @@ -34,7 +34,7 @@ void main() { var contents = file.readAsStringSync(); expect(contents, 'Feature edit\n'); - repo.reset(target: sha, resetType: GitReset.soft); + repo.reset(oid: repo[sha], resetType: GitReset.soft); contents = file.readAsStringSync(); expect(contents, 'Feature edit\n'); @@ -49,7 +49,7 @@ void main() { var contents = file.readAsStringSync(); expect(contents, 'Feature edit\n'); - repo.reset(target: sha, resetType: GitReset.mixed); + repo.reset(oid: repo[sha], resetType: GitReset.mixed); contents = file.readAsStringSync(); expect(contents, 'Feature edit\n'); diff --git a/test/revparse_test.dart b/test/revparse_test.dart index ebeb238..93a6aa2 100644 --- a/test/revparse_test.dart +++ b/test/revparse_test.dart @@ -22,13 +22,13 @@ void main() { group('revParse', () { test('.single() returns commit with different spec strings', () { final headCommit = repo.revParseSingle('HEAD'); - expect(headCommit.id.sha, headSHA); + expect(headCommit.oid.sha, headSHA); final parentCommit = repo.revParseSingle('HEAD^'); - expect(parentCommit.id.sha, parentSHA); + expect(parentCommit.oid.sha, parentSHA); final initCommit = repo.revParseSingle('@{-1}'); - expect(initCommit.id.sha, '5aecfa0fb97eadaac050ccb99f03c3fb65460ad4'); + expect(initCommit.oid.sha, '5aecfa0fb97eadaac050ccb99f03c3fb65460ad4'); headCommit.free(); parentCommit.free(); @@ -39,7 +39,7 @@ void main() { final masterRef = repo.lookupReference('refs/heads/master'); var headParse = repo.revParseExt('master'); - expect(headParse.object.id.sha, headSHA); + expect(headParse.object.oid.sha, headSHA); expect(headParse.reference, masterRef); masterRef.free(); @@ -50,7 +50,9 @@ void main() { headParse = repo.revParseExt('feature'); expect( - headParse.object.id.sha, '5aecfa0fb97eadaac050ccb99f03c3fb65460ad4'); + headParse.object.oid.sha, + '5aecfa0fb97eadaac050ccb99f03c3fb65460ad4', + ); expect(headParse.reference, featureRef); featureRef.free(); @@ -61,7 +63,7 @@ void main() { test('.ext() returns only commit when no intermidiate reference found', () { final headParse = repo.revParseExt('HEAD^'); - expect(headParse.object.id.sha, parentSHA); + expect(headParse.object.oid.sha, parentSHA); expect(headParse.reference, isNull); headParse.object.free(); @@ -72,7 +74,7 @@ void main() { () { var revspec = repo.revParse('master'); - expect(revspec.from.id.sha, headSHA); + expect(revspec.from.oid.sha, headSHA); expect(revspec.to, isNull); expect(revspec.flags, {GitRevSpec.single}); @@ -80,8 +82,8 @@ void main() { revspec = repo.revParse('HEAD^1..5aecfa'); - expect(revspec.from.id.sha, parentSHA); - expect(revspec.to?.id.sha, '5aecfa0fb97eadaac050ccb99f03c3fb65460ad4'); + expect(revspec.from.oid.sha, parentSHA); + expect(revspec.to?.oid.sha, '5aecfa0fb97eadaac050ccb99f03c3fb65460ad4'); expect(revspec.flags, {GitRevSpec.range}); revspec.from.free(); @@ -89,11 +91,11 @@ void main() { revspec = repo.revParse('HEAD...feature'); - expect(revspec.from.id.sha, headSHA); - expect(revspec.to?.id.sha, '5aecfa0fb97eadaac050ccb99f03c3fb65460ad4'); + expect(revspec.from.oid.sha, headSHA); + expect(revspec.to?.oid.sha, '5aecfa0fb97eadaac050ccb99f03c3fb65460ad4'); expect(revspec.flags, {GitRevSpec.range, GitRevSpec.mergeBase}); expect( - repo.mergeBase(a: revspec.from.id.sha, b: revspec.to!.id.sha), + repo.mergeBase(a: revspec.from.oid, b: revspec.to!.oid), isA(), ); diff --git a/test/revwalk_test.dart b/test/revwalk_test.dart index 4076ecd..575ad18 100644 --- a/test/revwalk_test.dart +++ b/test/revwalk_test.dart @@ -33,7 +33,7 @@ void main() { final commits = walker.walk(); for (var i = 0; i < commits.length; i++) { - expect(commits[i].id.sha, log[i]); + expect(commits[i].oid.sha, log[i]); } for (final c in commits) { @@ -51,7 +51,7 @@ void main() { final commits = walker.walk(); for (var i = 0; i < commits.length; i++) { - expect(commits[i].id.sha, log.reversed.toList()[i]); + expect(commits[i].oid.sha, log.reversed.toList()[i]); } for (final c in commits) { @@ -68,13 +68,13 @@ void main() { final timeSortedCommits = walker.walk(); for (var i = 0; i < timeSortedCommits.length; i++) { - expect(timeSortedCommits[i].id.sha, log[i]); + expect(timeSortedCommits[i].oid.sha, log[i]); } 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]); + expect(reverseSortedCommits[i].oid.sha, log.reversed.toList()[i]); } for (final c in timeSortedCommits) { diff --git a/test/submodule_test.dart b/test/submodule_test.dart index a21ec2f..de483cd 100644 --- a/test/submodule_test.dart +++ b/test/submodule_test.dart @@ -33,9 +33,9 @@ void main() { expect(submodule.path, testSubmodule); expect(submodule.url, submoduleUrl); expect(submodule.branch, ''); - expect(submodule.headId?.sha, submoduleHeadSha); - expect(submodule.indexId?.sha, submoduleHeadSha); - expect(submodule.workdirId?.sha, null); + expect(submodule.headOid?.sha, submoduleHeadSha); + expect(submodule.indexOid?.sha, submoduleHeadSha); + expect(submodule.workdirOid?.sha, null); expect(submodule.ignore, GitSubmoduleIgnore.none); expect(submodule.updateRule, GitSubmoduleUpdate.checkout); diff --git a/test/tag_test.dart b/test/tag_test.dart index 4fd9746..cee25da 100644 --- a/test/tag_test.dart +++ b/test/tag_test.dart @@ -7,13 +7,13 @@ void main() { late Repository repo; late Tag tag; late Directory tmpDir; - late Oid tagID; + late Oid tagOid; setUp(() { tmpDir = setupRepo(Directory('test/assets/testrepo/')); repo = Repository.open(tmpDir.path); - tagID = repo['f0fdbf506397e9f58c59b88dfdd72778ec06cc0c']; - tag = repo.lookupTag(tagID); + tagOid = repo['f0fdbf506397e9f58c59b88dfdd72778ec06cc0c']; + tag = repo.lookupTag(tagOid); }); tearDown(() { @@ -37,7 +37,7 @@ void main() { final target = tag.target as Commit; final tagger = tag.tagger; - expect(tag.id, tagID); + expect(tag.oid, tagOid); expect(tag.name, 'v0.2'); expect(tag.message, 'annotated tag\n'); expect(target.message, 'add subdirectory file\n'); @@ -69,11 +69,11 @@ void main() { final tagger = newTag.tagger; final newTagTarget = newTag.target as Commit; - expect(newTag.id.sha, '131a5eb6b7a880b5096c550ee7351aeae7b95a42'); + expect(newTag.oid.sha, '131a5eb6b7a880b5096c550ee7351aeae7b95a42'); expect(newTag.name, tagName); expect(newTag.message, message); expect(tagger, signature); - expect(newTagTarget.id, target); + expect(newTagTarget.oid, target); newTag.free(); newTagTarget.free(); diff --git a/test/tree_test.dart b/test/tree_test.dart index b8bdfd0..963b5bd 100644 --- a/test/tree_test.dart +++ b/test/tree_test.dart @@ -30,13 +30,13 @@ void main() { test('returns correct values', () { expect(tree.length, 4); - expect(tree.entries.first.id.sha, fileSHA); + expect(tree.entries.first.oid.sha, fileSHA); expect(tree.entries[0].name, '.gitignore'); expect(tree.entries[0].filemode, GitFilemode.blob); }); test('returns tree entry with provided index position', () { - expect(tree[0].id.sha, fileSHA); + expect(tree[0].oid.sha, fileSHA); }); test('throws when provided index position is outside of valid range', () { @@ -45,7 +45,7 @@ void main() { }); test('returns tree entry with provided filename', () { - expect(tree['.gitignore'].id.sha, fileSHA); + expect(tree['.gitignore'].oid.sha, fileSHA); }); test('throws when nothing found for provided filename', () { @@ -54,7 +54,7 @@ void main() { test('returns tree entry with provided path to file', () { final entry = tree['dir/dir_file.txt']; - expect(entry.id.sha, 'e69de29bb2d1d6434b8b29ae775ad8c2e48c5391'); + expect(entry.oid.sha, 'e69de29bb2d1d6434b8b29ae775ad8c2e48c5391'); entry.free(); }); @@ -77,7 +77,7 @@ void main() { expect(newTree.length, 1); expect(entry.name, 'filename'); expect(entry.filemode, GitFilemode.blob); - expect(entry.id, fileOid); + expect(entry.oid, fileOid); builder.free(); entry.free(); diff --git a/test/treebuilder_test.dart b/test/treebuilder_test.dart index 4412415..72aa394 100644 --- a/test/treebuilder_test.dart +++ b/test/treebuilder_test.dart @@ -33,7 +33,7 @@ void main() { expect(builder, isA()); expect(builder.length, tree.length); - expect(oid, tree.id); + expect(oid, tree.oid); builder.free(); }); @@ -56,7 +56,7 @@ void main() { builder.add( filename: entry.name, - oid: entry.id, + oid: entry.oid, filemode: entry.filemode, ); expect(builder[entry.name].name, entry.name);