Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def favor_to_enum(favor):
if favor == 'normal':
return C.GIT_MERGE_FILE_FAVOR_NORMAL
elif favor == 'ours':
return C.GIT_MERGE_FILE_FAVOR_OURS
elif favor == 'theirs':
return C.GIT_MERGE_FILE_FAVOR_THEIRS
elif favor == 'union':
return C.GIT_MERGE_FILE_FAVOR_UNION
else:
return None
def __del__(self):
if not self.from_iterator:
C.git_config_entry_free(self._entry)
def __del__(self):
C.git_config_iterator_free(self._iter)
def set_head(self, target):
"""
Set HEAD to point to the given target.
Parameters:
target
The new target for HEAD. Can be a string or Oid (to detach).
"""
if isinstance(target, Oid):
oid = ffi.new('git_oid *')
ffi.buffer(oid)[:] = target.raw[:]
err = C.git_repository_set_head_detached(self._repo, oid)
check_error(err)
return
# if it's a string, then it's a reference name
err = C.git_repository_set_head(self._repo, to_bytes(target))
check_error(err)
def get_xdg_config():
"""Return a object representing the global configuration file.
"""
return Config._from_found_config(C.git_config_find_xdg)
# This file is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; see the file COPYING. If not, write to
# the Free Software Foundation, 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301, USA.
# Import from pygit2
from .ffi import ffi, C
from _pygit2 import GitError
value_errors = set([C.GIT_EEXISTS, C.GIT_EINVALIDSPEC, C.GIT_EAMBIGUOUS])
def check_error(err, io=False):
if err >= 0:
return
# Error message
giterr = C.git_error_last()
if giterr != ffi.NULL:
message = ffi.string(giterr.message).decode('utf8')
else:
message = "err %d (no message provided)" % err
# Translate to Python errors
if err in value_errors:
raise ValueError(message)
def fetch(self, refspecs=None, message=None, callbacks=None, prune=C.GIT_FETCH_PRUNE_UNSPECIFIED):
"""Perform a fetch against this remote. Returns a
object.
Parameters:
prune : enum
Either , , or
. The first uses the configuration from the
repo, the second will remove any remote branch in the local
repository that does not exist in the remote and the last will
always keep the remote branches
"""
fetch_opts = ffi.new('git_fetch_options *')
err = C.git_fetch_init_options(fetch_opts, C.GIT_FETCH_OPTIONS_VERSION)
def open(self):
"""Open the repository for a submodule."""
crepo = ffi.new('git_repository **')
err = C.git_submodule_open(crepo, self._subm)
check_error(err)
return self._repo._from_c(crepo[0], True)
Push the given refspec to the remote. Raises ``GitError`` on protocol
error or unpack failure.
When the remote has a githook installed, that denies the reference this
function will return successfully. Thus it is strongly recommended to
install a callback, that implements
:py:meth:`RemoteCallbacks.push_update_reference` and check the passed
parameters for successfull operations.
Parameters:
specs : [str]
Push refspecs to use.
"""
push_opts = ffi.new('git_push_options *')
err = C.git_push_init_options(push_opts, C.GIT_PUSH_OPTIONS_VERSION)
if callbacks is None:
callbacks = RemoteCallbacks()
callbacks._fill_push_options(push_opts)
# Build custom callback structure
try:
with StrArray(specs) as refspecs:
err = C.git_remote_push(self._remote, refspecs, push_opts)
check_error(err)
finally:
callbacks._self_handle = None