summaryrefslogtreecommitdiff
path: root/lib/git/cmd.py
diff options
context:
space:
mode:
authorSverre Rabbelier <sverre@rabbelier.nl>2008-06-13 20:10:01 +0200
committerSverre Rabbelier <sverre@rabbelier.nl>2008-06-13 20:39:52 +0200
commit0aa1ce356c7c3d53d6ee035b4c7bcf425e108cdc (patch)
tree7877832dcef94e5361aed2fc2ad766df821ba390 /lib/git/cmd.py
parentb38020ae17ed9f83af75ce176e96267dcce6ecbd (diff)
downloadgitpython-0aa1ce356c7c3d53d6ee035b4c7bcf425e108cdc.tar.gz
Added a with_keep_cwd option
When executing commands, if the with_keep_cwd option is specified, the current working directory will be set to os.getcwd() instead of the directory containing the .git directory.
Diffstat (limited to 'lib/git/cmd.py')
-rw-r--r--lib/git/cmd.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/lib/git/cmd.py b/lib/git/cmd.py
index 1eed1f84..8a3de181 100644
--- a/lib/git/cmd.py
+++ b/lib/git/cmd.py
@@ -56,6 +56,7 @@ class Git(MethodMissingMixin):
with_stderr=False,
with_exceptions=False,
with_raw_output=False,
+ with_keep_cwd=False,
):
"""
Handles executing the command on the shell and consumes and returns
@@ -79,6 +80,9 @@ class Git(MethodMissingMixin):
``with_raw_output``
Whether to avoid stripping off trailing whitespace.
+ ``with_keep_cwd``
+ Whether to use the current working directory from os.getcwd().
+
Returns
str(output) # with_status = False (Default)
tuple(int(status), str(output)) # with_status = True
@@ -94,9 +98,15 @@ class Git(MethodMissingMixin):
else:
stderr = subprocess.PIPE
+ # Allow the user to have the command executed in their working dir.
+ if with_keep_cwd:
+ cwd = os.getcwd()
+ else:
+ cwd=self.git_dir
+
# Start the process
proc = subprocess.Popen(command,
- cwd=self.git_dir,
+ cwd=cwd,
stdin=istream,
stderr=stderr,
stdout=subprocess.PIPE
@@ -183,6 +193,7 @@ class Git(MethodMissingMixin):
with_stderr = kwargs.pop("with_stderr", None)
with_exceptions = kwargs.pop("with_exceptions", None)
with_raw_output = kwargs.pop("with_raw_output", None)
+ with_keep_cwd = kwargs.pop("with_keep_cwd", None)
# Prepare the argument list
opt_args = self.transform_kwargs(**kwargs)
@@ -198,4 +209,5 @@ class Git(MethodMissingMixin):
with_stderr = with_stderr,
with_exceptions = with_exceptions,
with_raw_output = with_raw_output,
+ with_keep_cwd = with_keep_cwd,
)