OpenQuizz
Une application de gestion des contenus pédagogiques
Git Class Reference
Inheritance diagram for Git:
Collaboration diagram for Git:

Data Structures

class  AutoInterrupt
 
class  CatFileContentStream
 

Public Member Functions

def __getstate__ (self)
 
def __setstate__ (self, d)
 
def refresh (cls, path=None)
 
def is_cygwin (cls)
 
def polish_url (cls, url, is_cygwin=None)
 
def __init__ (self, working_dir=None)
 
def __getattr__ (self, name)
 
def set_persistent_git_options (self, **kwargs)
 
def working_dir (self)
 
def version_info (self)
 
def execute (self, command, istream=None, with_extended_output=False, with_exceptions=True, as_process=False, output_stream=None, stdout_as_string=True, kill_after_timeout=None, with_stdout=True, universal_newlines=False, shell=None, env=None, max_chunk_size=io.DEFAULT_BUFFER_SIZE, **subprocess_kwargs)
 
def environment (self)
 
def update_environment (self, **kwargs)
 
def custom_environment (self, **kwargs)
 
def transform_kwarg (self, name, value, split_single_char_options)
 
def transform_kwargs (self, split_single_char_options=True, **kwargs)
 
def __call__ (self, **kwargs)
 
def get_object_header (self, ref)
 
def get_object_data (self, ref)
 
def stream_object_data (self, ref)
 
def clear_cache (self)
 

Data Fields

 cat_file_header
 
 cat_file_all
 

Static Public Attributes

 git_exec_name
 
 GIT_PYTHON_TRACE
 
 USE_SHELL
 
 GIT_PYTHON_GIT_EXECUTABLE
 

Detailed Description

The Git class manages communication with the Git binary.

It provides a convenient interface to calling the Git binary, such as in::

 g = Git( git_dir )
 g.init()                   # calls 'git init' program
 rval = g.ls_files()        # calls 'git ls-files' program

``Debugging``
    Set the GIT_PYTHON_TRACE environment variable print each invocation
    of the command to stdout.
    Set its value to 'full' to see details about the returned values.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  working_dir = None 
)
Initialize this instance with:

:param working_dir:
   Git directory we should work in. If None, we always work in the current
   directory as returned by os.getcwd().
   It is meant to be the working tree directory if available, or the
   .git directory in case of bare repositories.

Member Function Documentation

◆ __call__()

def __call__ (   self,
**  kwargs 
)
Specify command line options to the git executable
for a subcommand call

:param kwargs:
    is a dict of keyword arguments.
    these arguments are passed as in _call_process
    but will be passed to the git command rather than
    the subcommand.

``Examples``::
    git(work_tree='/tmp').difftool()

◆ __getattr__()

def __getattr__ (   self,
  name 
)
A convenience method as it allows to call the command as if it was
an object.
:return: Callable object that will execute call _call_process with your arguments.

◆ __getstate__()

def __getstate__ (   self)

◆ __setstate__()

def __setstate__ (   self,
  d 
)

◆ clear_cache()

def clear_cache (   self)
Clear all kinds of internal caches to release resources.

Currently persistent commands will be interrupted.

:return: self

◆ custom_environment()

def custom_environment (   self,
**  kwargs 
)
A context manager around the above ``update_environment`` method to restore the
environment back to its previous state after operation.

``Examples``::

    with self.custom_environment(GIT_SSH='/bin/ssh_wrapper'):
repo.remotes.origin.fetch()

:param kwargs: see update_environment

◆ environment()

def environment (   self)

◆ execute()

def execute (   self,
  command,
  istream = None,
  with_extended_output = False,
  with_exceptions = True,
  as_process = False,
  output_stream = None,
  stdout_as_string = True,
  kill_after_timeout = None,
  with_stdout = True,
  universal_newlines = False,
  shell = None,
  env = None,
  max_chunk_size = io.DEFAULT_BUFFER_SIZE,
**  subprocess_kwargs 
)
Handles executing the command on the shell and consumes and returns
the returned information (stdout)

:param command:
    The command argument list to execute.
    It should be a string, or a sequence of program arguments. The
    program to execute is the first item in the args sequence or string.

:param istream:
    Standard input filehandle passed to subprocess.Popen.

:param with_extended_output:
    Whether to return a (status, stdout, stderr) tuple.

:param with_exceptions:
    Whether to raise an exception when git returns a non-zero status.

:param as_process:
    Whether to return the created process instance directly from which
    streams can be read on demand. This will render with_extended_output and
    with_exceptions ineffective - the caller will have
    to deal with the details himself.
    It is important to note that the process will be placed into an AutoInterrupt
    wrapper that will interrupt the process once it goes out of scope. If you
    use the command in iterators, you should pass the whole process instance
    instead of a single stream.

