-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsmartpull.py
More file actions
executable file
·36 lines (33 loc) · 1.26 KB
/
smartpull.py
File metadata and controls
executable file
·36 lines (33 loc) · 1.26 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
#!/usr/bin/python3
from git import Repo
from git.exc import GitCommandError
import logging
logger = logging.getLogger('SmartPull')
logging.basicConfig(format="%(levelname)s:%(message)s", level=logging.INFO)
def main():
file = open('/smart_pull_repos', 'r')
lines = file.readlines()
for line in lines:
repo_path=line.strip()
try:
repo = Repo(repo_path)
initial_commit = repo.commit()
if 'master' in repo.remote().refs:
master_branch = 'master'
else:
master_branch = 'main'
if repo.is_dirty():
logger.warning(f"{repo_path} HEAD is dirty, will only fetch")
repo.remote().fetch()
elif str(repo.active_branch) != master_branch:
logger.warning(f"{repo_path} HEAD pointing to {repo.active_branch}, will only fetch")
repo.remote().fetch()
else:
logger.info(f"{repo_path} HEAD is clean, will pull")
repo.remote().pull(master_branch)
if initial_commit != repo.commit():
logger.warning("master branch updated")
except GitCommandError as err:
logger.error(err)
if __name__ == "__main__":
main()