Ggit.Ref

g GObject.Object GObject.Object Ggit.ObjectFactoryBase Ggit.ObjectFactoryBase GObject.Object->Ggit.ObjectFactoryBase Ggit.Native Ggit.Native Ggit.Ref Ggit.Ref Ggit.Native->Ggit.Ref Ggit.ObjectFactoryBase->Ggit.Native

Subclasses:

Ggit.Branch

Methods

Inherited:

GObject.Object (37)

Structs:

GObject.ObjectClass (5)

class

is_valid_name (name)

delete ()

delete_log ()

get_log ()

get_name ()

get_owner ()

get_reference_type ()

get_shorthand ()

get_symbolic_target ()

get_target ()

has_log ()

is_branch ()

is_note ()

is_remote ()

is_tag ()

lookup ()

rename (new_name, force, log_message)

resolve ()

set_symbolic_target (target, log_message)

set_target (oid, log_message)

to_string ()

Virtual Methods

Inherited:

GObject.Object (7)

Properties

Inherited:

Ggit.Native (1)

Signals

Inherited:

GObject.Object (1)

Fields

Inherited:

GObject.Object (1)

Name

Type

Access

Description

parent_instance

Ggit.Native

r

Class Details

class Ggit.Ref(**kwargs)
Bases:

Ggit.Native

Abstract:

No

Structure:

Ggit.RefClass

Reprensents a git reference.

classmethod is_valid_name(name)
Parameters:

name (str) – the name to validate.

Returns:

True if name is valid, False otherwise.

Return type:

bool

Check if the given name is a valid name for a reference. Note that name should be the full ref name (including prefixes).

Valid toplevel names can contain only capital letters and underscores and must start and end with a letter (e.g. HEAD, ORIG_HEAD).

Valid refs/ names may contain any characters, except ‘~’, ‘^’, ‘:’, ‘\’, ‘?’, ‘[’, ‘*’, “..” and “@{”, because they are interpreted by revparse.

delete()
Raises:

GLib.Error

Deletes self.

This method works for both direct and symbolic references.

The reference will be immediately removed on disk and from memory. The given reference pointer will no longer be valid.

delete_log()
Raises:

GLib.Error

Deletes the log for self, on error error is set.

get_log()
Raises:

GLib.Error

Returns:

the reflog or None.

Return type:

Ggit.Reflog or None

Gets the Ggit.Reflog for self. The reflog will be created if it doesn’t exist yet.

get_name()
Returns:

the full name of a reference or None.

Return type:

str or None

Gets the full name of self.

get_owner()
Returns:

the repository where a reference resides or None.

Return type:

Ggit.Repository or None

Gets the repository where self resides.

get_reference_type()
Returns:

the type of a reference.

Return type:

Ggit.RefType

Gets the type of self. Either direct (Ggit.RefType.OID) or symbolic (Ggit.RefType.SYMBOLIC).

get_shorthand()
Returns:

the shorthand name of a reference or None.

Return type:

str or None

Gets the shorthand name of self.

get_symbolic_target()
Returns:

the name if available, None otherwise.

Return type:

str or None

Get full name to the reference pointed to by a symbolic reference. Only available if the reference is symbolic.

get_target()
Returns:

a new oid if available, None otherwise.

Return type:

Ggit.OId or None

Get the OID pointed to by a direct reference. Only available if the reference is direct (i.e. an object id reference, not a symbolic one).

has_log()
Returns:

True if self has a log, False otherwise.

Return type:

bool

Get whether self has an existing log.

is_branch()
Returns:

True if the reference is a branch, False otherwise.

Return type:

bool

Check whether the reference is a branch.

is_note()
Returns:

True if the reference is a note, False otherwise.

Return type:

bool

Check whether the reference is a note.

is_remote()
Returns:

True if the reference is a remote, False otherwise.

Return type:

bool

Check whether the reference is a remote.

is_tag()
Returns:

True if the reference is a tag, False otherwise.

Return type:

bool

Check whether the reference is a tag.

lookup()
Raises:

GLib.Error

Returns:

a Ggit.Object or None.

Return type:

Ggit.Object or None

Convenient method to resolve a reference to an object.

rename(new_name, force, log_message)
Parameters:
  • new_name (str) – the new name.

  • force (bool) – True to force the renaming.

  • log_message (str) – The one line long message to be appended to the reflog.

Raises:

GLib.Error

Returns:

a newly created Ggit.Ref or None.

Return type:

Ggit.Ref or None

Rename an existing reference.

This method works for both direct and symbolic references.

The new name will be checked for validity. See ggit_ref_create_symbolic() for rules about valid names.

If not error, self will be deleted from disk and a new Ggit.Ref will be returned.

The reference will be immediately renamed in-memory and on disk.

If the force flag is not enabled, and there’s already a reference with the given name, the renaming will fail.

IMPORTANT: The user needs to write a proper reflog entry if the reflog is enabled for the repository. We only rename the reflog if it exists.

resolve()
Raises:

GLib.Error

Returns:

the resolved reference to the peeled one or None.

Return type:

Ggit.Ref or None

Resolves a symbolic reference.

This method iteratively peels a symbolic reference until it resolves to a direct reference to an OID.

If a direct reference is passed as an argument, that reference is returned immediately.

set_symbolic_target(target, log_message)
Parameters:
  • target (str) – The new target for the reference.

  • log_message (str or None) – The one line long message to be appended to the reflog.

Raises:

GLib.Error

Returns:

the newly created Ggit.Ref or None.

Return type:

Ggit.Ref or None

Create a new reference with the same name as the given reference but a different symbolic target. The reference must be a symbolic reference, otherwise this will fail.

The new reference will be written to disk, overwriting the given reference.

The target name will be checked for validity. See ggit_ref_create_symbolic() for rules about valid names.

set_target(oid, log_message)
Parameters:
  • oid (Ggit.OId) – a Ggit.OId.

  • log_message (str or None) – The one line long message to be appended to the reflog.

Raises:

GLib.Error

Returns:

the newly created Ggit.Ref or None.

Return type:

Ggit.Ref or None

Create a new reference with the same name as the given reference but a different OID target. The reference must be a direct reference, otherwise this will fail.

The new reference will be written to disk, overwriting the given reference.

to_string()
Returns:

a string representation of the ref or None.

Return type:

str or None

Get a string representation of the ref.