コード例 #1
0
ファイル: gitcmds.py プロジェクト: mwh/git-cola
def current_branch():
    """Return the current branch"""
    decode = core.decode
    head = git.git_path('HEAD')
    try:
        key = os.stat(head).st_mtime
        if _current_branch.key == key:
            return _current_branch.value
    except OSError:
        pass
    data = git.rev_parse('HEAD', with_stderr=True, symbolic_full_name=True)
    if data.startswith('fatal:'):
        # git init -- read .git/HEAD.  We could do this unconditionally
        # and avoid the subprocess call.  It's probably time to start
        # using dulwich.
        data = _read_git_head(head)

    for refs_prefix in ('refs/heads/', 'refs/remotes/'):
        if data.startswith(refs_prefix):
            value = decode(data[len(refs_prefix):])
            _current_branch.key = key
            _current_branch.value = value
            return value
    # Detached head
    return data
コード例 #2
0
def merge_message_path():
    """Return the path to .git/MERGE_MSG or .git/SQUASH_MSG."""
    for basename in ('MERGE_MSG', 'SQUASH_MSG'):
        path = git.git_path(basename)
        if core.exists(path):
            return path
    return None
コード例 #3
0
ファイル: gitcmds.py プロジェクト: suside/git-cola
def merge_message_path():
    """Return the path to .git/MERGE_MSG or .git/SQUASH_MSG."""
    for basename in ('MERGE_MSG', 'SQUASH_MSG'):
        path = git.git_path(basename)
        if os.path.exists(path):
            return path
    return None
コード例 #4
0
ファイル: gitcmds.py プロジェクト: queer1/git-cola
def current_branch():
    """Return the current branch"""
    decode = core.decode
    head = git.git_path('HEAD')
    try:
        key = os.stat(head).st_mtime
        if _current_branch.key == key:
            return _current_branch.value
    except OSError:
        pass
    status, data = git.rev_parse('HEAD',
                                 symbolic_full_name=True,
                                 with_status=True)
    if status != 0:
        # git init -- read .git/HEAD.  We could do this unconditionally...
        data = _read_git_head(head)

    for refs_prefix in ('refs/heads/', 'refs/remotes/', 'refs/tags/'):
        if data.startswith(refs_prefix):
            value = decode(data[len(refs_prefix):])
            _current_branch.key = key
            _current_branch.value = value
            return value
    # Detached head
    return data
コード例 #5
0
ファイル: gitcmds.py プロジェクト: jalaludin/git-cola
def merge_message_path():
    """Return the path to .git/MERGE_MSG or .git/SQUASH_MSG."""
    for basename in ("MERGE_MSG", "SQUASH_MSG"):
        path = git.git_path(basename)
        if core.exists(path):
            return path
    return None
コード例 #6
0
 def __init__(self, monitor, refs_only):
     _BaseThread.__init__(self, monitor, refs_only)
     self._worktree = self._transform_path(core.abspath(git.worktree()))
     self._worktree_watch = None
     self._git_dir = self._transform_path(core.abspath(git.git_path()))
     self._git_dir_watch = None
     self._stop_event_lock = Lock()
     self._stop_event = None
コード例 #7
0
 def __init__(self, monitor, refs_only):
     _BaseThread.__init__(self, monitor, refs_only)
     self._worktree = self._transform_path(core.abspath(git.getcwd()))
     self._worktree_watch = None
     self._git_dir = self._transform_path(core.abspath(git.git_path()))
     self._git_dir_watch = None
     self._stop_event_lock = Lock()
     self._stop_event = None
コード例 #8
0
ファイル: gitcmds.py プロジェクト: jalaludin/git-cola
def abort_merge():
    """Abort a merge by reading the tree at HEAD."""
    # Reset the worktree
    git.read_tree("HEAD", reset=True, u=True, v=True)
    # remove MERGE_HEAD
    merge_head = git.git_path("MERGE_HEAD")
    if core.exists(merge_head):
        core.unlink(merge_head)
    # remove MERGE_MESSAGE, etc.
    merge_msg_path = merge_message_path()
    while merge_msg_path:
        core.unlink(merge_msg_path)
        merge_msg_path = merge_message_path()
