mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-05 04:39:07 -04:00
Compare commits
No commits in common. "master" and "v1.2.0" have entirely different histories.
10 changed files with 110 additions and 122 deletions
14
CHANGELOG.md
14
CHANGELOG.md
|
@ -1,17 +1,3 @@
|
||||||
## 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
|
|
||||||
|
|
||||||
- docs: update README with troubleshooting instructions for Windows
|
|
||||||
|
|
||||||
- chore: bump minimum dart and flutter versions
|
|
||||||
|
|
||||||
- chore: Lookup library in system path (thanks @dnys1)
|
|
||||||
|
|
||||||
## 1.2.0
|
## 1.2.0
|
||||||
|
|
||||||
- feat: upgrade libgit2 to 1.5.0
|
- feat: upgrade libgit2 to 1.5.0
|
||||||
|
|
15
README.md
15
README.md
|
@ -1,5 +1,7 @@
|
||||||
# libgit2dart
|
# libgit2dart
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
**Dart bindings to libgit2**
|
**Dart bindings to libgit2**
|
||||||
|
|
||||||
libgit2dart package provides ability to use [libgit2](https://github.com/libgit2/libgit2) in Dart/Flutter.
|
libgit2dart package provides ability to use [libgit2](https://github.com/libgit2/libgit2) in Dart/Flutter.
|
||||||
|
@ -663,8 +665,6 @@ Fork libgit2dart, improve libgit2dart, send a pull request.
|
||||||
|
|
||||||
### Troubleshooting
|
### Troubleshooting
|
||||||
|
|
||||||
#### Linux:
|
|
||||||
|
|
||||||
If you are developing on Linux using non-Debian based distrib you might encounter these errors:
|
If you are developing on Linux using non-Debian based distrib you might encounter these errors:
|
||||||
|
|
||||||
- Failed to load dynamic library: libpcre.so.3: cannot open shared object file: No such file or directory
|
- Failed to load dynamic library: libpcre.so.3: cannot open shared object file: No such file or directory
|
||||||
|
@ -679,16 +679,6 @@ sudo ln -s /usr/lib64/libpcre.so /usr/lib64/libpcre.so.3
|
||||||
sudo ln -s /usr/lib64/libpcreposix.so /usr/lib64/libpcreposix.so.3
|
sudo ln -s /usr/lib64/libpcreposix.so /usr/lib64/libpcreposix.so.3
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Windows:
|
|
||||||
|
|
||||||
If you are developing on Windows you might encounter:
|
|
||||||
|
|
||||||
- Failed to load dynamic library: error code 126
|
|
||||||
|
|
||||||
That happens because libgit2 dynamic library bundled with libgit2dart package is precompiled with ssh support, and it fails to find the `libssh2.dll`.
|
|
||||||
|
|
||||||
To fix that error you should [build](https://github.com/libssh2/libssh2/blob/master/docs/INSTALL_CMAKE.md) libssh2, and place resulting `libssh2.dll` somewhere in system path (e.g. "Windows\System32").
|
|
||||||
|
|
||||||
### Ffigen
|
### Ffigen
|
||||||
|
|
||||||
To generate bindings with ffigen use (adjust paths to yours):
|
To generate bindings with ffigen use (adjust paths to yours):
|
||||||
|
@ -703,6 +693,7 @@ To run all tests and generate coverage report make sure to have activated packag
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
$ dart pub global activate coverage
|
$ dart pub global activate coverage
|
||||||
|
$ dart pub global activate flutter_coverage_badge
|
||||||
```
|
```
|
||||||
|
|
||||||
And run:
|
And run:
|
||||||
|
|
|
@ -5,6 +5,7 @@ import 'package:libgit2dart/libgit2dart.dart';
|
||||||
import 'package:libgit2dart/src/libgit2.dart';
|
import 'package:libgit2dart/src/libgit2.dart';
|
||||||
import 'package:libgit2dart/src/util.dart';
|
import 'package:libgit2dart/src/util.dart';
|
||||||
import 'package:path/path.dart' as path;
|
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
|
/// Copies prebuilt libgit2 library from package in '.pub_cache' into correct
|
||||||
/// directory for [platform].
|
/// directory for [platform].
|
||||||
|
@ -22,26 +23,29 @@ Future<void> copyLibrary(String platform) async {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
final libPath = checkCache();
|
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 libName = getLibName();
|
final libName = getLibName();
|
||||||
|
|
||||||
stdout.writeln('Copying libgit2 for $platform');
|
stdout.writeln('Copying libgit2 for $platform');
|
||||||
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);
|
final destination = path.join(libDir, platform);
|
||||||
Directory(destination).createSync(recursive: true);
|
Directory(destination).createSync(recursive: true);
|
||||||
File(path.join(libPath, platform, libName)).copySync(
|
File(path.join(libPath!, platform, libName)).copySync(
|
||||||
path.join(destination, libName),
|
path.join(destination, libName),
|
||||||
);
|
);
|
||||||
|
|
||||||
stdout.writeln('Done! libgit2 for $platform is now available!');
|
stdout.writeln('Done! libgit2 for $platform is now available!');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
class CleanCommand extends Command<void> {
|
class CleanCommand extends Command<void> {
|
||||||
@override
|
@override
|
||||||
|
@ -53,11 +57,9 @@ class CleanCommand extends Command<void> {
|
||||||
@override
|
@override
|
||||||
void run() {
|
void run() {
|
||||||
stdout.writeln('Cleaning...');
|
stdout.writeln('Cleaning...');
|
||||||
if (Directory(libDir).existsSync()) {
|
|
||||||
Directory(libDir).deleteSync(recursive: true);
|
Directory(libDir).deleteSync(recursive: true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void main(List<String> args) {
|
void main(List<String> args) {
|
||||||
final runner = CommandRunner<void>(
|
final runner = CommandRunner<void>(
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
#!/bin/bash
|
#!/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 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
|
20
coverage_badge.svg
Normal file
20
coverage_badge.svg
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
<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>
|
After Width: | Height: | Size: 1 KiB |
|
@ -1,13 +1,12 @@
|
||||||
// coverage:ignore-file
|
// coverage:ignore-file
|
||||||
|
|
||||||
import 'dart:convert';
|
|
||||||
import 'dart:ffi';
|
import 'dart:ffi';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_opts_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_opts_bindings.dart';
|
||||||
import 'package:path/path.dart' as path;
|
import 'package:path/path.dart' as path;
|
||||||
import 'package:pub_semver/pub_semver.dart';
|
import 'package:pub_cache/pub_cache.dart';
|
||||||
|
|
||||||
const libgit2Version = '1.5.0';
|
const libgit2Version = '1.5.0';
|
||||||
final libDir = path.join('.dart_tool', 'libgit2');
|
final libDir = path.join('.dart_tool', 'libgit2');
|
||||||
|
@ -26,20 +25,6 @@ String getLibName() {
|
||||||
return 'libgit2-$libgit2Version.$ext';
|
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].
|
/// Checks if [File]/[Link] exists for [path].
|
||||||
bool _doesFileExist(String path) {
|
bool _doesFileExist(String path) {
|
||||||
return File(path).existsSync() || Link(path).existsSync();
|
return File(path).existsSync() || Link(path).existsSync();
|
||||||
|
@ -68,22 +53,18 @@ String? _resolveLibPath(String name) {
|
||||||
libPath = path.join(path.dirname(Platform.resolvedExecutable), 'lib', name);
|
libPath = path.join(path.dirname(Platform.resolvedExecutable), 'lib', name);
|
||||||
if (_doesFileExist(libPath)) return libPath;
|
if (_doesFileExist(libPath)) return libPath;
|
||||||
|
|
||||||
// If lib is installed in system dir.
|
String checkCache(PubCache pubCache) {
|
||||||
if (Platform.isMacOS || Platform.isLinux) {
|
final pubCacheDir =
|
||||||
final paths = [
|
pubCache.getLatestVersion('libgit2dart')!.resolve()!.location;
|
||||||
'/usr/local/lib/libgit2.$libgit2Version.dylib',
|
return path.join(pubCacheDir.path, Platform.operatingSystem, name);
|
||||||
'/usr/local/lib/libgit2.so.$libgit2Version',
|
|
||||||
'/usr/lib64/libgit2.so.$libgit2Version'
|
|
||||||
];
|
|
||||||
for (final path in paths) {
|
|
||||||
if (_doesFileExist(path)) return path;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If lib is in '.pub_cache' folder.
|
// If lib is in Flutter's '.pub_cache' folder.
|
||||||
final cachedLocation = checkCache();
|
final env = Platform.environment;
|
||||||
if (cachedLocation != null) {
|
if (env.containsKey('FLUTTER_ROOT')) {
|
||||||
libPath = path.join(cachedLocation, Platform.operatingSystem, name);
|
final flutterPubCache =
|
||||||
|
PubCache(Directory(path.join(env['FLUTTER_ROOT']!, '.pub-cache')));
|
||||||
|
libPath = checkCache(flutterPubCache);
|
||||||
if (_doesFileExist(libPath)) return libPath;
|
if (_doesFileExist(libPath)) return libPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#
|
#
|
||||||
Pod::Spec.new do |s|
|
Pod::Spec.new do |s|
|
||||||
s.name = 'libgit2dart'
|
s.name = 'libgit2dart'
|
||||||
s.version = '1.2.2'
|
s.version = '1.2.0'
|
||||||
s.summary = 'Dart bindings to libgit2.'
|
s.summary = 'Dart bindings to libgit2.'
|
||||||
s.description = <<-DESC
|
s.description = <<-DESC
|
||||||
Dart bindings to libgit2.
|
Dart bindings to libgit2.
|
||||||
|
|
|
@ -2,13 +2,13 @@ name: libgit2dart
|
||||||
|
|
||||||
description: Dart bindings to libgit2, provides ability to use libgit2 library in Dart and Flutter.
|
description: Dart bindings to libgit2, provides ability to use libgit2 library in Dart and Flutter.
|
||||||
|
|
||||||
version: 1.2.2
|
version: 1.2.0
|
||||||
|
|
||||||
homepage: https://github.com/SkinnyMind/libgit2dart
|
homepage: https://github.com/SkinnyMind/libgit2dart
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ">=2.18.0 <3.0.0"
|
sdk: ">=2.17.0 <3.0.0"
|
||||||
flutter: ">=3.3.0"
|
flutter: ">=3.0.0"
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
args: ^2.3.0
|
args: ^2.3.0
|
||||||
|
@ -16,7 +16,7 @@ dependencies:
|
||||||
ffi: ^2.0.0
|
ffi: ^2.0.0
|
||||||
meta: ^1.7.0
|
meta: ^1.7.0
|
||||||
path: ^1.8.1
|
path: ^1.8.1
|
||||||
pub_semver: ^2.1.3
|
pub_cache: ^0.3.1
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
ffigen: ^6.0.1
|
ffigen: ^6.0.1
|
||||||
|
|
|
@ -83,7 +83,10 @@ void main() {
|
||||||
cloneDir.deleteSync(recursive: true);
|
cloneDir.deleteSync(recursive: true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('clones repository with provided keypair', () {
|
test(
|
||||||
|
testOn: '!linux',
|
||||||
|
'clones repository with provided keypair',
|
||||||
|
() {
|
||||||
final cloneDir = Directory.systemTemp.createTempSync('clone');
|
final cloneDir = Directory.systemTemp.createTempSync('clone');
|
||||||
final keypair = Keypair(
|
final keypair = Keypair(
|
||||||
username: 'git',
|
username: 'git',
|
||||||
|
@ -104,7 +107,8 @@ void main() {
|
||||||
if (Platform.isLinux || Platform.isMacOS) {
|
if (Platform.isLinux || Platform.isMacOS) {
|
||||||
cloneDir.deleteSync(recursive: true);
|
cloneDir.deleteSync(recursive: true);
|
||||||
}
|
}
|
||||||
});
|
},
|
||||||
|
);
|
||||||
|
|
||||||
test('throws when no credentials is provided', () {
|
test('throws when no credentials is provided', () {
|
||||||
final cloneDir = Directory.systemTemp.createTempSync('clone');
|
final cloneDir = Directory.systemTemp.createTempSync('clone');
|
||||||
|
@ -185,7 +189,10 @@ void main() {
|
||||||
cloneDir.deleteSync(recursive: true);
|
cloneDir.deleteSync(recursive: true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('clones repository with provided keypair from memory', () {
|
test(
|
||||||
|
testOn: '!linux',
|
||||||
|
'clones repository with provided keypair from memory',
|
||||||
|
() {
|
||||||
final cloneDir = Directory.systemTemp.createTempSync('clone');
|
final cloneDir = Directory.systemTemp.createTempSync('clone');
|
||||||
final pubKey = File(p.join('test', 'assets', 'keys', 'id_rsa.pub'))
|
final pubKey = File(p.join('test', 'assets', 'keys', 'id_rsa.pub'))
|
||||||
.readAsStringSync();
|
.readAsStringSync();
|
||||||
|
@ -210,7 +217,8 @@ void main() {
|
||||||
if (Platform.isLinux || Platform.isMacOS) {
|
if (Platform.isLinux || Platform.isMacOS) {
|
||||||
cloneDir.deleteSync(recursive: true);
|
cloneDir.deleteSync(recursive: true);
|
||||||
}
|
}
|
||||||
});
|
},
|
||||||
|
);
|
||||||
|
|
||||||
test('throws when provided keypair from memory is incorrect', () {
|
test('throws when provided keypair from memory is incorrect', () {
|
||||||
final cloneDir = Directory.systemTemp.createTempSync('clone');
|
final cloneDir = Directory.systemTemp.createTempSync('clone');
|
||||||
|
|
|
@ -278,7 +278,7 @@ void main() {
|
||||||
expect(refs.first.localId, null);
|
expect(refs.first.localId, null);
|
||||||
expect(refs.first.name, 'HEAD');
|
expect(refs.first.name, 'HEAD');
|
||||||
expect(refs.first.symRef, 'refs/heads/master');
|
expect(refs.first.symRef, 'refs/heads/master');
|
||||||
expect(refs.first.oid.sha, '49322bb17d3acc9146f98c97d078513228bbf3c0');
|
expect((refs.first.oid).sha, '49322bb17d3acc9146f98c97d078513228bbf3c0');
|
||||||
expect(refs.first.toString(), contains('RemoteReference{'));
|
expect(refs.first.toString(), contains('RemoteReference{'));
|
||||||
expect(refs.first, remote.ls().first);
|
expect(refs.first, remote.ls().first);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue