mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-04 20:29:08 -04:00
test: disable repository owner verification for tests (#47)
This commit is contained in:
parent
f42f8a6e1b
commit
94c40f9a94
4 changed files with 61 additions and 4 deletions
|
@ -2480,17 +2480,39 @@ class Libgit2 {
|
||||||
/// @return 0 on success, <0 on failure
|
/// @return 0 on success, <0 on failure
|
||||||
int git_libgit2_opts(
|
int git_libgit2_opts(
|
||||||
int option,
|
int option,
|
||||||
|
ffi.Pointer<ffi.Int8> out,
|
||||||
) {
|
) {
|
||||||
return _git_libgit2_opts(
|
return _git_libgit2_opts(
|
||||||
option,
|
option,
|
||||||
|
out,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
late final _git_libgit2_optsPtr =
|
late final _git_libgit2_optsPtr = _lookup<
|
||||||
_lookup<ffi.NativeFunction<ffi.Int32 Function(ffi.Int32)>>(
|
ffi.NativeFunction<
|
||||||
|
ffi.Int32 Function(
|
||||||
|
ffi.Int32, ffi.Pointer<ffi.Int8>)>>('git_libgit2_opts');
|
||||||
|
late final _git_libgit2_opts = _git_libgit2_optsPtr
|
||||||
|
.asFunction<int Function(int, ffi.Pointer<ffi.Int8>)>();
|
||||||
|
|
||||||
|
/// Set a library global option.
|
||||||
|
///
|
||||||
|
/// Look at [git_libgit2_opts]
|
||||||
|
int git_libgit2_opts_set(
|
||||||
|
int option,
|
||||||
|
int value,
|
||||||
|
) {
|
||||||
|
return _git_libgit2_opts_set(
|
||||||
|
option,
|
||||||
|
value,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
late final _git_libgit2_opts_setPtr =
|
||||||
|
_lookup<ffi.NativeFunction<ffi.Int32 Function(ffi.Int32, ffi.Int32)>>(
|
||||||
'git_libgit2_opts');
|
'git_libgit2_opts');
|
||||||
late final _git_libgit2_opts =
|
late final _git_libgit2_opts_set =
|
||||||
_git_libgit2_optsPtr.asFunction<int Function(int)>();
|
_git_libgit2_opts_setPtr.asFunction<int Function(int, int)>();
|
||||||
|
|
||||||
/// Free the memory referred to by the git_buf.
|
/// Free the memory referred to by the git_buf.
|
||||||
///
|
///
|
||||||
|
|
|
@ -2,6 +2,7 @@ import 'dart:ffi';
|
||||||
|
|
||||||
import 'package:ffi/ffi.dart';
|
import 'package:ffi/ffi.dart';
|
||||||
import 'package:libgit2dart/libgit2dart.dart';
|
import 'package:libgit2dart/libgit2dart.dart';
|
||||||
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
import 'package:libgit2dart/src/util.dart';
|
import 'package:libgit2dart/src/util.dart';
|
||||||
|
|
||||||
class Libgit2 {
|
class Libgit2 {
|
||||||
|
@ -33,4 +34,25 @@ class Libgit2 {
|
||||||
.where((e) => featuresInt & e.value == e.value)
|
.where((e) => featuresInt & e.value == e.value)
|
||||||
.toSet();
|
.toSet();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns owner validation setting for repository directories.
|
||||||
|
static bool get ownerValidation {
|
||||||
|
libgit2.git_libgit2_init();
|
||||||
|
final out = calloc<Int8>();
|
||||||
|
libgit2.git_libgit2_opts(
|
||||||
|
git_libgit2_opt_t.GIT_OPT_GET_OWNER_VALIDATION,
|
||||||
|
out,
|
||||||
|
);
|
||||||
|
return out.value == 1 || false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Sets owner validation setting for repository directories.
|
||||||
|
static set ownerValidation(bool value) {
|
||||||
|
libgit2.git_libgit2_init();
|
||||||
|
final valueC = value ? 1 : 0;
|
||||||
|
libgit2.git_libgit2_opts_set(
|
||||||
|
git_libgit2_opt_t.GIT_OPT_SET_OWNER_VALIDATION,
|
||||||
|
valueC,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
import 'package:libgit2dart/libgit2dart.dart';
|
||||||
import 'package:path/path.dart' as p;
|
import 'package:path/path.dart' as p;
|
||||||
|
|
||||||
Directory setupRepo(Directory repoDir) {
|
Directory setupRepo(Directory repoDir) {
|
||||||
|
Libgit2.ownerValidation = false;
|
||||||
final tmpDir = Directory.systemTemp.createTempSync('testrepo');
|
final tmpDir = Directory.systemTemp.createTempSync('testrepo');
|
||||||
copyRepo(from: repoDir, to: tmpDir);
|
copyRepo(from: repoDir, to: tmpDir);
|
||||||
return tmpDir;
|
return tmpDir;
|
||||||
|
|
|
@ -14,5 +14,16 @@ void main() {
|
||||||
{GitFeature.threads, GitFeature.https, GitFeature.ssh, GitFeature.nsec},
|
{GitFeature.threads, GitFeature.https, GitFeature.ssh, GitFeature.nsec},
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test(
|
||||||
|
'sets and returns the owner validation setting for repository '
|
||||||
|
'directories', () {
|
||||||
|
final oldValue = Libgit2.ownerValidation;
|
||||||
|
Libgit2.ownerValidation = !oldValue;
|
||||||
|
expect(Libgit2.ownerValidation, equals(!oldValue));
|
||||||
|
|
||||||
|
// Set it back
|
||||||
|
Libgit2.ownerValidation = oldValue;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue