| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -32,6 +32,7 @@ | |||
| 32 | 32 | from fun import ( | |
| 33 | 33 | rev_parse, | |
| 34 | 34 | is_git_dir, | |
| 35 | + read_gitfile, | ||
| 35 | 36 | touch | |
| 36 | 37 | ) | |
| 37 | 38 | ||
@@ -113,6 +114,11 @@ def __init__(self, path=None, odbt = DefaultDBType): | |||
| 113 | 114 | self.git_dir = gitpath | |
| 114 | 115 | self._working_tree_dir = curpath | |
| 115 | 116 | break | |
| 117 | + gitpath = read_gitfile(gitpath) | ||
| 118 | + if gitpath: | ||
| 119 | + self.git_dir = gitpath | ||
| 120 | + self._working_tree_dir = curpath | ||
| 121 | + break | ||
| 116 | 122 | curpath, dummy = os.path.split(curpath) | |
| 117 | 123 | if not dummy: | |
| 118 | 124 | break | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -30,6 +30,17 @@ def is_git_dir(d): | |||
| 30 | 30 | os.readlink(headref).startswith('refs')) | |
| 31 | 31 | return False | |
| 32 | 32 | ||
| 33 | + def read_gitfile(f): | ||
| 34 | + """ This is taken from the git setup.c:read_gitfile function. | ||
| 35 | + :return gitdir path or None if gitfile is invalid.""" | ||
| 36 | + | ||
| 37 | + if not isfile(f): | ||
| 38 | + return None | ||
| 39 | + line = open(f, 'r').readline().rstrip() | ||
| 40 | + if line[0:8] != 'gitdir: ': | ||
| 41 | + return None | ||
| 42 | + path = os.path.realpath(line[8:]) | ||
| 43 | + return path if is_git_dir(path) else None | ||
| 33 | 44 | ||
| 34 | 45 | def short_to_long(odb, hexsha): | |
| 35 | 46 | """:return: long hexadecimal sha1 from the given less-than-40 byte hexsha | |
| Back | FazBrowse Home | New Git URL |
0 commit comments