Skip to content

Commit cf37099

Browse files
committed
use shell=True in windows (git.exe needs to be on %PATH%)
One bug remaining: git on windows is returning status 0 for `git this-does-not-exist`, so no GitCommandError is raised.
1 parent bfdc8e2 commit cf37099

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

‎lib/git/cmd.py‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
# cmd.py
1+
# cmd.py
22
# Copyright (C) 2008 Michael Trier ([email protected]) and contributors
33
#
44
# This module is part of GitPython and is released under
55
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
66

7-
importos
7+
importos, sys
88
importsubprocess
99
importre
1010
fromutilsimport*
@@ -16,6 +16,10 @@
1616
execute_kwargs= ('istream', 'with_keep_cwd', 'with_extended_output',
1717
'with_exceptions', 'with_raw_output')
1818

19+
extra={}
20+
ifsys.platform=='win32':
21+
extra={'shell': True}
22+
1923
classGit(object):
2024
"""
2125
The Git class manages communication with the Git binary
@@ -83,7 +87,8 @@ def execute(self, command,
8387
cwd=cwd,
8488
stdin=istream,
8589
stderr=subprocess.PIPE,
86-
stdout=subprocess.PIPE
90+
stdout=subprocess.PIPE,
91+
**extra
8792
)
8893

8994
# Wait for the process to return

‎test/git/test_git.py‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# This module is part of GitPython and is released under
55
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
66

7-
importos
7+
importos, sys
88
fromtest.testlibimport*
99
fromgitimportGit, GitCommandError
1010

@@ -45,7 +45,10 @@ def test_it_accepts_stdin(self):
4545
fh.close()
4646

4747
deftest_it_handles_large_input(self):
48-
output=self.git.execute(["cat", "/bin/bash"])
48+
ifsys.platform=='win32':
49+
output=self.git.execute(["type", "C:\WINDOWS\system32\cmd.exe"])
50+
else:
51+
output=self.git.execute(["cat", "/bin/bash"])
4952
assert_true(len(output) >4096) # at least 4k
5053

5154
@patch(Git, 'execute')

‎test/git/test_repo.py‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# This module is part of GitPython and is released under
55
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
66

7-
importos
7+
importos, sys
88
importtime
99
fromtest.testlibimport*
1010
fromgitimport*
@@ -15,7 +15,10 @@ def setup(self):
1515

1616
@raises(InvalidGitRepositoryError)
1717
deftest_new_should_raise_on_invalid_repo_location(self):
18-
Repo("/tmp")
18+
ifsys.platform=="win32":
19+
Repo("C:\\WINDOWS\\Temp")
20+
else:
21+
Repo("/tmp")
1922

2023
@raises(NoSuchPathError)
2124
deftest_new_should_raise_on_non_existant_path(self):
@@ -141,7 +144,8 @@ def test_fork_bare(self, repo, git):
141144
self.repo.fork_bare("repos/foo/bar.git")
142145

143146
assert_true(git.called)
144-
assert_equal(git.call_args, (('clone', '%s/.git'%absolute_project_path(), 'repos/foo/bar.git'),{'bare': True}))
147+
path=os.path.join(absolute_project_path(), '.git')
148+
assert_equal(git.call_args, (('clone', path, 'repos/foo/bar.git'),{'bare': True}))
145149
assert_true(repo.called)
146150

147151
@patch(Repo, '__init__')
@@ -152,7 +156,8 @@ def test_fork_bare_with_options(self, repo, git):
152156
self.repo.fork_bare("repos/foo/bar.git", **{'template': '/awesome'})
153157

154158
assert_true(git.called)
155-
assert_equal(git.call_args, (('clone', '%s/.git'%absolute_project_path(), 'repos/foo/bar.git'),
159+
path=os.path.join(absolute_project_path(), '.git')
160+
assert_equal(git.call_args, (('clone', path, 'repos/foo/bar.git'),
156161
{'bare': True, 'template': '/awesome'}))
157162
assert_true(repo.called)
158163

@@ -246,7 +251,8 @@ def test_alternates_setter_empty(self, os):
246251
assert_true(os.called)
247252

248253
deftest_repr(self):
249-
assert_equal('<GitPython.Repo "%s/.git">'%os.path.abspath(GIT_REPO), repr(self.repo))
254+
path=os.path.join(os.path.abspath(GIT_REPO), '.git')
255+
assert_equal('<GitPython.Repo "%s">'%path, repr(self.repo))
250256

251257
@patch(Git, '_call_process')
252258
deftest_log(self, git):

0 commit comments

Comments
(0)