Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- import os
- import webbrowser
- import shlex
- import subprocess
- import tempfile
- import click
- CMD_TPL = '''git log {0}...{1} "--pretty=format:<li><a href="{remote_origin}/commit/%H">view commit</a> (Author: %an) %s - %Cgreen%ar</li>"'''
- REMOTE_ORIGIN = 'git config --get remote.origin.url'
- def get_remote():
- ret = subprocess.check_output(shlex.split(REMOTE_ORIGIN))
- return ret.decode('utf-8').rsplit('.', 1)[0]
- def get_compare_result(commits):
- remote_origin = get_remote()
- cmd = CMD_TPL.format(*commits, remote_origin=remote_origin)
- ret = subprocess.check_output(shlex.split(cmd))
- return ret.decode('utf-8')
- def write_to_file(result):
- with tempfile.NamedTemporaryFile('w', suffix='.html', delete=False) as f:
- f.write(result)
- webbrowser.open_new_tab('file:///' + f.name)
- @click.command()
- @click.option('-b', '--branch', default='dev', required=False, help='The remote branch that compared with local HEAD commit.')
- @click.option('-c', '--commit', required=False, multiple=True, help='The commits to compare.')
- @click.option('-r', '--repo', required=True, help='The git repo.')
- def get_change_log(branch, commit, repo):
- os.chdir(os.path.abspath(os.path.join(r'e:\gitrepos', repo)))
- if not len(commit):
- commit = [f'origin/{branch}', 'HEAD']
- if len(commit) == 1:
- commit = ['HEAD'] + list(commit)
- ret = get_compare_result(commit)
- write_to_file(ret)
- if __name__ == '__main__':
- get_change_log()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement