mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-06 22:54:16 +02:00
[arch] improvement -> history/downgrade considering the repository commit + bug fixes
This commit is contained in:
@@ -2,15 +2,12 @@ from datetime import datetime
|
||||
from typing import List, Tuple, Optional
|
||||
|
||||
from bauh.commons import system
|
||||
from bauh.commons.system import new_subprocess
|
||||
from bauh.commons.system import new_subprocess, SimpleProcess
|
||||
|
||||
|
||||
def is_installed() -> bool:
|
||||
try:
|
||||
new_subprocess(['git', '--version'])
|
||||
return True
|
||||
except FileNotFoundError:
|
||||
return False
|
||||
code, _ = system.execute(cmd='which git', output=False)
|
||||
return code == 0
|
||||
|
||||
|
||||
def list_commits(proj_dir: str) -> List[dict]:
|
||||
@@ -30,6 +27,17 @@ def list_commits(proj_dir: str) -> List[dict]:
|
||||
return commits
|
||||
|
||||
|
||||
def get_current_commit(repo_path: str) -> Optional[str]:
|
||||
code, output = system.execute(cmd='git log -1 --format=%H', shell=True, cwd=repo_path)
|
||||
|
||||
if code == 0:
|
||||
for line in output.strip().split('\n'):
|
||||
line_strip = line.strip()
|
||||
|
||||
if line_strip:
|
||||
return line_strip
|
||||
|
||||
|
||||
def log_shas_and_timestamps(repo_path: str) -> Optional[List[Tuple[str, int]]]:
|
||||
code, output = system.execute(cmd='git log --format="%H %at"', shell=True, cwd=repo_path)
|
||||
|
||||
@@ -43,3 +51,12 @@ def log_shas_and_timestamps(repo_path: str) -> Optional[List[Tuple[str, int]]]:
|
||||
logs.append((line_split[0].strip(), int(line_split[1].strip())))
|
||||
|
||||
return logs
|
||||
|
||||
|
||||
def clone_as_process(url: str, cwd: Optional[str], depth: int = -1) -> SimpleProcess:
|
||||
cmd = ['git', 'clone', url]
|
||||
|
||||
if depth > 0:
|
||||
cmd.append('--depth={}'.format(depth))
|
||||
|
||||
return SimpleProcess(cmd=cmd, cwd=cwd)
|
||||
|
||||
Reference in New Issue
Block a user