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
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
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
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
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
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
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
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()
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
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()
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
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
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 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
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
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
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 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
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
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
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
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