Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgit.py
More file actions
Latest commit
58 lines (43 loc) · 1.93 KB
/
Copy pathgit.py
File metadata and controls
58 lines (43 loc) · 1.93 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python3
"""A wrapper for commandline Git tools"""
importlogging
frompathlibimportPath
fromsubprocessimportCalledProcessError
fromtypingimportList, Optional, FrozenSet
fromutils.data_processingimportchecked_subprocess, remove_none
defgit(*args, **kwargs) ->str:
try:
result=checked_subprocess(['git'] +list(args), **kwargs)
exceptCalledProcessErrorase:
logging.error(e.args)
logging.error(e.stderr)
raisee
returnresult.stdoutifresult.stdoutelseresult.stderr
defgit_modified_files(from_commit: str, to_commit: str) ->List[Path]:
defget_modified_path(status_and_name: str) ->Optional[Path]:
"""
Returns the path relative to the repo root (or none, if this status doesn't represent a modification).
Examples of what status_and_name might look like:
M _converters_/ObjConverter
A resources/android/library/scenery_packs/sim objects/apt_vehicles/pushback/GT110_NML.etc
R100 setup_git.sh scripts/setup_git.sh
D resources/common_ios/apt_nav_dat/earth_awy.dat
"""
ifstatus_and_name[0] =='M':
returnPath(status_and_name.replace('M', '', 1).strip())
else:
returnNone
returnremove_none(
map(get_modified_path,
git('diff', '--name-status', from_commit, to_commit).splitlines(keepends=False))
)
defgit_current_branch() ->str:
returngit('rev-parse', '--abbrev-ref', 'HEAD').strip()
defgit_all_known_tags() ->FrozenSet[str]:
returnfrozenset(git('tag').strip().splitlines(keepends=False))
defgit_current_tags() ->List[str]:
returngit_tags_for_commit('HEAD')
defgit_tags_for_commit(sha_or_name: str) ->List[str]:
returngit('tag', '-l', '--points-at', sha_or_name).strip().split()
defgit_create_tag(new_tag: str, capture_stdout: bool=True):
git('tag', new_tag, capture_stdout=capture_stdout)