-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit.py
More file actions
28 lines (21 loc) · 943 Bytes
/
Copy pathgit.py
File metadata and controls
28 lines (21 loc) · 943 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from typing import Set
from .subprocess import read_and_display
async def get_first_commit_hash(cwd: str) -> str:
"""..."""
cmd = ['git', 'rev-list', '--max-parents=0', 'HEAD']
_, stdout, _ = await read_and_display(cmd, cwd=cwd)
hash: str = stdout.decode().strip()
return hash
async def get_changed_files_between_commits(cwd: str, before_commit: str, after_comit='HEAD', location: str = None) -> Set[str]:
"""Get changed files between commits without duplicates
example:
>>> git log --format='' --name-only 526b944024cd363a0748f2df33702dde748d8fae..HEAD pages/miui/updates/ | sort -u
"""
cmd = ['git', 'log', '--format=', '--name-only', f'{before_commit}..{after_comit}']
if location:
cmd.append(location)
_, stdout, _ = await read_and_display(cmd, cwd=cwd)
if stdout:
files = stdout.decode().strip().split('\n')
return set(files)
return set([])