| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent b29388a commit 9d5d143
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -47,7 +47,7 @@ | |||
| 47 | 47 | from .fun import ( | |
| 48 | 48 | rev_parse, | |
| 49 | 49 | is_git_dir, | |
| 50 | - find_git_dir, | ||
| 50 | + find_submodule_git_dir, | ||
| 51 | 51 | touch, | |
| 52 | 52 | ) | |
| 53 | 53 | from git.compat import ( | |
@@ -79,7 +79,7 @@ | |||
| 79 | 79 | ||
| 80 | 80 | ||
| 81 | 81 | def _expand_path(p): | |
| 82 | - return os.path.abspath(os.path.expandvars(os.path.expanduser(p))) | ||
| 82 | + return os.path.normpath(os.path.abspath(os.path.expandvars(os.path.expanduser(p)))) | ||
| 83 | 83 | ||
| 84 | 84 | ||
| 85 | 85 | class Repo(object): | |
@@ -98,6 +98,11 @@ class Repo(object): | |||
| 98 | 98 | 'git_dir' is the .git repository directory, which is always set.""" | |
| 99 | 99 | DAEMON_EXPORT_FILE = 'git-daemon-export-ok' | |
| 100 | 100 | ||
| 101 | + git = None # Must exist, or __del__ will fail in case we raise on `__init__()` | ||
| 102 | + working_dir = None | ||
| 103 | + _working_tree_dir = None | ||
| 104 | + git_dir = None | ||
| 105 | + | ||
| 101 | 106 | # precompiled regex | |
| 102 | 107 | re_whitespace = re.compile(r'\s+') | |
| 103 | 108 | re_hexsha_only = re.compile('^[0-9A-Fa-f]{40}$') | |
@@ -138,16 +143,11 @@ def __init__(self, path=None, odbt=DefaultDBType, search_parent_directories=Fals | |||
| 138 | 143 | :raise InvalidGitRepositoryError: | |
| 139 | 144 | :raise NoSuchPathError: | |
| 140 | 145 | :return: git.Repo """ | |
| 141 | - self.git = None # should be set for __del__ not to fail in case we raise | ||
| 142 | 146 | epath = os.getenv('GIT_DIR') | |
| 143 | 147 | epath = _expand_path(epath or path or os.getcwd()) | |
| 144 | 148 | if not os.path.exists(epath): | |
| 145 | 149 | raise NoSuchPathError(epath) | |
| 146 | 150 | ||
| 147 | - self.working_dir = None | ||
| 148 | - self._working_tree_dir = None | ||
| 149 | - self.git_dir = None | ||
| 150 | - | ||
| 151 | 151 | ## Walk up the path to find the `.git` dir. | |
| 152 | 152 | # | |
| 153 | 153 | curpath = epath | |
@@ -157,20 +157,20 @@ def __init__(self, path=None, odbt=DefaultDBType, search_parent_directories=Fals | |||
| 157 | 157 | # repo instances with paths that depend on path-portions that will not exist after being | |
| 158 | 158 | # removed. It's just cleaner. | |
| 159 | 159 | if is_git_dir(curpath): | |
| 160 | - self.git_dir = os.path.normpath(curpath) | ||
| 160 | + self.git_dir = curpath | ||
| 161 | 161 | self._working_tree_dir = os.path.dirname(self.git_dir) | |
| 162 | 162 | break | |
| 163 | 163 | ||
| 164 | - gitpath = find_git_dir(join(curpath, '.git')) | ||
| 165 | - if gitpath is not None: | ||
| 166 | - self.git_dir = os.path.normpath(gitpath) | ||
| 164 | + sm_gitpath = find_submodule_git_dir(join(curpath, '.git')) | ||
| 165 | + if sm_gitpath is not None: | ||
| 166 | + self.git_dir = os.path.normpath(sm_gitpath) | ||
| 167 | 167 | self._working_tree_dir = curpath | |
| 168 | 168 | break | |
| 169 | 169 | ||
| 170 | 170 | if not search_parent_directories: | |
| 171 | 171 | break | |
| 172 | - curpath, dummy = os.path.split(curpath) | ||
| 173 | - if not dummy: | ||
| 172 | + curpath, tail = os.path.split(curpath) | ||
| 173 | + if not tail: | ||
| 174 | 174 | break | |
| 175 | 175 | # END while curpath | |
| 176 | 176 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,7 +20,7 @@ | |||
| 20 | 20 | from git.compat import xrange | |
| 21 | 21 | ||
| 22 | 22 | ||
| 23 | - __all__ = ('rev_parse', 'is_git_dir', 'touch', 'find_git_dir', 'name_to_object', 'short_to_long', 'deref_tag', | ||
| 23 | + __all__ = ('rev_parse', 'is_git_dir', 'touch', 'find_submodule_git_dir', 'name_to_object', 'short_to_long', 'deref_tag', | ||
| 24 | 24 | 'to_commit') | |
| 25 | 25 | ||
| 26 | 26 | ||
@@ -49,7 +49,8 @@ def is_git_dir(d): | |||
| 49 | 49 | return False | |
| 50 | 50 | ||
| 51 | 51 | ||
| 52 | - def find_git_dir(d): | ||
| 52 | + def find_submodule_git_dir(d): | ||
| 53 | + """Search for a submodule repo.""" | ||
| 53 | 54 | if is_git_dir(d): | |
| 54 | 55 | return d | |
| 55 | 56 | ||
@@ -64,7 +65,7 @@ def find_git_dir(d): | |||
| 64 | 65 | path = content[8:] | |
| 65 | 66 | if not os.path.isabs(path): | |
| 66 | 67 | path = join(dirname(d), path) | |
| 67 | - return find_git_dir(path) | ||
| 68 | + return find_submodule_git_dir(path) | ||
| 68 | 69 | # end handle exception | |
| 69 | 70 | return None | |
| 70 | 71 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,7 +14,7 @@ | |||
| 14 | 14 | from git.objects.submodule.base import Submodule | |
| 15 | 15 | from git.objects.submodule.root import RootModule, RootUpdateProgress | |
| 16 | 16 | from git.repo.fun import ( | |
| 17 | - find_git_dir, | ||
| 17 | + find_submodule_git_dir, | ||
| 18 | 18 | touch | |
| 19 | 19 | ) | |
| 20 | 20 | from git.test.lib import ( | |
@@ -757,7 +757,7 @@ def assert_exists(sm, value=True): | |||
| 757 | 757 | else: | |
| 758 | 758 | assert osp.isfile(module_repo_path) | |
| 759 | 759 | assert sm.module().has_separate_working_tree() | |
| 760 | - assert find_git_dir(module_repo_path) is not None, "module pointed to by .git file must be valid" | ||
| 760 | + assert find_submodule_git_dir(module_repo_path) is not None, "module pointed to by .git file must be valid" | ||
| 761 | 761 | # end verify submodule 'style' | |
| 762 | 762 | ||
| 763 | 763 | # test move | |
| Back | FazBrowse Home | New Git URL |
0 commit comments