MCPcopy Create free account
hub / github.com/libgit2/pygit2 / set_target

Method set_target

pygit2/transaction.py:88–124  ·  view source on GitHub ↗

Set the target of a direct reference. The reference must be locked first via lock_ref(). Args: refname: Name of the reference to update target: Target OID or hex string signature: Signature for the reflog (None to use repo identity) m

(
        self,
        refname: str,
        target: Oid | str,
        signature: Signature | None = None,
        message: str | None = None,
    )

Source from the content-addressed store, hash-verified

86 check_error(err)
87
88 def set_target(
89 self,
90 refname: str,
91 target: Oid | str,
92 signature: Signature | None = None,
93 message: str | None = None,
94 ) -> None:
95 """Set the target of a direct reference.
96
97 The reference must be locked first via lock_ref().
98
99 Args:
100 refname: Name of the reference to update
101 target: Target OID or hex string
102 signature: Signature for the reflog (None to use repo identity)
103 message: Message for the reflog
104 """
105 self._check_thread()
106 if self._tx is None:
107 raise ValueError('Transaction already closed')
108
109 from ._pygit2 import Oid
110
111 c_refname = ffi.new('char[]', to_bytes(refname))
112
113 # Convert target to OID
114 if isinstance(target, str):
115 target = Oid(hex=target)
116
117 c_oid = ffi.new('git_oid *')
118 ffi.buffer(c_oid)[:] = target.raw
119
120 c_sig = signature._pointer if signature else ffi.NULL
121 c_msg = ffi.new('char[]', to_bytes(message)) if message else ffi.NULL
122
123 err = C.git_transaction_set_target(self._tx, c_refname, c_oid, c_sig, c_msg)
124 check_error(err)
125
126 def set_symbolic_target(
127 self,

Calls 3

_check_threadMethod · 0.95
to_bytesFunction · 0.85
check_errorFunction · 0.85