コード例 #9
0
 def __init__(self, monitor, refs_only):
     _BaseThread.__init__(self, monitor, refs_only)
     self._worktree = core.abspath(git.getcwd())
     self._git_dir = git.git_path()
     self._lock = Lock()
     self._inotify_fd = None
     self._pipe_r = None
     self._pipe_w = None
     self._worktree_wds = set()
     self._worktree_wd_map = {}
     self._git_dir_wds = set()
     self._git_dir_wd_map = {}
     self._git_dir_wd = None
コード例 #10
0
def abort_merge():
    """Abort a merge by reading the tree at HEAD."""
    # Reset the worktree
    git.read_tree('HEAD', reset=True, u=True, v=True)
    # remove MERGE_HEAD
    merge_head = git.git_path('MERGE_HEAD')
    if core.exists(merge_head):
        core.unlink(merge_head)
    # remove MERGE_MESSAGE, etc.
    merge_msg_path = merge_message_path()
    while merge_msg_path:
        core.unlink(merge_msg_path)
        merge_msg_path = merge_message_path()
コード例 #11
0
 def __init__(self, monitor, refs_only):
     _BaseThread.__init__(self, monitor, refs_only)
     self._worktree = core.abspath(git.worktree())
     self._git_dir = git.git_path()
     self._lock = Lock()
     self._inotify_fd = None
     self._pipe_r = None
     self._pipe_w = None
     self._worktree_wds = set()
     self._worktree_wd_map = {}
     self._git_dir_wds = set()
     self._git_dir_wd_map = {}
     self._git_dir_wd = None
コード例 #12
0
ファイル: fsmonitor.py プロジェクト: ttimz1313/git-cola
 def __init__(self, monitor, refs_only):
     _BaseThread.__init__(self, monitor, refs_only)
     if refs_only:
         worktree = None
     else:
         worktree = git.worktree()
         if worktree is not None:
             worktree = self._transform_path(core.abspath(worktree))
     self._worktree = worktree
     self._worktree_watch = None
     self._git_dir = self._transform_path(core.abspath(git.git_path()))
     self._git_dir_watch = None
     self._stop_event_lock = Lock()
     self._stop_event = None
コード例 #13
0
ファイル: gitcmds.py プロジェクト: jalaludin/git-cola
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
コード例 #14
0
ファイル: gitcmds.py プロジェクト: suside/git-cola
def _read_git_head(head, default='master', git=git):
    """Pure-python .git/HEAD reader"""
    # Legacy .git/HEAD symlinks
    if os.path.islink(head):
        refs_heads = os.path.realpath(git.git_path('refs', 'heads'))
        path = os.path.abspath(head).replace('\\', '/')
        if path.startswith(refs_heads + '/'):
            return path[len(refs_heads)+1:]

    # Common .git/HEAD "ref: refs/heads/master" file
    elif os.path.isfile(head):
        data = utils.slurp(core.decode(head)).rstrip()
        ref_prefix = 'ref: '
        if data.startswith(ref_prefix):
            return data[len(ref_prefix):]
        # Detached head
        return data

    return default
コード例 #15
0
ファイル: gitcmds.py プロジェクト: 007durgesh219/git-cola
def _read_git_head(head, default='master', git=git):
    """Pure-python .git/HEAD reader"""
    # Common .git/HEAD "ref: refs/heads/master" files
    islink = core.islink(head)
    if core.isfile(head) and not islink:
        data = core.read(head).rstrip()
        ref_prefix = 'ref: '
        if data.startswith(ref_prefix):
            return data[len(ref_prefix):]
        # Detached head
        return data
    # Legacy .git/HEAD symlinks
    elif islink:
        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:]

    return default
