Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit abc2e53

Browse files
committed
cmd: properly handle cwd for repos with work trees
This is a fix on top of Govind's latest performance improvement. self._cwd was always set to self._git_dir which means a lot of commands that require work trees were not available to GitPython. Execute now uses self._cwd which is equal to self._git_dir by default, and self.get_work_tree() if a work tree exists. Signed-off-by: David Aguilar <[email protected]>
1 parent 52654c0 commit abc2e53

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

lib/git/cmd.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ def refresh(self):
2424
self._git_dir = None
2525
self._is_in_repo = not not self.get_git_dir()
2626
self._work_tree = None
27+
self._cwd = self._git_dir
28+
if self._git_dir:
29+
self._cwd = self.get_work_tree()
2730

2831
def _is_git_dir(self, d):
2932
""" This is taken from the git setup.c:is_git_directory
@@ -115,7 +118,7 @@ def execute(self, command,
115118

116119
# Start the process
117120
proc = subprocess.Popen(command,
118-
cwd=self._git_dir,
121+
cwd=self._cwd,
119122
stdin=istream,
120123
stderr=stderr,
121124
stdout=subprocess.PIPE

0 commit comments

Comments
 (0)