mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-05 04:39:07 -04:00
feat(reset): add ability to remove entries in index
This commit is contained in:
parent
16c42b9b2d
commit
664e0688b2
3 changed files with 29 additions and 9 deletions
|
@ -28,12 +28,15 @@ void reset({
|
||||||
/// Updates some entries in the index from the target commit tree.
|
/// Updates some entries in the index from the target commit tree.
|
||||||
///
|
///
|
||||||
/// The scope of the updated entries is determined by the paths being passed in
|
/// The scope of the updated entries is determined by the paths being passed in
|
||||||
/// the pathspec parameters.
|
/// the [pathspec] parameters.
|
||||||
|
///
|
||||||
|
/// Passing a null [targetPointer] will result in removing entries in the index
|
||||||
|
/// matching the provided [pathspec]s.
|
||||||
///
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
void resetDefault({
|
void resetDefault({
|
||||||
required Pointer<git_repository> repoPointer,
|
required Pointer<git_repository> repoPointer,
|
||||||
required Pointer<git_object> targetPointer,
|
required Pointer<git_object>? targetPointer,
|
||||||
required List<String> pathspec,
|
required List<String> pathspec,
|
||||||
}) {
|
}) {
|
||||||
final pathspecC = calloc<git_strarray>();
|
final pathspecC = calloc<git_strarray>();
|
||||||
|
@ -50,7 +53,7 @@ void resetDefault({
|
||||||
|
|
||||||
final error = libgit2.git_reset_default(
|
final error = libgit2.git_reset_default(
|
||||||
repoPointer,
|
repoPointer,
|
||||||
targetPointer,
|
targetPointer ?? nullptr,
|
||||||
pathspecC,
|
pathspecC,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -578,13 +578,19 @@ class Repository extends Equatable {
|
||||||
/// The scope of the updated entries is determined by the paths being passed
|
/// The scope of the updated entries is determined by the paths being passed
|
||||||
/// in the [pathspec].
|
/// in the [pathspec].
|
||||||
///
|
///
|
||||||
|
/// Passing a null [oid] will result in removing entries in the index
|
||||||
|
/// matching the provided [pathspec]s.
|
||||||
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
void resetDefault({required Oid oid, required List<String> pathspec}) {
|
void resetDefault({required Oid? oid, required List<String> pathspec}) {
|
||||||
final object = object_bindings.lookup(
|
Pointer<git_object>? object;
|
||||||
|
if (oid != null) {
|
||||||
|
object = object_bindings.lookup(
|
||||||
repoPointer: _repoPointer,
|
repoPointer: _repoPointer,
|
||||||
oidPointer: oid.pointer,
|
oidPointer: oid.pointer,
|
||||||
type: GitObject.commit.value,
|
type: GitObject.commit.value,
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
reset_bindings.resetDefault(
|
reset_bindings.resetDefault(
|
||||||
repoPointer: _repoPointer,
|
repoPointer: _repoPointer,
|
||||||
|
|
|
@ -61,6 +61,17 @@ void main() {
|
||||||
expect(repo.status['feature_file'], {GitStatus.wtModified});
|
expect(repo.status['feature_file'], {GitStatus.wtModified});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('removes entry in the index when null oid is provided', () {
|
||||||
|
const fileName = 'new_file.txt';
|
||||||
|
File(p.join(tmpDir.path, fileName)).createSync();
|
||||||
|
|
||||||
|
repo.index.add(fileName);
|
||||||
|
expect(repo.status[fileName], {GitStatus.indexNew});
|
||||||
|
|
||||||
|
repo.resetDefault(oid: null, pathspec: [fileName]);
|
||||||
|
expect(repo.status[fileName], {GitStatus.wtNew});
|
||||||
|
});
|
||||||
|
|
||||||
test('throws when pathspec list is empty', () {
|
test('throws when pathspec list is empty', () {
|
||||||
expect(
|
expect(
|
||||||
() => repo.resetDefault(oid: repo.head.target, pathspec: []),
|
() => repo.resetDefault(oid: repo.head.target, pathspec: []),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue