From 836c85e77e57e14101e90b9c800cc5c89bcddc00 Mon Sep 17 00:00:00 2001 From: Arjan Molenaar Date: Tue, 3 Oct 2023 14:25:49 +0200 Subject: [PATCH 1/3] fix: use shallow clones for backups --- t4c/backup.py | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/t4c/backup.py b/t4c/backup.py index 35ba503d..281133e2 100644 --- a/t4c/backup.py +++ b/t4c/backup.py @@ -140,28 +140,40 @@ def clone_git_repository() -> pathlib.Path: git_dir.mkdir(exist_ok=True) log.debug("Cloning git repository...") - subprocess.run( - ["git", "clone", os.environ["GIT_REPO_URL"], "/tmp/git"], - check=True, - env={ - "GIT_USERNAME": os.getenv("GIT_USERNAME", ""), - "GIT_PASSWORD": os.getenv("GIT_PASSWORD", ""), - "GIT_ASKPASS": "/etc/git_askpass.py", - }, - ) + env = { + "GIT_USERNAME": os.getenv("GIT_USERNAME", ""), + "GIT_PASSWORD": os.getenv("GIT_PASSWORD", ""), + "GIT_ASKPASS": "/etc/git_askpass.py", + } + try: subprocess.run( - ["git", "switch", os.environ["GIT_REPO_BRANCH"]], + [ + "git", + "clone", + "--depth=1", + f"--branch={os.environ['GIT_REPO_BRANCH']}", + os.environ["GIT_REPO_URL"], + "/tmp/git", + ], check=True, cwd=git_dir, + env=env, ) except subprocess.CalledProcessError as e: print(e.returncode) if e.returncode == 128: subprocess.run( - ["git", "switch", "-c", os.environ["GIT_REPO_BRANCH"]], + [ + "git", + "clone", + "--depth=1", + os.environ["GIT_REPO_URL"], + "/tmp/git", + ], check=True, cwd=git_dir, + env=env, ) else: raise e From e9a4e241aaf39fe477999e6dc0b387c60912636c Mon Sep 17 00:00:00 2001 From: Arjan Molenaar Date: Fri, 13 Oct 2023 14:16:12 +0200 Subject: [PATCH 2/3] fix: make sure we always push HEAD --- t4c/backup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t4c/backup.py b/t4c/backup.py index 281133e2..2ee281aa 100644 --- a/t4c/backup.py +++ b/t4c/backup.py @@ -280,7 +280,7 @@ def git_commit_and_push(git_dir: pathlib.Path) -> None: ) subprocess.run( - ["git", "push", "origin", os.environ["GIT_REPO_BRANCH"]], + ["git", "push", "origin", f"HEAD:{os.environ['GIT_REPO_BRANCH']}"], check=True, cwd=git_dir, env={ From 38fa34da45266e880d6dba5e07817574abeb88fe Mon Sep 17 00:00:00 2001 From: Arjan Molenaar Date: Fri, 13 Oct 2023 14:29:23 +0200 Subject: [PATCH 3/3] fix: remove unneeded print statement --- t4c/backup.py | 1 - 1 file changed, 1 deletion(-) diff --git a/t4c/backup.py b/t4c/backup.py index 2ee281aa..39788527 100644 --- a/t4c/backup.py +++ b/t4c/backup.py @@ -161,7 +161,6 @@ def clone_git_repository() -> pathlib.Path: env=env, ) except subprocess.CalledProcessError as e: - print(e.returncode) if e.returncode == 128: subprocess.run( [