mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-05 04:39:07 -04:00
feat(reference): add ability to get shorthand name of reference
This commit is contained in:
parent
371d52b7f8
commit
a1884b4dac
3 changed files with 30 additions and 1 deletions
|
@ -73,6 +73,15 @@ String name(Pointer<git_reference> ref) {
|
||||||
return result.cast<Utf8>().toDartString();
|
return result.cast<Utf8>().toDartString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the reference's short name.
|
||||||
|
///
|
||||||
|
/// This will transform the reference name into a name "human-readable" version.
|
||||||
|
/// If no shortname is appropriate, it will return the full name.
|
||||||
|
String shorthand(Pointer<git_reference> ref) {
|
||||||
|
final result = libgit2.git_reference_shorthand(ref);
|
||||||
|
return result.cast<Utf8>().toDartString();
|
||||||
|
}
|
||||||
|
|
||||||
/// Fill a list with all the references that can be found in a repository.
|
/// Fill a list with all the references that can be found in a repository.
|
||||||
///
|
///
|
||||||
/// The string array will be filled with the names of all references;
|
/// The string array will be filled with the names of all references;
|
||||||
|
|
|
@ -165,6 +165,12 @@ class Reference {
|
||||||
/// Returns the full name of a reference.
|
/// Returns the full name of a reference.
|
||||||
String get name => bindings.name(_refPointer);
|
String get name => bindings.name(_refPointer);
|
||||||
|
|
||||||
|
/// Returns the reference's short name.
|
||||||
|
///
|
||||||
|
/// This will transform the reference name into a name "human-readable" version.
|
||||||
|
/// If no shortname is appropriate, it will return the full name.
|
||||||
|
String get shorthand => bindings.shorthand(_refPointer);
|
||||||
|
|
||||||
/// Returns a list with all the references that can be found in a repository.
|
/// Returns a list with all the references that can be found in a repository.
|
||||||
///
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
|
|
|
@ -272,11 +272,25 @@ void main() {
|
||||||
ref.free();
|
ref.free();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('returns the full name of a reference', () {
|
test('returns the full name', () {
|
||||||
expect(repo.head.name, 'refs/heads/master');
|
expect(repo.head.name, 'refs/heads/master');
|
||||||
repo.head.free();
|
repo.head.free();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('returns the short name', () {
|
||||||
|
final ref = repo.createReference(
|
||||||
|
name: 'refs/remotes/origin/master',
|
||||||
|
target: lastCommit,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(repo.head.shorthand, 'master');
|
||||||
|
expect(ref.shorthand, 'origin/master');
|
||||||
|
|
||||||
|
repo.head.free();
|
||||||
|
ref.delete();
|
||||||
|
ref.free();
|
||||||
|
});
|
||||||
|
|
||||||
test('returns a map with all the references of repository', () {
|
test('returns a map with all the references of repository', () {
|
||||||
expect(
|
expect(
|
||||||
repo.references,
|
repo.references,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue