summaryrefslogtreecommitdiff
path: root/lib/git/repo.py
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2009-11-05 21:20:10 +0100
committerSebastian Thiel <byronimo@gmail.com>2009-11-05 21:20:10 +0100
commit555b0efc2c19aa8cf7c548b4097bd20a73f572ca (patch)
treebfbd4bcfc294bda8d65ca0774d4ad2b871f3cf03 /lib/git/repo.py
parent4e99d9ab2acfaf2ebb4b150736590d6a4e33f449 (diff)
downloadgitpython-555b0efc2c19aa8cf7c548b4097bd20a73f572ca.tar.gz
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 )
Diffstat (limited to 'lib/git/repo.py')
-rw-r--r--lib/git/repo.py33
1 files changed, 32 insertions, 1 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)