-
Notifications
You must be signed in to change notification settings - Fork 0
/
version.py
52 lines (48 loc) 路 1.71 KB
/
version.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
40
41
42
43
44
45
46
47
48
49
50
51
52
"""For version control."""
import logging
logging.getLogger().setLevel(logging.INFO)
def git_commit(
repop: str,
suffix_message: str='',
force=False,
):
"""Version control.
Args:
repop (str): path to the repository.
suffix_message (str, optional): add suffix to the version (commit) message. Defaults to ''.
"""
from git import Repo
from roux.lib.sys import input_binary
repo=Repo(repop,search_parent_directories=True)
logging.info(f"Active branch: {repo.active_branch.name}")
def commit(repo):
logging.info("Modified files:")
logging.info([o.b_path for o in repo.index.diff(None)])
if not force:
if not input_binary("Continue? [y/n]"):
return
repo.git.add(update=True)
repo.index.commit('auto-update'+suffix_message)
logging.info('git-committed')
def push(repo):
logging.info(f"Remotes: {','.join([o.name for o in repo.remotes])}")
if len(repo.untracked_files)!=0:
logging.info(f'{len(repo.untracked_files)} untracked file/s in the repo.')
if len(repo.untracked_files) < 100:
logging.info(repo.untracked_files)
yes=input_binary("add all of them? [y/n]")
if yes:
repo.git.add(repo.untracked_files)
else:
yes=input_binary("add none of them? [y/n]")
if yes:
commit(repo)
else:
repo.git.add(eval(input('list of files in py syntax:')))
if suffix_message=='':
if not force:
suffix_message=input('commit message:')
repo.index.commit('manual-update'+suffix_message)
commit(repo)
push(repo)
return