mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
ab2d3957cb
Co-authored-by: Kamil Śliwak <kamil.sliwak@codepoets.it>
40 lines
900 B
Python
40 lines
900 B
Python
import subprocess
|
|
from pathlib import Path
|
|
from shutil import which
|
|
|
|
|
|
def run_git_command(command):
|
|
process = subprocess.run(
|
|
command,
|
|
encoding='utf8',
|
|
capture_output=True,
|
|
check=True,
|
|
)
|
|
return process.stdout.strip()
|
|
|
|
|
|
def git_current_branch():
|
|
return run_git_command(['git', 'symbolic-ref', 'HEAD', '--short'])
|
|
|
|
|
|
def git_commit_hash(ref: str = 'HEAD'):
|
|
return run_git_command(['git', 'rev-parse', '--verify', ref])
|
|
|
|
|
|
def git_diff(file_a: Path, file_b: Path) -> int:
|
|
if which('git') is None:
|
|
raise RuntimeError('git not found.')
|
|
|
|
return subprocess.run([
|
|
'git',
|
|
'diff',
|
|
'--color',
|
|
'--word-diff=plain',
|
|
'--word-diff-regex=.',
|
|
'--ignore-space-change',
|
|
'--ignore-blank-lines',
|
|
'--exit-code',
|
|
file_a,
|
|
file_b,
|
|
], encoding='utf8', check=False).returncode
|