Ejemplo n.º 1
0
def push(window, additional_args=None):
    child = pexpect.spawn('git push')
    try:
        child.expect("Username*", timeout=2)
        dialog = AuthorizationWrapper(window)
        dialog.exec_()
        child.sendline(dialog.username)
        child.expect("Password*", timeout=2)
        child.sendline(dialog.password)
        child.expect(pexpect.EOF)
        info = child.before
    except (pexpect.TIMEOUT, pexpect.EOF):
        try:
            child.expect("Password*", timeout=2)
            dialog = AuthorizationWrapper(window)
            dialog.ui.Username_lineEdit.setText("Not needed")
            dialog.ui.Username_lineEdit.setReadOnly(True)
            dialog.exec_()
            child.sendline(dialog.password)
            child.expect(pexpect.EOF)
            info = child.before
        except (pexpect.TIMEOUT, pexpect.EOF):
            if get_url().startswith('https://'):
                info = 'Timeout error!'
            else:
                info = getoutput('git push')
    save_log('git push', info)
    return info
Ejemplo 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
Ejemplo n.º 3
0
def clone_repository(window, source, destination):
    cloning_timeout = 5
    command = 'git clone %s %s' % (source, destination)
    child = pexpect.spawn(command)
    try:
        child.expect("Username*", timeout=cloning_timeout)
        dialog = AuthorizationWrapper(window)
        dialog.exec_()
        child.sendline(dialog.username)
        child.expect("Password*", timeout=cloning_timeout)
        child.sendline(dialog.password)
        child.expect(pexpect.EOF)
        info = child.before
    except (pexpect.TIMEOUT, pexpect.EOF):
        rm_command = 'rm -rf ' + destination
        system(rm_command)
        try:
            child.expect("Password*", timeout=cloning_timeout)
            dialog = AuthorizationWrapper(window)
            dialog.ui.Username_lineEdit.setText("Not needed")
            dialog.ui.Username_lineEdit.setReadOnly(True)
            dialog.exec_()
            child.sendline(dialog.password)
            child.expect(pexpect.EOF)
            info = child.before
        except (pexpect.TIMEOUT, pexpect.EOF):
            system(rm_command)
            if source.startswith('https://') and '@' in source:
                return (False, 'Timeout error!')
            else:
                info = getoutput(command)
    save_log(command, info)
    return (True, info)
Ejemplo n.º 4
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:]
Ejemplo 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
Ejemplo 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
Ejemplo n.º 7
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
Ejemplo n.º 8
0
def check_repository(path):
    chdir(path)
    command = 'git rev-parse --git-dir'
    output = getoutput(command)
    save_log(command, output)
    if 'fatal' in output:
        return False
    return True
Ejemplo n.º 9
0
def create_branch(window, branch):
    command = 'git checkout -b ' + branch
    save_log(command, getoutput(command))
    url = get_url()
    additional_args = []
    if url.startswith("[email protected]"):
        additional_args.append('origin')
    additional_args.append(branch)
    return push(window, additional_args)
Ejemplo n.º 10
0
def get_settings():
    command_username = '******'
    command_email = 'git config --global user.email'
    settings = []
    output_username = getoutput(command_username)
    output_email = getoutput(command_email)
    save_log(command_username, output_username)
    save_log(command_email, output_email)
    settings.append(output_username)
    settings.append(output_email)
    return settings
Ejemplo n.º 11
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)
Ejemplo n.º 12
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"
Ejemplo n.º 13
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
Ejemplo n.º 14
0
def git_check_out(file):
    command = 'git checkout -- ' + file
    output = getoutput(command)
    save_log(command, output)
Ejemplo n.º 15
0
def stashes_list():
    command = 'git stash list'
    output = getoutput_lines(command)
    save_log(command, output[0])
    return output[1]
Ejemplo n.º 16
0
def stash():
    command = 'git stash'
    output = getoutput(command)
    save_log(command, output)
    return output
Ejemplo n.º 17
0
def drop_stash(stash):
    command = 'git stash drop ' + stash
    output = getoutput(command)
    save_log(command, output)
    return output
Ejemplo n.º 18
0
def change_remote_branch(branch, new_name):
    command = 'git checkout -b %s %s' % (new_name, branch)
    output = getoutput(command)
    save_log(command, output)
    return output
Ejemplo n.º 19
0
def git_add(file):
    command = 'git add ' + file
    output = getoutput(command)
    save_log(command, output)
Ejemplo n.º 20
0
def clean(file):
    command = 'git clean -f ' + file
    output = getoutput(command)
    save_log(command, output)
Ejemplo n.º 21
0
def commit_amend(message):
    command = 'git commit --amend -m "%s"' % message
    output = getoutput(command)
    save_log(command, output)
    return output
Ejemplo n.º 22
0
def get_staged_files():
    command = 'git diff --name-status --cached'
    output = getoutput_lines(command)
    save_log(command, output[0])
    return get_splited(output)
Ejemplo n.º 23
0
def to_string(files, command):
    strfiles = " ".join(files)
    command += strfiles
    output = getoutput(command)
    save_log(command, output)
Ejemplo n.º 24
0
def delete_branch(branch):
    command = 'git branch -d ' + branch
    output = getoutput(command)
    save_log(command, output)
    return output
Ejemplo n.º 25
0
def diff(filename):
    command = 'git diff ' + filename
    output = getoutput(command)
    save_log(command, output)
    return output
Ejemplo n.º 26
0
def get_url():
    command = "git config --get remote.origin.url"
    output = getoutput(command)
    save_log(command, output)
    return output
Ejemplo n.º 27
0
def git_rm(file):
    command = 'git rm ' + file
    output = getoutput(command)
    save_log(command, output)
Ejemplo n.º 28
0
def apply_stash(stash):
    command = 'git stash apply ' + stash 
    save_log(command, getoutput(command))
Ejemplo n.º 29
0
def cherry_pick(window, branch, commit):
    change_branch(branch)
    command = 'git cherry-pick ' + commit
    output = getoutput(command)
    save_log(command, output)
    return output
Ejemplo n.º 30
0
def change_local_branch(branch):
    command = 'git checkout ' + branch
    save_log(command, getoutput(command))