aboutsummaryrefslogtreecommitdiff
path: root/reposync.py
blob: 083ef74f52d12342d3ab7fc75e2f6c7e3479ee3b (plain) (blame)
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
#!/usr/bin/python3
from git import Repo
from datetime import datetime
import os 

repoFile = open("repositories.txt", "r")

while(True):
	line = repoFile.readline()
	if not line:
		break

	line = line.strip()
	now = datetime.now().strftime("[%H:%M:%S] ")
	if not os.path.isdir(line):
		print("\033[0;31m%s\033[0;0m \033[0;34m%s\033[0;0m is not a directory!"%(now, line))
		continue

	repo = Repo(line)
	if not repo.bare:
		branch = repo.active_branch

		# Thanks to https://stackoverflow.com/a/65535263/12036073
		if list(repo.iter_commits(f'{branch}..{branch}@{{u}}')):
			print("\033[0;31m%s\033[0;34m%s\033[0;0m\'s origin was updated, pulling..."%(now, line))
			repo.remotes.origin.pull()
		else:
			print("\033[0;32m%s\033[0;34m%s\033[0;0m is up to date"%(now, line))
	else:
		print("\033[0;31m%s\033[0;0m Repository \033[0;34m%s\033[0;0m must not be bare!"%(now, line))

repoFile.close()