summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/git/repo.py33
-rw-r--r--test/testlib/helper.py5
2 files changed, 36 insertions, 2 deletions
diff --git a/lib/git/repo.py b/lib/git/repo.py
index 6d388633..d39f11d1 100644
--- a/lib/git/repo.py
+++ b/lib/git/repo.py
@@ -674,7 +674,38 @@ class Repo(object):
Returns
``git.Repo`` (the newly cloned repo)
"""
- self.git.clone(self.path, path, **kwargs)
+ # special handling for windows for path at which the clone should be
+ # created.
+ # tilde '~' will be expanded to the HOME no matter where the ~ occours. Hence
+ # we at least give a proper error instead of letting git fail
+ prev_cwd = None
+ prev_path = None
+ if os.name == 'nt':
+ if '~' in path:
+ raise OSError("Git cannot handle the ~ character in path %r correctly" % path)
+
+ # on windows, git will think paths like c: are relative and prepend the
+ # current working dir ( before it fails ). We temporarily adjust the working
+ # dir to make this actually work
+ match = re.match("(\w:[/\\\])(.*)", path)
+ if match:
+ prev_cwd = os.getcwd()
+ prev_path = path
+ drive, rest_of_path = match.groups()
+ os.chdir(drive)
+ path = rest_of_path
+ kwargs['with_keep_cwd'] = True
+ # END cwd preparation
+ # END windows handling
+
+ try:
+ self.git.clone(self.path, path, **kwargs)
+ finally:
+ if prev_cwd is not None:
+ os.chdir(prev_cwd)
+ path = prev_path
+ # END reset previous working dir
+ # END bad windows handling
return Repo(path)
diff --git a/test/testlib/helper.py b/test/testlib/helper.py
index 5599f05e..e9a15d5c 100644
--- a/test/testlib/helper.py
+++ b/test/testlib/helper.py
@@ -176,7 +176,10 @@ def with_rw_and_rw_remote_repo(working_tree_ref):
rw_repo.git.ls_remote(d_remote)
except GitCommandError,e:
print str(e)
- raise AssertionError('Please start a git-daemon to run this test, execute: git-daemon "%s"'%tempfile.gettempdir())
+ if os.name == 'nt':
+ raise AssertionError('git-daemon needs to run this test, but windows does not have one. Otherwise, run: git-daemon "%s"'%tempfile.gettempdir())
+ else:
+ raise AssertionError('Please start a git-daemon to run this test, execute: git-daemon "%s"'%tempfile.gettempdir())
try:
return func(self, rw_repo, rw_remote_repo)