Compare commits

..

4 commits

Author SHA1 Message Date
Aleksey Kulikov
b66662f33c chore: v1.2.2 2023-02-03 12:54:44 +03:00
Aleksey Kulikov
e1ca7e81a2 chore: remove coverage badge 2023-02-02 16:20:28 +03:00
Aleksey Kulikov
7c6060b02c
test(credentials): enable some of the previously disabled tests for Linux (#82) 2023-02-02 16:15:24 +03:00
Aleksey Kulikov
ed67a4e307
fix: lookup package in correct location of Dart/Flutter cached packages (#81) 2023-02-02 15:29:31 +03:00
9 changed files with 87 additions and 107 deletions

View file

@ -1,3 +1,7 @@
## 1.2.2
- fix: lookup package in correct location of Dart/Flutter cached packages
## 1.2.1
- fix: use default location of Flutter's '.pub_cache' folder

View file

@ -1,7 +1,5 @@
# libgit2dart
![Coverage](coverage_badge.svg)
**Dart bindings to libgit2**
libgit2dart package provides ability to use [libgit2](https://github.com/libgit2/libgit2) in Dart/Flutter.
@ -705,7 +703,6 @@ To run all tests and generate coverage report make sure to have activated packag
```sh
$ dart pub global activate coverage
$ dart pub global activate flutter_coverage_badge
```
And run:

View file

@ -5,7 +5,6 @@ import 'package:libgit2dart/libgit2dart.dart';
import 'package:libgit2dart/src/libgit2.dart';
import 'package:libgit2dart/src/util.dart';
import 'package:path/path.dart' as path;
import 'package:pub_cache/pub_cache.dart';
/// Copies prebuilt libgit2 library from package in '.pub_cache' into correct
/// directory for [platform].
@ -23,27 +22,24 @@ Future<void> copyLibrary(String platform) async {
);
}
} else {
String? checkCache(PubCache pubCache) =>
pubCache.getLatestVersion('libgit2dart')?.resolve()?.location.path;
final libPath = checkCache(PubCache()) ??
checkCache(
PubCache(
Directory(
path.join(Platform.environment['FLUTTER_ROOT']!, '.pub-cache'),
),
),
);
final libPath = checkCache();
final libName = getLibName();
stdout.writeln('Copying libgit2 for $platform');
final destination = path.join(libDir, platform);
Directory(destination).createSync(recursive: true);
File(path.join(libPath!, platform, libName)).copySync(
path.join(destination, libName),
);
if (libPath == null) {
stdout.writeln(
"Couldn't find libgit2dart package.\n"
"Make sure to run 'dart pub get' to resolve dependencies.",
);
} else {
final destination = path.join(libDir, platform);
Directory(destination).createSync(recursive: true);
File(path.join(libPath, platform, libName)).copySync(
path.join(destination, libName),
);
stdout.writeln('Done! libgit2 for $platform is now available!');
stdout.writeln('Done! libgit2 for $platform is now available!');
}
}
}
@ -57,7 +53,9 @@ class CleanCommand extends Command<void> {
@override
void run() {
stdout.writeln('Cleaning...');
Directory(libDir).deleteSync(recursive: true);
if (Directory(libDir).existsSync()) {
Directory(libDir).deleteSync(recursive: true);
}
}
}

View file

@ -1,2 +1,2 @@
#!/bin/bash
dart test --coverage=coverage --test-randomize-ordering-seed random && dart pub global run coverage:format_coverage --lcov --check-ignore --in=coverage --out=coverage/lcov.info --report-on=lib && genhtml coverage/lcov.info -o coverage/ && dart pub global run flutter_coverage_badge
dart test --coverage=coverage --test-randomize-ordering-seed random && dart pub global run coverage:format_coverage --lcov --check-ignore --in=coverage --out=coverage/lcov.info --report-on=lib && genhtml coverage/lcov.info -o coverage/

View file

@ -1,20 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="102" height="20">
<linearGradient id="b" x2="0" y2="100%">
<stop offset="0" stop-color="#bbb" stop-opacity=".1"/>
<stop offset="1" stop-opacity=".1"/>
</linearGradient>
<clipPath id="a">
<rect width="102" height="20" rx="3" fill="#fff"/>
</clipPath>
<g clip-path="url(#a)">
<path fill="#555" d="M0 0h59v20H0z"/>
<path fill="#44cc11" d="M59 0h43v20H59z"/>
<path fill="url(#b)" d="M0 0h102v20H0z"/>
</g>
<g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="110">
<text x="305" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="490">coverage</text>
<text x="305" y="140" transform="scale(.1)" textLength="490">coverage</text>
<text x="795" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="330">100%</text>
<text x="795" y="140" transform="scale(.1)" textLength="330">100%</text>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 1 KiB

View file

