diff --git a/lib/src/annotated.dart b/lib/src/annotated.dart index c500dd9..0c4669e 100644 --- a/lib/src/annotated.dart +++ b/lib/src/annotated.dart @@ -84,6 +84,7 @@ class AnnotatedCommit extends Equatable { /// Pointer to pointer to memory address for allocated commit object. /// /// Note: For internal use. + @internal Pointer get pointer => _annotatedCommitPointer; /// Commit oid that the given annotated commit refers to. diff --git a/lib/src/bindings/worktree.dart b/lib/src/bindings/worktree.dart index 663c1f2..61923da 100644 --- a/lib/src/bindings/worktree.dart +++ b/lib/src/bindings/worktree.dart @@ -96,8 +96,16 @@ bool isPrunable(Pointer wt) { /// Prune working tree. /// /// Prune the working tree, that is remove the git data structures on disk. -void prune(Pointer wt) { - libgit2.git_worktree_prune(wt, nullptr); +void prune({required Pointer worktreePointer, int? flags}) { + final opts = calloc(); + libgit2.git_worktree_prune_options_init( + opts, + GIT_WORKTREE_PRUNE_OPTIONS_VERSION, + ); + + if (flags != null) opts.ref.flags = flags; + + libgit2.git_worktree_prune(worktreePointer, opts); } /// List names of linked working trees. diff --git a/lib/src/blob.dart b/lib/src/blob.dart index 89ea241..5b27d78 100644 --- a/lib/src/blob.dart +++ b/lib/src/blob.dart @@ -12,6 +12,7 @@ class Blob extends Equatable { /// blob object in memory. /// /// Note: For internal use. Use [Blob.lookup] instead. + @internal Blob(this._blobPointer) { _finalizer.attach(this, _blobPointer, detach: this); } @@ -30,6 +31,7 @@ class Blob extends Equatable { /// Pointer to memory address for allocated blob object. /// /// Note: For internal use. + @internal Pointer get pointer => _blobPointer; /// Creates a new blob from a [content] string and writes it to ODB. diff --git a/lib/src/branch.dart b/lib/src/branch.dart index 976598c..c221105 100644 --- a/lib/src/branch.dart +++ b/lib/src/branch.dart @@ -15,6 +15,7 @@ class Branch extends Equatable { /// Note: For internal use. Instead, use one of: /// - [Branch.create] /// - [Branch.lookup] + @internal Branch(this._branchPointer) { _finalizer.attach(this, _branchPointer, detach: this); } @@ -74,6 +75,7 @@ class Branch extends Equatable { /// Pointer to memory address for allocated branch object. /// /// Note: For internal use. + @internal Pointer get pointer => _branchPointer; /// Returns a list of branches that can be found in a [repo]sitory for diff --git a/lib/src/commit.dart b/lib/src/commit.dart index 0e399ff..3cd7ef1 100644 --- a/lib/src/commit.dart +++ b/lib/src/commit.dart @@ -13,6 +13,7 @@ class Commit extends Equatable { /// commit object in memory. /// /// Note: For internal use. Use [Commit.lookup] instead. + @internal Commit(this._commitPointer) { _finalizer.attach(this, _commitPointer, detach: this); } @@ -31,6 +32,7 @@ class Commit extends Equatable { /// Pointer to memory address for allocated commit object. /// /// Note: For internal use. + @internal Pointer get pointer => _commitPointer; /// Creates new commit in the [repo]sitory. diff --git a/lib/src/config.dart b/lib/src/config.dart index 7ccce28..5d236de 100644 --- a/lib/src/config.dart +++ b/lib/src/config.dart @@ -20,6 +20,7 @@ class Config with IterableMixin { /// - [Config.system] /// - [Config.global] /// - [Config.xdg] + @internal Config(this._configPointer) { _finalizer.attach(this, _configPointer, detach: this); } diff --git a/lib/src/diff.dart b/lib/src/diff.dart index 9ca2605..3425ce2 100644 --- a/lib/src/diff.dart +++ b/lib/src/diff.dart @@ -21,6 +21,7 @@ class Diff extends Equatable { /// - [Diff.treeToWorkdirWithIndex] /// - [Diff.treeToTree] /// - [Diff.parse] + @internal Diff(this._diffPointer) { _finalizer.attach(this, _diffPointer, detach: this); } @@ -276,6 +277,7 @@ class Diff extends Equatable { /// Pointer to memory address for allocated diff object. /// /// Note: For internal use. + @internal Pointer get pointer => _diffPointer; /// How many diff records are there in a diff. @@ -471,6 +473,9 @@ final _finalizer = Finalizer>( class DiffDelta extends Equatable { /// Initializes a new instance of [DiffDelta] class from provided /// pointer to diff delta object in memory. + /// + /// Note: For internal use. + @internal const DiffDelta(this._diffDeltaPointer); /// Pointer to memory address for allocated diff delta object. @@ -578,6 +583,7 @@ class DiffStats { /// pointer to diff stats object in memory. /// /// Note: For internal use. + @internal DiffStats(this._diffStatsPointer) { _statsFinalizer.attach(this, _diffStatsPointer, detach: this); } diff --git a/lib/src/error.dart b/lib/src/error.dart index 97eec9b..5a52968 100644 --- a/lib/src/error.dart +++ b/lib/src/error.dart @@ -3,9 +3,12 @@ import 'dart:ffi'; import 'package:libgit2dart/src/bindings/libgit2_bindings.dart'; import 'package:libgit2dart/src/extensions.dart'; +import 'package:meta/meta.dart'; /// Details of the last error that occurred. class LibGit2Error { + /// Note: For internal use. + @internal LibGit2Error(this._errorPointer); final Pointer _errorPointer; diff --git a/lib/src/git_types.dart b/lib/src/git_types.dart index 65be8ed..3659324 100644 --- a/lib/src/git_types.dart +++ b/lib/src/git_types.dart @@ -1192,3 +1192,18 @@ enum GitIndexAddOption { const GitIndexAddOption(this.value); final int value; } + +/// Flags to alter working tree pruning behavior. +enum GitWorktree { + /// Prune working tree even if working tree is valid. + pruneValid(1), + + /// Prune working tree even if it is locked. + pruneLocked(2), + + /// Prune checked out working tree. + pruneWorkingTree(4); + + const GitWorktree(this.value); + final int value; +} diff --git a/lib/src/index.dart b/lib/src/index.dart index 96ff8f8..63ab0be 100644 --- a/lib/src/index.dart +++ b/lib/src/index.dart @@ -13,6 +13,7 @@ class Index with IterableMixin { /// pointer to index object in memory. /// /// Note: For internal use. + @internal Index(this._indexPointer) { _finalizer.attach(this, _indexPointer, detach: this); } @@ -31,6 +32,7 @@ class Index with IterableMixin { /// Pointer to memory address for allocated index object. /// /// Note: For internal use. + @internal Pointer get pointer => _indexPointer; /// Full path to the index file on disk. @@ -339,6 +341,7 @@ class IndexEntry extends Equatable { /// Initializes a new instance of [IndexEntry] class. /// /// Note: For internal use. + @internal const IndexEntry(this._indexEntryPointer); final Pointer _indexEntryPointer; @@ -346,6 +349,7 @@ class IndexEntry extends Equatable { /// Pointer to memory address for allocated index entry object. /// /// Note: For internal use. + @internal Pointer get pointer => _indexEntryPointer; /// [Oid] of the index entry. @@ -387,6 +391,7 @@ class ConflictEntry { /// Initializes a new instance of [ConflictEntry] class. /// /// Note: For internal use. + @internal const ConflictEntry( this._indexPointer, this._path, diff --git a/lib/src/note.dart b/lib/src/note.dart index 1dd874b..f29aac0 100644 --- a/lib/src/note.dart +++ b/lib/src/note.dart @@ -11,6 +11,7 @@ class Note extends Equatable { /// pointer to note and annotatedOid objects in memory. /// /// Note: For internal use. Use [Note.lookup] instead. + @internal Note(this._notePointer, this._annotatedOidPointer) { _finalizer.attach(this, _notePointer, detach: this); } diff --git a/lib/src/odb.dart b/lib/src/odb.dart index 0969f2f..a3c486f 100644 --- a/lib/src/odb.dart +++ b/lib/src/odb.dart @@ -12,6 +12,7 @@ class Odb extends Equatable { /// pointer to Odb object in memory. /// /// Note: For internal use. + @internal Odb(this._odbPointer) { _finalizer.attach(this, _odbPointer, detach: this); } @@ -32,6 +33,7 @@ class Odb extends Equatable { /// Pointer to memory address for allocated oid object. /// /// Note: For internal use. + @internal Pointer get pointer => _odbPointer; /// Adds an on-disk alternate to an existing Object DB. diff --git a/lib/src/oid.dart b/lib/src/oid.dart index ceca4b1..0e50b1b 100644 --- a/lib/src/oid.dart +++ b/lib/src/oid.dart @@ -14,6 +14,7 @@ class Oid extends Equatable { /// pointer to Oid object in memory. /// /// Note: For internal use. Use [Oid.fromSHA] instead. + @internal Oid(this._oidPointer); /// Initializes a new instance of [Oid] class by determining if an object can @@ -41,6 +42,9 @@ class Oid extends Equatable { /// Initializes a new instance of [Oid] class from provided raw git_oid /// structure. + /// + /// Note: For internal use. + @internal Oid.fromRaw(git_oid raw) { _oidPointer = bindings.fromRaw(raw.id); } @@ -50,6 +54,7 @@ class Oid extends Equatable { /// Pointer to memory address for allocated oid object. /// /// Note: For internal use. + @internal Pointer get pointer => _oidPointer; /// Hexadecimal SHA string. diff --git a/lib/src/packbuilder.dart b/lib/src/packbuilder.dart index f151b07..c9a9ea6 100644 --- a/lib/src/packbuilder.dart +++ b/lib/src/packbuilder.dart @@ -2,6 +2,7 @@ import 'dart:ffi'; import 'package:libgit2dart/libgit2dart.dart'; import 'package:libgit2dart/src/bindings/libgit2_bindings.dart'; import 'package:libgit2dart/src/bindings/packbuilder.dart' as bindings; +import 'package:meta/meta.dart'; class PackBuilder { /// Initializes a new instance of [PackBuilder] class. @@ -9,6 +10,7 @@ class PackBuilder { /// Throws a [LibGit2Error] if error occured. /// /// Note: For internal use. + @internal PackBuilder(Repository repo) { _packbuilderPointer = bindings.init(repo.pointer); _finalizer.attach(this, _packbuilderPointer, detach: this); diff --git a/lib/src/patch.dart b/lib/src/patch.dart index 16e5b25..c837afa 100644 --- a/lib/src/patch.dart +++ b/lib/src/patch.dart @@ -18,6 +18,7 @@ class Patch extends Equatable { /// - [Patch.fromBlobAndBuffer] /// - [Patch.fromBuffers] /// - [Patch.fromDiff] + @internal Patch(this._patchPointer) { _finalizer.attach(this, _patchPointer, detach: this); } diff --git a/lib/src/reference.dart b/lib/src/reference.dart index 1f45270..c5d4471 100644 --- a/lib/src/reference.dart +++ b/lib/src/reference.dart @@ -17,6 +17,7 @@ class Reference extends Equatable { /// Note: For internal use. Instead, use one of: /// - [Reference.create] /// - [Reference.lookup] + @internal Reference(this._refPointer) { _finalizer.attach(this, _refPointer, detach: this); } @@ -87,6 +88,7 @@ class Reference extends Equatable { /// Pointer to memory address for allocated reference object. /// /// Note: For internal use. + @internal Pointer get pointer => _refPointer; /// Deletes an existing reference with provided [name]. diff --git a/lib/src/refspec.dart b/lib/src/refspec.dart index 679abca..66c9405 100644 --- a/lib/src/refspec.dart +++ b/lib/src/refspec.dart @@ -11,6 +11,7 @@ class Refspec extends Equatable { /// from provided pointer to refspec object in memory. /// /// Note: For internal use. + @internal const Refspec(this._refspecPointer); /// Pointer to memory address for allocated refspec object. diff --git a/lib/src/remote.dart b/lib/src/remote.dart index 9144861..d74dbf3 100644 --- a/lib/src/remote.dart +++ b/lib/src/remote.dart @@ -327,6 +327,7 @@ class TransferProgress { /// pointer to transfer progress object in memory. /// /// Note: For internal use. + @internal const TransferProgress(this._transferProgressPointer); /// Pointer to memory address for allocated transfer progress object. diff --git a/lib/src/repository.dart b/lib/src/repository.dart index 2cc9f04..619b1ea 100644 --- a/lib/src/repository.dart +++ b/lib/src/repository.dart @@ -23,6 +23,7 @@ class Repository extends Equatable { /// - [Repository.init] /// - [Repository.open] /// - [Repository.clone] + @internal Repository(Pointer pointer) { _repoPointer = pointer; _finalizer.attach(this, _repoPointer, detach: this); @@ -161,6 +162,7 @@ class Repository extends Equatable { /// Pointer to memory address for allocated repository object. /// /// Note: For internal use. + @internal Pointer get pointer => _repoPointer; /// Looks for a git repository and return its path. The lookup start from diff --git a/lib/src/revwalk.dart b/lib/src/revwalk.dart index 610ebb9..78b8491 100644 --- a/lib/src/revwalk.dart +++ b/lib/src/revwalk.dart @@ -2,6 +2,7 @@ import 'dart:ffi'; import 'package:libgit2dart/libgit2dart.dart'; import 'package:libgit2dart/src/bindings/libgit2_bindings.dart'; import 'package:libgit2dart/src/bindings/revwalk.dart' as bindings; +import 'package:meta/meta.dart'; class RevWalk { /// Initializes a new instance of the [RevWalk] class. @@ -15,6 +16,7 @@ class RevWalk { /// Pointer to memory address for allocated [RevWalk] object. /// /// Note: For internal use. + @internal Pointer get pointer => _revWalkPointer; /// Returns the list of commits from the revision walk. diff --git a/lib/src/signature.dart b/lib/src/signature.dart index c533191..620b33c 100644 --- a/lib/src/signature.dart +++ b/lib/src/signature.dart @@ -16,6 +16,7 @@ class Signature extends Equatable { /// Note: For internal use. Instead, use one of: /// - [Signature.create] /// - [Signature.defaultSignature] + @internal Signature(Pointer pointer) { _signaturePointer = bindings.duplicate(pointer); _finalizer.attach(this, _signaturePointer, detach: this); @@ -62,6 +63,7 @@ class Signature extends Equatable { /// Pointer to memory address for allocated signature object. /// /// Note: For internal use. + @internal Pointer get pointer => _signaturePointer; /// Full name of the author. diff --git a/lib/src/stash.dart b/lib/src/stash.dart index 85f5ff2..bbd1267 100644 --- a/lib/src/stash.dart +++ b/lib/src/stash.dart @@ -7,6 +7,9 @@ import 'package:meta/meta.dart'; class Stash extends Equatable { /// Initializes a new instance of [Stash] class from provided stash [index], /// [message] and [oid]. + /// + /// Note: For internal use. Use [Stash.create] instead to create stash. + @internal const Stash({ required this.index, required this.message, diff --git a/lib/src/tag.dart b/lib/src/tag.dart index 8a9e26a..14965e8 100644 --- a/lib/src/tag.dart +++ b/lib/src/tag.dart @@ -13,6 +13,7 @@ class Tag extends Equatable { /// tag object in memory. /// /// Note: For internal use. Use [Tag.lookup] instead. + @internal Tag(this._tagPointer) { _finalizer.attach(this, _tagPointer, detach: this); } diff --git a/lib/src/tree.dart b/lib/src/tree.dart index 5ab1a73..d3a479a 100644 --- a/lib/src/tree.dart +++ b/lib/src/tree.dart @@ -12,6 +12,7 @@ class Tree extends Equatable { /// tree object in memory. /// /// Note: For internal use. Use [Tree.lookup] instead. + @internal Tree(this._treePointer) { _finalizer.attach(this, _treePointer, detach: this); } @@ -30,6 +31,7 @@ class Tree extends Equatable { /// Pointer to memory address for allocated tree object. /// /// Note: For internal use. + @internal Pointer get pointer => _treePointer; /// List with tree entries of a tree. @@ -113,6 +115,7 @@ class TreeEntry extends Equatable { /// tree entry object in memory. /// /// Note: For internal use. + @internal const TreeEntry(this._treeEntryPointer); /// Initializes a new instance of [TreeEntry] class from provided pointer to diff --git a/lib/src/worktree.dart b/lib/src/worktree.dart index 32939c6..d78e7cc 100644 --- a/lib/src/worktree.dart +++ b/lib/src/worktree.dart @@ -77,10 +77,15 @@ class Worktree extends Equatable { /// Throws a [LibGit2Error] if error occured. bool get isPrunable => bindings.isPrunable(_worktreePointer); - /// Prunes working tree. + /// Prunes working tree, that is removes the git data structures on disk. /// - /// Prune the working tree, that is remove the git data structures on disk. - void prune() => bindings.prune(_worktreePointer); + /// [flags] is optional combination of [GitWorktree] flags. + void prune([Set? flags]) { + bindings.prune( + worktreePointer: _worktreePointer, + flags: flags?.fold(0, (acc, e) => acc! | e.value), + ); + } /// Whether worktree is valid. /// diff --git a/test/git_types_test.dart b/test/git_types_test.dart index cdbacaf..68ef591 100644 --- a/test/git_types_test.dart +++ b/test/git_types_test.dart @@ -562,4 +562,14 @@ void main() { final actual = {for (final e in GitIndexAddOption.values) e: e.value}; expect(actual, expected); }); + + test('GitWorktree returns correct values', () { + const expected = { + GitWorktree.pruneValid: 1, + GitWorktree.pruneLocked: 2, + GitWorktree.pruneWorkingTree: 4, + }; + final actual = {for (final e in GitWorktree.values) e: e.value}; + expect(actual, expected); + }); } diff --git a/test/worktree_test.dart b/test/worktree_test.dart index 0da572a..550cf33 100644 --- a/test/worktree_test.dart +++ b/test/worktree_test.dart @@ -151,6 +151,22 @@ void main() { expect(repo.worktrees, []); }); + test('prunes worktree with provided flags', () { + expect(repo.worktrees, []); + + final worktree = Worktree.create( + repo: repo, + name: worktreeName, + path: worktreeDir.path, + ); + expect(repo.worktrees, [worktreeName]); + expect(worktree.isPrunable, false); + expect(worktree.isValid, true); + + worktree.prune({GitWorktree.pruneValid}); + expect(repo.worktrees, []); + }); + test('throws when trying get list of worktrees and error occurs', () { expect( () => Worktree.list(Repository(nullptr)),