def is_git_dir(d): """From git's setup.c:is_git_directory().""" if core.isdir(d) and core.isdir(join(d, "objects")) and core.isdir(join(d, "refs")): headref = join(d, "HEAD") return core.isfile(headref) or (core.islink(headref) and core.readlink(headref).startswith("refs")) return is_git_file(d)
def is_git_dir(d): """From git's setup.c:is_git_directory().""" if (core.isdir(d) and core.isdir(join(d, 'objects')) and core.isdir(join(d, 'refs'))): headref = join(d, 'HEAD') return (core.isfile(headref) or (core.islink(headref) and core.readlink(headref).startswith('refs'))) return is_git_file(d)
def is_git_dir(git_dir): """From git's setup.c:is_git_directory().""" result = False if git_dir: headref = join(git_dir, 'HEAD') if (core.isdir(git_dir) and core.isdir(join(git_dir, 'objects')) and core.isdir(join(git_dir, 'refs'))): result = (core.isfile(headref) or (core.islink(headref) and core.readlink(headref).startswith('refs/'))) else: result = is_git_file(git_dir) return result
def is_git_dir(git_dir): """From git's setup.c:is_git_directory().""" result = False if git_dir: headref = join(git_dir, 'HEAD') if (core.isdir(git_dir) and (core.isdir(join(git_dir, 'objects')) and core.isdir(join(git_dir, 'refs'))) or (core.isfile(join(git_dir, 'gitdir')) and core.isfile(join(git_dir, 'commondir')))): result = (core.isfile(headref) or (core.islink(headref) and core.readlink(headref).startswith('refs/'))) else: result = is_git_file(git_dir) return result
def _read_git_head(head, default='master', git=git): """Pure-python .git/HEAD reader""" # Legacy .git/HEAD symlinks if core.islink(head): refs_heads = core.realpath(git.git_path('refs', 'heads')) path = core.abspath(head).replace('\\', '/') if path.startswith(refs_heads + '/'): return path[len(refs_heads) + 1:] # Common .git/HEAD "ref: refs/heads/master" file elif core.isfile(head): data = core.read(head).rstrip() ref_prefix = 'ref: ' if data.startswith(ref_prefix): return data[len(ref_prefix):] # Detached head return data return default
def _read_git_head(head, default="master", git=git): """Pure-python .git/HEAD reader""" # Legacy .git/HEAD symlinks if core.islink(head): refs_heads = core.realpath(git.git_path("refs", "heads")) path = core.abspath(head).replace("\\", "/") if path.startswith(refs_heads + "/"): return path[len(refs_heads) + 1 :] # Common .git/HEAD "ref: refs/heads/master" file elif core.isfile(head): data = core.read(head).rstrip() ref_prefix = "ref: " if data.startswith(ref_prefix): return data[len(ref_prefix) :] # Detached head return data return default
def _read_git_head(head, default='master', git=git): """Pure-python .git/HEAD reader""" # Legacy .git/HEAD symlinks if core.islink(head): refs_heads = core.realpath(git.git_path('refs', 'heads')) path = core.abspath(head).replace('\\', '/') if path.startswith(refs_heads + '/'): return path[len(refs_heads)+1:] # Common .git/HEAD "ref: refs/heads/master" file elif core.isfile(head): data = core.read(head).rstrip() ref_prefix = 'ref: ' if data.startswith(ref_prefix): return data[len(ref_prefix):] # Detached head return data return default