diff options
author | Kostis Anagnostopoulos <ankostis@gmail.com> | 2016-10-19 16:01:47 +0200 |
---|---|---|
committer | Kostis Anagnostopoulos <ankostis@gmail.com> | 2016-10-19 16:01:47 +0200 |
commit | 9d5d143f72e4d588e3a0abb2ab82fa5a2c35e8aa (patch) | |
tree | 01f02c1aff9dbf5aa04bc862a47364af6987ba38 | |
parent | b29388a8f9cf3522e5f52b47572af7d8f61862a1 (diff) | |
download | gitpython-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()`).
-rw-r--r-- | git/repo/base.py | 26 | ||||
-rw-r--r-- | git/repo/fun.py | 7 | ||||
-rw-r--r-- | git/test/test_submodule.py | 4 |
3 files changed, 19 insertions, 18 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 diff --git a/git/repo/fun.py b/git/repo/fun.py index 320eb1c8..fe0896a9 100644 --- a/git/repo/fun.py +++ b/git/repo/fun.py @@ -20,7 +20,7 @@ from git.exc import WorkTreeRepositoryUnsupported from git.compat import xrange -__all__ = ('rev_parse', 'is_git_dir', 'touch', 'find_git_dir', 'name_to_object', 'short_to_long', 'deref_tag', +__all__ = ('rev_parse', 'is_git_dir', 'touch', 'find_submodule_git_dir', 'name_to_object', 'short_to_long', 'deref_tag', 'to_commit') @@ -49,7 +49,8 @@ def is_git_dir(d): return False -def find_git_dir(d): +def find_submodule_git_dir(d): + """Search for a submodule repo.""" if is_git_dir(d): return d @@ -64,7 +65,7 @@ def find_git_dir(d): path = content[8:] if not os.path.isabs(path): path = join(dirname(d), path) - return find_git_dir(path) + return find_submodule_git_dir(path) # end handle exception return None diff --git a/git/test/test_submodule.py b/git/test/test_submodule.py index 9db4f9c9..39040ced 100644 --- a/git/test/test_submodule.py +++ b/git/test/test_submodule.py @@ -14,7 +14,7 @@ from git.exc import ( from git.objects.submodule.base import Submodule from git.objects.submodule.root import RootModule, RootUpdateProgress from git.repo.fun import ( - find_git_dir, + find_submodule_git_dir, touch ) from git.test.lib import ( @@ -757,7 +757,7 @@ class TestSubmodule(TestBase): else: assert osp.isfile(module_repo_path) assert sm.module().has_separate_working_tree() - assert find_git_dir(module_repo_path) is not None, "module pointed to by .git file must be valid" + assert find_submodule_git_dir(module_repo_path) is not None, "module pointed to by .git file must be valid" # end verify submodule 'style' # test move |