示例#1
0
文件: git.py 项目: Jobava/git-cola
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)
示例#2
0
文件: git.py 项目: jmdcal/git-cola
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)
示例#3
0
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)
示例#4
0
文件: git.py 项目: iJunkie22/git-cola
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
示例#5
0
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
示例#6
0
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
示例#7
0
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
示例#8
0
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