@ -1,12 +1,13 @@
// coverage:ignore-file
import 'dart:convert';
import 'dart:ffi';
import 'dart:io';
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
import 'package:libgit2dart/src/bindings/libgit2_opts_bindings.dart';
import 'package:path/path.dart' as path;
import 'package:pub_cache/pub_cache.dart';
import 'package:pub_semver/pub_semver.dart';
const libgit2Version = '1.5.0';
final libDir = path.join('.dart_tool', 'libgit2');
@ -25,6 +26,20 @@ String getLibName() {
return 'libgit2-$libgit2Version.$ext';
}
/// Returns location of the most recent verison of the libgit2dart package
/// contained in the cache.
String? checkCache() {
final cache = json.decode(
Process.runSync('dart', ['pub', 'cache', 'list']).stdout as String,
) as Map<String, dynamic>;
final packages = cache['packages'] as Map<String, dynamic>;
final libPackages = packages['libgit2dart'] as Map<String, dynamic>?;
final versions = libPackages?.keys.map((e) => Version.parse(e)).toList();
final latestVersion = libPackages?[Version.primary(versions!).toString()]
as Map<String, dynamic>?;
return latestVersion?['location'] as String?;
}
/// Checks if [File]/[Link] exists for [path].
bool _doesFileExist(String path) {
return File(path).existsSync() || Link(path).existsSync();
@ -65,16 +80,10 @@ String? _resolveLibPath(String name) {
}
}
String checkCache(PubCache pubCache) {
final pubCacheDir =
pubCache.getLatestVersion('libgit2dart')!.resolve()!.location;
return path.join(pubCacheDir.path, Platform.operatingSystem, name);
}
// If lib is in Flutter's '.pub_cache' folder.
final env = Platform.environment;
if (env.containsKey('FLUTTER_ROOT')) {
libPath = checkCache(PubCache());
// If lib is in '.pub_cache' folder.
final cachedLocation = checkCache();
if (cachedLocation != null) {
libPath = path.join(cachedLocation, Platform.operatingSystem, name);
if (_doesFileExist(libPath)) return libPath;
}

View file

@ -4,7 +4,7 @@
#
Pod::Spec.new do |s|
s.name = 'libgit2dart'
s.version = '1.2.1'
s.version = '1.2.2'
s.summary = 'Dart bindings to libgit2.'
s.description = <<-DESC
Dart bindings to libgit2.

View file

@ -2,7 +2,7 @@ name: libgit2dart
description: Dart bindings to libgit2, provides ability to use libgit2 library in Dart and Flutter.
version: 1.2.1
version: 1.2.2
homepage: https://github.com/SkinnyMind/libgit2dart
@ -16,7 +16,7 @@ dependencies:
ffi: ^2.0.0
meta: ^1.7.0
path: ^1.8.1
pub_cache: ^0.3.1
pub_semver: ^2.1.3
dev_dependencies:
ffigen: ^6.0.1

View file

@ -83,32 +83,28 @@ void main() {
cloneDir.deleteSync(recursive: true);
});
test(
testOn: '!linux',
'clones repository with provided keypair',
() {
final cloneDir = Directory.systemTemp.createTempSync('clone');
final keypair = Keypair(
username: 'git',
pubKey: p.join('test', 'assets', 'keys', 'id_rsa.pub'),
privateKey: p.join('test', 'assets', 'keys', 'id_rsa'),
passPhrase: 'empty',
);
final callbacks = Callbacks(credentials: keypair);
test('clones repository with provided keypair', () {
final cloneDir = Directory.systemTemp.createTempSync('clone');
final keypair = Keypair(
username: 'git',
pubKey: p.join('test', 'assets', 'keys', 'id_rsa.pub'),
privateKey: p.join('test', 'assets', 'keys', 'id_rsa'),
passPhrase: 'empty',
);
final callbacks = Callbacks(credentials: keypair);
final repo = Repository.clone(
url: 'ssh://git@github.com/libgit2/TestGitRepository',
localPath: cloneDir.path,
callbacks: callbacks,
);
final repo = Repository.clone(
url: 'ssh://git@github.com/libgit2/TestGitRepository',
localPath: cloneDir.path,
callbacks: callbacks,
);
expect(repo.isEmpty, false);
expect(repo.isEmpty, false);
if (Platform.isLinux || Platform.isMacOS) {
cloneDir.deleteSync(recursive: true);
}
},
);
if (Platform.isLinux || Platform.isMacOS) {
cloneDir.deleteSync(recursive: true);
}
});
test('throws when no credentials is provided', () {
final cloneDir = Directory.systemTemp.createTempSync('clone');
@ -189,36 +185,32 @@ void main() {
cloneDir.deleteSync(recursive: true);
});
test(
testOn: '!linux',
'clones repository with provided keypair from memory',
() {
final cloneDir = Directory.systemTemp.createTempSync('clone');
final pubKey = File(p.join('test', 'assets', 'keys', 'id_rsa.pub'))
.readAsStringSync();
final privateKey =
File(p.join('test', 'assets', 'keys', 'id_rsa')).readAsStringSync();
final keypair = KeypairFromMemory(
username: 'git',
pubKey: pubKey,
privateKey: privateKey,
passPhrase: 'empty',
);
final callbacks = Callbacks(credentials: keypair);
test('clones repository with provided keypair from memory', () {
final cloneDir = Directory.systemTemp.createTempSync('clone');
final pubKey = File(p.join('test', 'assets', 'keys', 'id_rsa.pub'))
.readAsStringSync();
final privateKey =
File(p.join('test', 'assets', 'keys', 'id_rsa')).readAsStringSync();
final keypair = KeypairFromMemory(
username: 'git',
pubKey: pubKey,
privateKey: privateKey,
passPhrase: 'empty',
);
final callbacks = Callbacks(credentials: keypair);
final repo = Repository.clone(
url: 'ssh://git@github.com/libgit2/TestGitRepository',
localPath: cloneDir.path,
callbacks: callbacks,
);
final repo = Repository.clone(
url: 'ssh://git@github.com/libgit2/TestGitRepository',
localPath: cloneDir.path,
callbacks: callbacks,
);
expect(repo.isEmpty, false);
expect(repo.isEmpty, false);
if (Platform.isLinux || Platform.isMacOS) {
cloneDir.deleteSync(recursive: true);
}
},
);
if (Platform.isLinux || Platform.isMacOS) {
cloneDir.deleteSync(recursive: true);
}
});
test('throws when provided keypair from memory is incorrect', () {
final cloneDir = Directory.systemTemp.createTempSync('clone');