def git_history(): error, data = run('git log --abbrev-commit --decorate --date=iso') commits = textutils.blocks(data, lambda x: x and x[:6] == 'commit') output = [] for commit in commits: text = [] for line in commit: if line.startswith('commit'): sha1 = line.split()[1] main = line.split('(', 1) labels = '' if len(main) == 2: labels = main[1].split(')', 1)[0] labels = labels.split(', ') elif line.startswith('Author'): author = line.split(' ', 1)[1].lstrip() elif line.startswith('Date'): date = line.split(' ', 1)[1].lstrip() elif line.startswith('Merge'): pass else: text.append(line.lstrip()) message = ' | '.join([x for x in text if x]) history_line = [labels, message, author, date, sha1] output.append(history_line) return output
def git_diff(path, cached=False): if not path or type(path) is not str: raise Exception('Path not supported: ' + str(path)) opt = '--cached' if cached else '' cmd = 'git diff {} -- {}'.format(opt, path) error, data = run(cmd) if not data: cmd = 'git diff -- /dev/null %s' % path error, data = run(cmd) if data: data = data[5:] error = 0 else: data = data[4:] if error: raise Exception('Error executing "' + cmd + '" (error = ' + str(error)) hunks = list(textutils.blocks(data, lambda x: x and x.startswith('@@'))) return hunks
def git_diff(path): if not path or type(path) is not str: raise Exception('Path not supported: ' + str(path)) cmd = 'git diff -- %s' % path data, error = run_with_error_code(cmd) if not data: cmd = 'git diff -- /dev/null %s' % path data, error = run_with_error_code(cmd) if data: data = data[5:] error = 0 else: data = data[4:] # import cursutils # cursutils.debug() if error: raise Exception('Error executing "' + cmd + '" (error = ' + str(error)) hunks = textutils.blocks(data, lambda x: x and x.startswith('@@')) screen_content = [] for h in hunks: screen_content += textutils.remove_superfluous_alineas(h) screen_content.append('─' * 80) return screen_content