aboutsummaryrefslogtreecommitdiff
path: root/src/sync.py
blob: 822104f717ccfc35082ebb2824787c2457cd92b0 (plain)
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
from common import *
import copy

def sync_obj(repo_name: str) -> str:
    if not repo_name in tracked:
        return ""

    cmds = ""
    for p in tracked[repo_name]:
        cmds += str(copy.copy([{"path":p, "repo": repo_name, "full_path": os.path.join(REPO_LOC, repo_name, p)}]))
    return cmds

def sync(sync_repos: list[repo_pair]) -> None:
    cmds = ""
    for r in sync_repos:
        print(r)
        full_path = os.path.join(REPO_LOC, r["name"])
        if os.path.isdir(full_path):

            old_hash = subprocess.getoutput(f"cd {full_path} && git rev-parse HEAD")
            os.system(f"cd {full_path} && git pull --quiet")

            new_hash = subprocess.getoutput(f"cd {full_path} && git rev-parse HEAD")
            
            if old_hash == new_hash:
                print(f"{r['name']}: up to date")
            else:
                print(f"{r['name']}: {new_hash}")
 
        else:
            os.system(f"cd {REPO_LOC} && git clone {r['url']} {r['name']}")
            new_hash = subprocess.getoutput(f"cd {full_path} && git rev-parse HEAD")

            print(f"{r['name']}: {new_hash}")

        if questionary.confirm("would you like to sync all tracked packages, from this repo?").ask():
            cmds += sync_obj(r["name"])

    if cmds != "":
        eexec(cmds)