|
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) |
|
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.
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.