aboutsummaryrefslogtreecommitdiff
path: root/reposync.py
blob: 5458cd5fdd04bc721814cd6bac4aea7ef3ddce0c (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
33
34
#!/usr/bin/python3
from git import Repo
from datetime import datetime
import os 

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

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

	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)
	for remote in repo.remotes:
		remote.fetch()

	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(f'\033[0;31m{now}\033[0;34m{line}\033[0;0m\'s origin was updated, pulling...')
			repo.remotes.origin.pull()
		else:
			print(f'\033[0;32m{now}\033[0;34m{line}\033[0;0m is up to date')
	else:
		print(f'\033[0;31m{now}\033[0;0m Repository \033[0;34m{line}\033[0;0m must not be bare!')

repoFile.close()