Esempio n. 1
0
def get_file_changes(base_command, flag, path, commit=None, comparsion=None):
    try:
        out = '<pre>'
        if 'M' in flag:
            if commit:
                command = base_command + '%s:%s %s:%s' % (comparsion, path, commit, path)
            else:
                command = base_command + path
            #print(base_command, flag, path, commit, comparsion)
            output = getoutput_lines(command)
            save_log(command, output[0])
            if not output[1][4:] and 'Binary' in "".join(output[1]): return "Cannot decode this file"
            #print(output[1][2])
            for line in output[1][4:]:
                line = remove_html(line)
                if len(line) > 0:
                    if line[0]=='-':
                        line = '<font color="RED"> %s</font>' % (line)
                    elif line[0]=='+':
                        line = '<font color="GREEN"> %s</font>' % (line)
                    out += line + '\n'
            out += '</pre>'
            return out
        elif 'A' in flag or flag == '??':
            if commit: 
                command = 'git show %s:%s' % (commit, path)
                output = getoutput_lines(command)
                save_log(command, output[0])
            else:
                if isdir(path):
                    save_log('isdir(path)', 'True')
                    return '<pre>This is a directory</pre>'
                output = open(path).read()
                save_log("open(path).read()", output)
                output = [None, output.split("\n")]
            for line in output[1]:
                line = remove_html(line)
                line = '<font color="GREEN"> + %s </font>' % (line)
                out += line + '\n'
            out += '</pre>'
            return out
        elif 'D' in flag:
            command = 'git show %s:%s' % (comparsion, path)
            output = getoutput_lines(command)
            save_log(command, output[0])
            for line in output[1]:
                line = remove_html(line)
                line = '<font color="RED"> - %s </font>' % (line)
                out += line + '\n'
            out += '</pre>'
            return out
    except UnicodeDecodeError:
        return "Cannot decode this file"
Esempio n. 2
0
def get_commits():
    command = 'git log --graph --pretty=format:"%h\n%s\n%an\n%ad"'
    output = getoutput_lines(command)
    save_log(command, output[0])
    commits = []
    i = 0
    commit = []
    for line in output[1]:
        j = 0
        for char in line:
            if char == '*' or char == '|' or char == '\\' or char == '/' or char == '_' or char == ' ':
                j += 1
            else:
                break
        commit.append(line[j:])
        i += 1
        if i == 4:
            i = 0
            commits.append(commit)
            commit = []
    i = 0
    while i < len(commits):
        command = 'git branch -r --contains ' + commits[i][0]
        output = getoutput(command)
        if output != '':
            break
        commits[i][1] = '[not pushed] ' + commits[i][1]
        i += 1
    return commits
Esempio n. 3
0
def get_current_branch():
    command = 'git branch'
    output = getoutput_lines(command)
    save_log(command, output[0])
    for line in output[1]:
        if '*' in line:
            return line[2:]
Esempio n. 4
0
def get_files(commit):
    command = 'git show --pretty="format:" --name-status ' +  commit
    output = getoutput_lines(command)
    save_log(command, output[0])
    files = []
    for line in output[1][1:]:
        files.append(line.split('\t'))
    return files
Esempio n. 5
0
def get_remote_branches():
    command = 'git branch -r'
    output = getoutput_lines(command)
    save_log(command, output[0])
    branches = []
    for line in output[1]:
        branches.append(line[2:].split(' ')[0])
    return branches
Esempio n. 6
0
def get_local_branches():
    command = 'git branch'
    output = getoutput_lines(command)
    save_log(command, output[0])
    branches = []
    for line in output[1]:
        branches.append(line[2:])
    return branches
Esempio n. 7
0
def get_unstaged_files():
    command = 'git status -s'
    output = getoutput_lines(command)
    files = output[1]
    j = 0
    if len(files) > 0 and files[0] != '':
        for i in range(len(files)):
            if files[i-j][0] != ' ' and files[i-j][0] != '?' and files[i-j][0] != 'U':
                del files[i-j]
                j += 1
    save_log(command, output[0])
    return get_splited(output)
Esempio n. 8
0
def get_graph():
    command = 'git log --graph --pretty=format:""'
    output = getoutput_lines(command)
    save_log(command, output[0])
    graph_output = output[1]
    graph = []
    graph_log = ''
    i = 0
    graph_commit = []
    graph_commit.append(graph_output[0])
    for i in range(1, len(graph_output)):
        if '*' in graph_output[i]:
            graph.append(graph_commit)
            graph_commit = []
        graph_commit.append(graph_output[i])
    graph.append(graph_commit)
    return graph
Esempio n. 9
0
def stashes_list():
    command = 'git stash list'
    output = getoutput_lines(command)
    save_log(command, output[0])
    return output[1]
Esempio n. 10
0
def get_staged_files():
    command = 'git diff --name-status --cached'
    output = getoutput_lines(command)
    save_log(command, output[0])
    return get_splited(output)