-
Notifications
You must be signed in to change notification settings - Fork 107
/
_git.py
39 lines (25 loc) · 993 Bytes
/
_git.py
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
29
30
31
32
33
34
35
36
37
38
39
# Copyright (c) Amber Brown, 2015
# See LICENSE for details.
from __future__ import annotations
import os
from subprocess import STDOUT, call, check_output
def remove_files(fragment_filenames: list[str]) -> None:
if fragment_filenames:
call(["git", "rm", "--quiet"] + fragment_filenames)
def stage_newsfile(directory: str, filename: str) -> None:
call(["git", "add", os.path.join(directory, filename)])
def get_remote_branches(base_directory: str) -> list[str]:
output = check_output(
["git", "branch", "-r"], cwd=base_directory, encoding="utf-8", stderr=STDOUT
)
return [branch.strip() for branch in output.strip().splitlines()]
def list_changed_files_compared_to_branch(
base_directory: str, compare_with: str
) -> list[str]:
output = check_output(
["git", "diff", "--name-only", compare_with + "..."],
cwd=base_directory,
encoding="utf-8",
stderr=STDOUT,
)
return output.strip().splitlines()