solidity/scripts/common/git_helpers.py
r0qs ab2d3957cb Add bytecode test for multiple sources compiler at same time
Co-authored-by: Kamil Śliwak <kamil.sliwak@codepoets.it>
2023-09-29 23:17:15 +02:00

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