Skip to content

Commit

Permalink
Merge pull request #212 from DSD-DBS/backup-shallow-clone
Browse files Browse the repository at this point in the history
fix: use shallow clones for backups
  • Loading branch information
MoritzWeber0 authored Oct 16, 2023
2 parents 97f2b17 + 38fa34d commit b2a8239
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions t4c/backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,28 +140,39 @@ 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 Expand Up @@ -268,7 +279,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={
Expand Down

0 comments on commit b2a8239

Please sign in to comment.