summaryrefslogtreecommitdiff
path: root/git/repo/base.py
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2015-01-10 19:20:22 +0100
committerSebastian Thiel <byronimo@gmail.com>2015-01-10 19:20:22 +0100
commit6e8aa9b0aefc30ee5807c2b2cf433a38555b7e0b (patch)
tree21085a6a7f94d6362e995bd3fe1cb77e28be36ed /git/repo/base.py
parent96c6ab4f7572fd5ca8638f3cb6e342d5000955e7 (diff)
downloadgitpython-6e8aa9b0aefc30ee5807c2b2cf433a38555b7e0b.tar.gz
Repo.init() now supports paths with a '~' in it, or environment variables in general.
Fixes #83
Diffstat (limited to 'git/repo/base.py')
-rw-r--r--git/repo/base.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/git/repo/base.py b/git/repo/base.py
index 97e49aa2..1dcb80ed 100644
--- a/git/repo/base.py
+++ b/git/repo/base.py
@@ -66,6 +66,10 @@ if sys.version_info[:2] < (2, 5): # python 2.4 compatiblity
__all__ = ('Repo', )
+def _expand_path(p):
+ return os.path.abspath(os.path.expandvars(os.path.expanduser(p)))
+
+
class Repo(object):
"""Represents a git repository and allows you to query references,
@@ -111,7 +115,7 @@ class Repo(object):
:raise InvalidGitRepositoryError:
:raise NoSuchPathError:
:return: git.Repo """
- epath = os.path.abspath(os.path.expandvars(os.path.expanduser(path or os.getcwd())))
+ epath = _expand_path(path or os.getcwd())
self.git = None # should be set for __del__ not to fail in case we raise
if not os.path.exists(epath):
raise NoSuchPathError(epath)
@@ -133,7 +137,7 @@ class Repo(object):
self.git_dir = gitpath
self._working_tree_dir = curpath
break
-
+
if not search_parent_directories:
break
curpath, dummy = os.path.split(curpath)
@@ -700,7 +704,8 @@ class Repo(object):
keyword arguments serving as additional options to the git-init command
:return: ``git.Repo`` (the newly created repo)"""
-
+ if path:
+ path = _expand_path(path)
if mkdir and path and not os.path.exists(path):
os.makedirs(path, 0o755)