Ejemplo n.º 1
0
def backup_and_stash_first():
    sys_call("git reset HEAD .")
    resp = from_sys_call("git stash save --keep-index --include-untracked").strip()
    if resp == "No local changes to save":
        return False
    else:
        return True
Ejemplo n.º 2
0
def get_remote_url_key():
    all_configs = from_sys_call("git config --list").strip().split("\n")
    matching_ln_regex = "^remote\.(.*)\.url=(.*)$"
    for c in all_configs:
        m = re.match(matching_ln_regex, c)
        if m and (re.match(http_regex, m.group(2)) or re.match(git_regex, m.group(2))):
            return m.group(1)
    return None
Ejemplo n.º 3
0
def backup_and_stash_first():
    sys_call("git reset HEAD .")
    resp = from_sys_call(
        "git stash save --keep-index --include-untracked").strip()
    if resp == "No local changes to save":
        return False
    else:
        return True
Ejemplo n.º 4
0
def get_ancestor_hash(ahash, index=None, short=True):
    arg_list = ["git", "rev-parse"]
    if short:
        arg_list.append("--short")
    the_hash = ahash
    if index is not None:
        the_hash = ahash + "~" + index
    arg_list.append(the_hash)
    return from_sys_call(" ".join(arg_list)).strip()
Ejemplo n.º 5
0
def get_ancestor_hash(ahash, index=None, short=True):
    arg_list = ["git", "rev-parse"]
    if short:
        arg_list.append("--short")
    the_hash = ahash
    if index is not None:
        the_hash = ahash + "~" + index
    arg_list.append(the_hash)
    return from_sys_call(" ".join(arg_list)).strip()
Ejemplo n.º 6
0
def get_remote_url_key():
    all_configs = from_sys_call("git config --list").strip().split("\n")
    matching_ln_regex = "^remote\.(.*)\.url=(.*)$"
    for c in all_configs:
        m = re.match(matching_ln_regex, c)
        if m and (re.match(http_regex, m.group(2))
                  or re.match(git_regex, m.group(2))):
            return m.group(1)
    return None
Ejemplo n.º 7
0
def github_info(prev_commit, post_commit):
    first_key = get_remote_url_key()
    if first_key is None:
        return None
    resp = from_sys_call("git config --get remote." + first_key + ".url").strip()
    m = re.match(http_regex, resp)
    if m:
        return m.group(0)[:-4] + "/compare/" + prev_commit + "..." + post_commit
    m = re.match(git_regex, resp)
    if m:
        return "https://github.com/" + m.group(1) + "/" + m.group(2) + "/compare/" + prev_commit + "..." + post_commit
    return None
Ejemplo n.º 8
0
def get_current_head_branch():
    branches_str = from_sys_call("git branch --list").strip()
    branches_unpolished = branches_str.split("\n")
    for branch_unpolished in branches_unpolished:
        branch_raw = branch_unpolished.strip()
        if branch_raw[0] == "*":
            m = re.compile("^\* \((detached from|HEAD detached at) ([a-z0-9]{5,})\)$").match(branch_raw)
            if m:
                return m.group(2)
            b = re.compile("^\* ([a-zA-Z0-9\-_]+)$").match(branch_raw)
            if b:
                return b.group(1)
            raise ValueError("unhandled branch name: " + branch_raw[2:].strip())
    raise EnvironmentError("no current head branch is listed")
Ejemplo n.º 9
0
def get_remote_head():
    rbs = from_sys_call("git branch -r").strip()
    all_remote_branches = set()
    for rb in rbs.split("\n"):
        rb = rb.strip().split(" ")[0]
        all_remote_branches.add(rb)
    if "origin/HEAD" in all_remote_branches:
        return "origin/HEAD"
    elif "origin/master" in all_remote_branches:
        return "origin/master"
    elif "origin/trunk" in all_remote_branches:
        return "origin/trunk"
    else:
        raise ValueError("expecting remote branch(es) to contain HEAD, master, or trunk")
