summaryrefslogtreecommitdiff
path: root/git/repo/base.py
diff options
context:
space:
mode:
authorKostis Anagnostopoulos <ankostis@gmail.com>2016-10-19 16:01:47 +0200
committerKostis Anagnostopoulos <ankostis@gmail.com>2016-10-19 16:01:47 +0200
commit9d5d143f72e4d588e3a0abb2ab82fa5a2c35e8aa (patch)
tree01f02c1aff9dbf5aa04bc862a47364af6987ba38 /git/repo/base.py
parentb29388a8f9cf3522e5f52b47572af7d8f61862a1 (diff)
downloadgitpython-9d5d143f72e4d588e3a0abb2ab82fa5a2c35e8aa.tar.gz
repo: minor code and doc correcions.
+ Expansion of paths also `osp.normalize()` them. + Make Repo-fields --> class-fields to avoid initializations on construct. + Explain and rename `git.repo.fun.find_git_dir()` is for submodules (`find_submodule_git_dir()`).
Diffstat (limited to 'git/repo/base.py')
-rw-r--r--git/repo/base.py26
1 files changed, 13 insertions, 13 deletions
diff --git a/git/repo/base.py b/git/repo/base.py
index d36864bb..bde9b936 100644
--- a/git/repo/base.py
+++ b/git/repo/base.py
@@ -47,7 +47,7 @@ from gitdb.util import (
from .fun import (
rev_parse,
is_git_dir,
- find_git_dir,
+ find_submodule_git_dir,
touch,
)
from git.compat import (
@@ -79,7 +79,7 @@ __all__ = ('Repo',)
def _expand_path(p):
- return os.path.abspath(os.path.expandvars(os.path.expanduser(p)))
+ return os.path.normpath(os.path.abspath(os.path.expandvars(os.path.expanduser(p))))
class Repo(object):
@@ -98,6 +98,11 @@ class Repo(object):
'git_dir' is the .git repository directory, which is always set."""
DAEMON_EXPORT_FILE = 'git-daemon-export-ok'
+ git = None # Must exist, or __del__ will fail in case we raise on `__init__()`
+ working_dir = None
+ _working_tree_dir = None
+ git_dir = None
+
# precompiled regex
re_whitespace = re.compile(r'\s+')
re_hexsha_only = re.compile('^[0-9A-Fa-f]{40}$')
@@ -138,16 +143,11 @@ class Repo(object):
:raise InvalidGitRepositoryError:
:raise NoSuchPathError:
:return: git.Repo """
- self.git = None # should be set for __del__ not to fail in case we raise
epath = os.getenv('GIT_DIR')
epath = _expand_path(epath or path or os.getcwd())
if not os.path.exists(epath):
raise NoSuchPathError(epath)
- self.working_dir = None
- self._working_tree_dir = None
- self.git_dir = None
-
## Walk up the path to find the `.git` dir.
#
curpath = epath
@@ -157,20 +157,20 @@ class Repo(object):
# repo instances with paths that depend on path-portions that will not exist after being
# removed. It's just cleaner.
if is_git_dir(curpath):
- self.git_dir = os.path.normpath(curpath)
+ self.git_dir = curpath
self._working_tree_dir = os.path.dirname(self.git_dir)
break
- gitpath = find_git_dir(join(curpath, '.git'))
- if gitpath is not None:
- self.git_dir = os.path.normpath(gitpath)
+ sm_gitpath = find_submodule_git_dir(join(curpath, '.git'))
+ if sm_gitpath is not None:
+ self.git_dir = os.path.normpath(sm_gitpath)
self._working_tree_dir = curpath
break
if not search_parent_directories:
break
- curpath, dummy = os.path.split(curpath)
- if not dummy:
+ curpath, tail = os.path.split(curpath)
+ if not tail:
break
# END while curpath