コード例 #16
0
ファイル: fsmonitor.py プロジェクト: ttimz1313/git-cola
 def __init__(self, monitor, refs_only):
     _BaseThread.__init__(self, monitor, refs_only)
     if refs_only:
         worktree = None
     else:
         worktree = git.worktree()
         if worktree is not None:
             worktree = core.abspath(worktree)
     self._worktree = worktree
     self._git_dir = git.git_path()
     self._lock = Lock()
     self._inotify_fd = None
     self._pipe_r = None
     self._pipe_w = None
     self._worktree_wds = set()
     self._worktree_wd_map = {}
     self._git_dir_wds = set()
     self._git_dir_wd_map = {}
     self._git_dir_wd = None
コード例 #17
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
コード例 #18
0
ファイル: gitcmds.py プロジェクト: jalaludin/git-cola
def current_branch():
    """Return the current branch"""
    head = git.git_path("HEAD")
    try:
        key = core.stat(head).st_mtime
        if _current_branch.key == key:
            return _current_branch.value
    except OSError:
        pass
    status, data, err = git.rev_parse("HEAD", symbolic_full_name=True)
    if status != 0:
        # git init -- read .git/HEAD.  We could do this unconditionally...
        data = _read_git_head(head)

    for refs_prefix in ("refs/heads/", "refs/remotes/", "refs/tags/"):
        if data.startswith(refs_prefix):
            value = data[len(refs_prefix) :]
            _current_branch.key = key
            _current_branch.value = value
            return value
    # Detached head
    return data
コード例 #19
0
ファイル: gitcmds.py プロジェクト: suside/git-cola
def current_branch():
    """Return the current branch"""
    decode = core.decode
    head = git.git_path('HEAD')
    try:
        key = os.stat(head).st_mtime
        if _current_branch.key == key:
            return _current_branch.value
    except OSError:
        pass
    status, data = git.rev_parse('HEAD', symbolic_full_name=True, with_status=True)
    if status != 0:
        # git init -- read .git/HEAD.  We could do this unconditionally...
        data = _read_git_head(head)

    for refs_prefix in ('refs/heads/', 'refs/remotes/', 'refs/tags/'):
        if data.startswith(refs_prefix):
            value = decode(data[len(refs_prefix):])
            _current_branch.key = key
            _current_branch.value = value
            return value
    # Detached head
    return data
コード例 #20
0
def merge_message(revision):
    """Return a merge message for FETCH_HEAD."""
    fetch_head = git.git_path('FETCH_HEAD')
    if core.exists(fetch_head):
        return git.fmt_merge_msg('--file', fetch_head)[STDOUT]
    return "Merge branch '%s'" % revision
コード例 #21
0
ファイル: gitcmds.py プロジェクト: suside/git-cola
def merge_message(revision):
    """Return a merge message for FETCH_HEAD."""
    fetch_head = git.git_path('FETCH_HEAD')
    if os.path.exists(fetch_head):
        return git.fmt_merge_msg('--file', fetch_head)
    return "Merge branch '%s'" % revision
コード例 #22
0
def commit_message_path():
    """Return the path to .git/GIT_COLA_MSG"""
    path = git.git_path("GIT_COLA_MSG")
    if core.exists(path):
        return path
    return None
コード例 #23
0
ファイル: gitcmds.py プロジェクト: jalaludin/git-cola
def merge_message(revision):
    """Return a merge message for FETCH_HEAD."""
    fetch_head = git.git_path("FETCH_HEAD")
    if core.exists(fetch_head):
        return git.fmt_merge_msg("--file", fetch_head)[STDOUT]
    return "Merge branch '%s'" % revision
コード例 #24
0
ファイル: gitcmds.py プロジェクト: jalaludin/git-cola
def commit_message_path():
    """Return the path to .git/GIT_COLA_MSG"""
    path = git.git_path("GIT_COLA_MSG")
    if core.exists(path):
        return path
    return None