Ejemplo n.º 10
0
def github_info(prev_commit, post_commit):
    first_key = get_remote_url_key()
    if first_key is None:
        return None
    resp = from_sys_call("git config --get remote." + first_key +
                         ".url").strip()
    m = re.match(http_regex, resp)
    if m:
        return m.group(
            0)[:-4] + "/compare/" + prev_commit + "..." + post_commit
    m = re.match(git_regex, resp)
    if m:
        return ("https://github.com/" + m.group(1) + "/" + m.group(2) +
                "/compare/" + prev_commit + "..." + post_commit)
    return None
Ejemplo n.º 11
0
def get_remote_head():
    rbs = from_sys_call("git branch -r").strip()
    all_remote_branches = set()
    for rb in rbs.split("\n"):
        rb = rb.strip().split(" ")[0]
        all_remote_branches.add(rb)
    if "origin/HEAD" in all_remote_branches:
        return "origin/HEAD"
    elif "origin/master" in all_remote_branches:
        return "origin/master"
    elif "origin/trunk" in all_remote_branches:
        return "origin/trunk"
    else:
        raise ValueError(
            "expecting remote branch(es) to contain HEAD, master, or trunk")
def get_expansion_set(go):
    expansion = set([])
    try:
        files = os.from_sys_call(
            " ".join(["ls", go, "|", "grep", config.expansion_tmp_files])).strip().split("\n")
        for fl in files:
            fl = fl.strip()
            ep = set([])
            try:
                ep = ep | set(ex.read_str_from(go + fl))
            except:
                pass
            expansion = expansion | ep
        return expansion
    except:
        return expansion
Ejemplo n.º 13
0
def get_current_head_branch():
    branches_str = from_sys_call("git branch --list").strip()
    branches_unpolished = branches_str.split("\n")
    for branch_unpolished in branches_unpolished:
        branch_raw = branch_unpolished.strip()
        if branch_raw[0] == "*":
            m = re.compile(
                "^\* \((detached from|HEAD detached at) ([a-z0-9]{5,})\)$"
            ).match(branch_raw)
            if m:
                return m.group(2)
            b = re.compile("^\* ([a-zA-Z0-9\-_]+)$").match(branch_raw)
            if b:
                return b.group(1)
            raise ValueError("unhandled branch name: " +
                             branch_raw[2:].strip())
    raise EnvironmentError("no current head branch is listed")
Ejemplo n.º 14
0
def clear_temp_checkout(current_commit):
    sys_call("git reset --hard " + current_commit)
    resp = from_sys_call("git stash save --keep-index --include-untracked").strip()
    if resp != "No local changes to save":
        sys_call("git stash drop")
Ejemplo n.º 15
0
def get_head_ancestor(index, short=True):
    if short:
        return from_sys_call("git rev-parse --short HEAD~" + index).strip()
    else:
        return from_sys_call("git rev-parse HEAD~" + index).strip()
Ejemplo n.º 16
0
def get_hash(hash_exp, short=True):
    arg_list = ["git", "rev-parse"]
    if short:
        arg_list.append("--short")
    arg_list.append(hash_exp)
    return from_sys_call(" ".join(arg_list)).strip()
Ejemplo n.º 17
0
def get_hash(hash_exp, short=True):
    arg_list = ["git", "rev-parse"]
    if short:
        arg_list.append("--short")
    arg_list.append(hash_exp)
    return from_sys_call(" ".join(arg_list)).strip()
Ejemplo n.º 18
0
def get_head_ancestor(index, short=True):
    if short:
        return from_sys_call("git rev-parse --short HEAD~" + index).strip()
    else:
        return from_sys_call("git rev-parse HEAD~" + index).strip()
Ejemplo n.º 19
0
def git_commit_msgs(from_commit, to_commit):
    gitlog = (
        "git log --graph --abbrev-commit " + "--format=format:'%h - (%ai) %s - %an%d' " + from_commit + ".." + to_commit
    )
    return from_sys_call(gitlog)
Ejemplo n.º 20
0
def clear_temp_checkout(current_commit):
    sys_call("git reset --hard " + current_commit)
    resp = from_sys_call(
        "git stash save --keep-index --include-untracked").strip()
    if resp != "No local changes to save":
        sys_call("git stash drop")
Ejemplo n.º 21
0
def git_commit_msgs(from_commit, to_commit):
    gitlog = "git log --graph --abbrev-commit " + \
        "--format=format:'%h - (%ai) %s - %an%d' " + from_commit + ".." + to_commit
    return from_sys_call(gitlog)