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

Skip to content

Commit 555b0ef

Browse files
committed
repo.clone: Added plenty of special handling to allow drive letters to work as expected. Its quite terrible to see a two-line method inflate to 20
as there is no git-daemon on windows, some tests will not work. The error message has been adjusted to be more precise for the poor people trying to run the tests on windows ( including myself )
1 parent 4e99d9a commit 555b0ef

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

lib/git/repo.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,38 @@ def clone(self, path, **kwargs):
674674
Returns
675675
``git.Repo`` (the newly cloned repo)
676676
"""
677-
self.git.clone(self.path, path, **kwargs)
677+
# special handling for windows for path at which the clone should be
678+
# created.
679+
# tilde '~' will be expanded to the HOME no matter where the ~ occours. Hence
680+
# we at least give a proper error instead of letting git fail
681+
prev_cwd = None
682+
prev_path = None
683+
if os.name == 'nt':
684+
if '~' in path:
685+
raise OSError("Git cannot handle the ~ character in path %r correctly" % path)
686+
687+
# on windows, git will think paths like c: are relative and prepend the
688+
# current working dir ( before it fails ). We temporarily adjust the working
689+
# dir to make this actually work
690+
match = re.match("(\w:[/\\\])(.*)", path)
691+
if match:
692+
prev_cwd = os.getcwd()
693+
prev_path = path
694+
drive, rest_of_path = match.groups()
695+
os.chdir(drive)
696+
path = rest_of_path
697+
kwargs['with_keep_cwd'] = True
698+
# END cwd preparation
699+
# END windows handling
700+
701+
try:
702+
self.git.clone(self.path, path, **kwargs)
703+
finally:
704+
if prev_cwd is not None:
705+
os.chdir(prev_cwd)
706+
path = prev_path
707+
# END reset previous working dir
708+
# END bad windows handling
678709
return Repo(path)
679710

680711

test/testlib/helper.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,10 @@ def remote_repo_creator(self):
176176
rw_repo.git.ls_remote(d_remote)
177177
except GitCommandError,e:
178178
print str(e)
179-
raise AssertionError('Please start a git-daemon to run this test, execute: git-daemon "%s"'%tempfile.gettempdir())
179+
if os.name == 'nt':
180+
raise AssertionError('git-daemon needs to run this test, but windows does not have one. Otherwise, run: git-daemon "%s"'%tempfile.gettempdir())
181+
else:
182+
raise AssertionError('Please start a git-daemon to run this test, execute: git-daemon "%s"'%tempfile.gettempdir())
180183

181184
try:
182185
return func(self, rw_repo, rw_remote_repo)

0 commit comments

Comments
 (0)