mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-04 20:29:08 -04:00
feat(reference): add ability to get log of reference
This commit is contained in:
parent
a97dcaa0d3
commit
58fa54f24a
5 changed files with 30 additions and 7 deletions
|
@ -43,12 +43,13 @@ String entryMessage(Pointer<git_reflog_entry> entry) {
|
|||
return result.cast<Utf8>().toDartString();
|
||||
}
|
||||
|
||||
/// Get the committer of this entry.
|
||||
Map<String, String> entryCommiter(Pointer<git_reflog_entry> entry) {
|
||||
/// Get the committer of this entry (name, email, seconds from epoch).
|
||||
Map<String, Object> entryCommiter(Pointer<git_reflog_entry> entry) {
|
||||
final result = libgit2.git_reflog_entry_committer(entry);
|
||||
var committer = <String, String>{};
|
||||
var committer = <String, Object>{};
|
||||
committer['name'] = result.ref.name.cast<Utf8>().toDartString();
|
||||
committer['email'] = result.ref.email.cast<Utf8>().toDartString();
|
||||
committer['when'] = result.ref.when.time;
|
||||
return committer;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ import 'dart:ffi';
|
|||
import 'bindings/libgit2_bindings.dart';
|
||||
import 'bindings/reference.dart' as bindings;
|
||||
import 'oid.dart';
|
||||
import 'reflog.dart';
|
||||
import 'util.dart';
|
||||
|
||||
enum ReferenceType { direct, symbolic }
|
||||
|
@ -145,6 +146,18 @@ class Reference {
|
|||
return bindings.hasLog(repo, name);
|
||||
}
|
||||
|
||||
/// Returns a list with entries of reference log.
|
||||
List<RefLogEntry> get log {
|
||||
final reflog = RefLog(this);
|
||||
var log = <RefLogEntry>[];
|
||||
|
||||
for (var i = 0; i < reflog.count; i++) {
|
||||
log.add(reflog.entryAt(i));
|
||||
}
|
||||
|
||||
return log;
|
||||
}
|
||||
|
||||
/// Checks if a reference is a local branch.
|
||||
bool get isBranch => bindings.isBranch(_refPointer);
|
||||
|
||||
|
|
|
@ -47,6 +47,6 @@ class RefLogEntry {
|
|||
/// Returns the log message.
|
||||
String get message => bindings.entryMessage(_entryPointer);
|
||||
|
||||
/// Returns the committer of this entry.
|
||||
Map<String, String> get committer => bindings.entryCommiter(_entryPointer);
|
||||
/// Returns the committer of this entry (name, email, seconds from epoch).
|
||||
Map<String, Object> get committer => bindings.entryCommiter(_entryPointer);
|
||||
}
|
||||
|
|
|
@ -82,7 +82,8 @@ void main() {
|
|||
final reflogEntry = reflog.entryAt(0);
|
||||
|
||||
expect(reflogEntry.message, 'log message');
|
||||
expect(reflogEntry.committer, {'name': 'name', 'email': 'email'});
|
||||
expect(reflogEntry.committer['name'], 'name');
|
||||
expect(reflogEntry.committer['email'], 'email');
|
||||
|
||||
reflog.free();
|
||||
ref.delete();
|
||||
|
@ -222,7 +223,8 @@ void main() {
|
|||
final reflogEntry = reflog.entryAt(0);
|
||||
|
||||
expect(reflogEntry.message, 'log message');
|
||||
expect(reflogEntry.committer, {'name': 'name', 'email': 'email'});
|
||||
expect(reflogEntry.committer['name'], 'name');
|
||||
expect(reflogEntry.committer['email'], 'email');
|
||||
|
||||
// set HEAD back to master
|
||||
repo
|
||||
|
@ -335,6 +337,12 @@ void main() {
|
|||
});
|
||||
});
|
||||
|
||||
test('returns log for reference', () {
|
||||
final ref = repo.getReference('refs/heads/master');
|
||||
expect(ref.log.last.message, 'commit (initial): init');
|
||||
ref.free();
|
||||
});
|
||||
|
||||
group('isValidName()', () {
|
||||
test('returns true for valid names', () {
|
||||
expect(Reference.isValidName('HEAD'), true);
|
||||
|
|
|
@ -51,6 +51,7 @@ void main() {
|
|||
final entry = reflog.entryAt(0);
|
||||
expect(entry.committer['name'], 'Aleksey Kulikov');
|
||||
expect(entry.committer['email'], 'skinny.mind@gmail.com');
|
||||
expect(entry.committer['when'], 1626091184);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue