feat(reference): add ability to create symbolic reference

This commit is contained in:
Aleksey Kulikov 2021-08-06 11:53:13 +03:00
parent 2477b4efd8
commit a97dcaa0d3
5 changed files with 274 additions and 89 deletions

View file

@ -1,5 +1,4 @@
import 'dart:ffi';
import 'package:ffi/ffi.dart';
import 'bindings/libgit2_bindings.dart';
import 'bindings/reference.dart' as bindings;
import 'oid.dart';
@ -42,6 +41,39 @@ class Reference {
_refPointer = bindings.createDirect(repo, name, oid, force, logMessage);
}
/// Initializes a new instance of the [Reference] class by creating a new symbolic reference.
///
/// A symbolic reference is a reference name that refers to another reference name.
/// If the other name moves, the symbolic name will move, too. As a simple example,
/// the "HEAD" reference might refer to "refs/heads/master" while on the "master" branch
/// of a repository.
///
/// The symbolic reference will be created in the repository and written to the disk.
/// The generated reference object must be freed by the user.
///
/// Valid reference names must follow one of two patterns:
///
/// Top-level names must contain only capital letters and underscores, and must begin and end
/// with a letter. (e.g. "HEAD", "ORIG_HEAD").
/// Names prefixed with "refs/" can be almost anything. You must avoid the characters
/// '~', '^', ':', '\', '?', '[', and '*', and the sequences ".." and "@{" which have special
/// meaning to revparse.
/// This function will throw an [LibGit2Error] if a reference already exists with the given
/// name unless force is true, in which case it will be overwritten.
///
/// The message for the reflog will be ignored if the reference does not belong in the standard
/// set (HEAD, branches and remote-tracking branches) and it does not have a reflog.
Reference.createSymbolic({
required Pointer<git_repository> repo,
required String name,
required String target,
required bool force,
required String logMessage,
}) {
_refPointer =
bindings.createSymbolic(repo, name, target, force, logMessage);
}
/// Initializes a new instance of the [Reference] class by
/// lookingup a reference by [name] in a repository.
///