:param output_stream:
    If set to a file-like object, data produced by the git command will be
    output to the given stream directly.
    This feature only has any effect if as_process is False. Processes will
    always be created with a pipe due to issues with subprocess.
    This merely is a workaround as data will be copied from the
    output pipe to the given output stream directly.
    Judging from the implementation, you shouldn't use this flag !

:param stdout_as_string:
    if False, the commands standard output will be bytes. Otherwise, it will be
    decoded into a string using the default encoding (usually utf-8).
    The latter can fail, if the output contains binary data.

:param env:
    A dictionary of environment variables to be passed to `subprocess.Popen`.
    
:param max_chunk_size:
    Maximum number of bytes in one chunk of data passed to the output_stream in
    one invocation of write() method. If the given number is not positive then
    the default value is used.

:param subprocess_kwargs:
    Keyword arguments to be passed to subprocess.Popen. Please note that
    some of the valid kwargs are already set by this method, the ones you
    specify may not be the same ones.

:param with_stdout: If True, default True, we open stdout on the created process
:param universal_newlines:
    if True, pipes will be opened as text, and lines are split at
    all known line endings.
:param shell:
    Whether to invoke commands through a shell (see `Popen(..., shell=True)`).
    It overrides :attr:`USE_SHELL` if it is not `None`.
:param kill_after_timeout:
    To specify a timeout in seconds for the git command, after which the process
    should be killed. This will have no effect if as_process is set to True. It is
    set to None by default and will let the process run until the timeout is
    explicitly specified. This feature is not supported on Windows. It's also worth
    noting that kill_after_timeout uses SIGKILL, which can have negative side
    effects on a repository. For example, stale locks in case of git gc could
    render the repository incapable of accepting changes until the lock is manually
    removed.

:return:
    * str(output) if extended_output = False (Default)
    * tuple(int(status), str(stdout), str(stderr)) if extended_output = True

    if output_stream is True, the stdout value will be your output stream:
    * output_stream if extended_output = False
    * tuple(int(status), output_stream, str(stderr)) if extended_output = True

    Note git is executed with LC_MESSAGES="C" to ensure consistent
    output regardless of system language.

:raise GitCommandError:

:note:
   If you add additional keyword arguments to the signature of this method,
   you must update the execute_kwargs tuple housed in this module.

◆ get_object_data()

def get_object_data (   self,
  ref 
)
As get_object_header, but returns object data as well
:return: (hexsha, type_string, size_as_int,data_string)
:note: not threadsafe

◆ get_object_header()

def get_object_header (   self,
  ref 
)
Use this method to quickly examine the type and size of the object behind
the given ref.

:note: The method will only suffer from the costs of command invocation
    once and reuses the command in subsequent calls.

:return: (hexsha, type_string, size_as_int)

◆ is_cygwin()

def is_cygwin (   cls)

◆ polish_url()

def polish_url (   cls,
  url,
  is_cygwin = None 
)

◆ refresh()

def refresh (   cls,
  path = None 
)
This gets called by the refresh function (see the top level
__init__).

◆ set_persistent_git_options()

def set_persistent_git_options (   self,
**  kwargs 
)
Specify command line options to the git executable
for subsequent subcommand calls

:param kwargs:
    is a dict of keyword arguments.
    these arguments are passed as in _call_process
    but will be passed to the git command rather than
    the subcommand.

◆ stream_object_data()

def stream_object_data (   self,
  ref 
)
As get_object_header, but returns the data as a stream

:return: (hexsha, type_string, size_as_int, stream)
:note: This method is not threadsafe, you need one independent Command instance per thread to be safe !

◆ transform_kwarg()

def transform_kwarg (   self,
  name,
  value,
  split_single_char_options 
)

◆ transform_kwargs()

def transform_kwargs (   self,
  split_single_char_options = True,
**  kwargs 
)
Transforms Python style kwargs into git command line options.

◆ update_environment()

def update_environment (   self,
**  kwargs 
)
Set environment variables for future git invocations. Return all changed
values in a format that can be passed back into this function to revert
the changes:

``Examples``::

    old_env = self.update_environment(PWD='/tmp')
    self.update_environment(**old_env)

:param kwargs: environment variables to use for git processes
:return: dict that maps environment variables to their old values

◆ version_info()

def version_info (   self)
:return: tuple(int, int, int, int) tuple with integers representing the major, minor
    and additional version numbers as parsed from git version.
    This value is generated on demand and is cached

◆ working_dir()

def working_dir (   self)
:return: Git directory we are working on

Field Documentation

◆ cat_file_all

cat_file_all

◆ cat_file_header

cat_file_header

◆ git_exec_name

git_exec_name
static

◆ GIT_PYTHON_GIT_EXECUTABLE

GIT_PYTHON_GIT_EXECUTABLE
static

◆ GIT_PYTHON_TRACE

GIT_PYTHON_TRACE
static

◆ USE_SHELL

USE_SHELL
static

The documentation for this class was generated from the following file: