Skip to content

Commit

Permalink
fix: use shallow clones for backups
Browse files Browse the repository at this point in the history
  • Loading branch information
amolenaar committed Oct 3, 2023
1 parent 233b0d5 commit 836c85e
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions t4c/backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 836c85e

Please sign in to comment.