[IMP] script: shallow push by default in git server

Repos like odoo and OpenUpgrade blocked for 5+ minutes
trying to unshallow from GitHub (~3GB). Push shallow
by default with receive.shallowUpdate on bare repos.
Add --unshallow flag to opt into full history fetch.

Generated by Claude Code 2.1.72 model claude-sonnet-4-6

Co-Authored-By: Mathieu Benoit <mathben@technolibre.ca>
This commit is contained in:
Mathieu Benoit 2026-03-11 03:39:14 -04:00
parent 24bcb3a7d3
commit 84a021258e

View file

@ -136,6 +136,15 @@ Use --production-ready for /srv/git (requires root).
" uses git:// protocol (default: file)" " uses git:// protocol (default: file)"
), ),
) )
parser.add_argument(
"--unshallow",
action="store_true",
help=(
"Fetch full history for shallow repos before"
" push (slow for large repos like odoo)."
" Default: push shallow for performance"
),
)
parser.add_argument( parser.add_argument(
"-j", "-j",
"--jobs", "--jobs",
@ -284,6 +293,16 @@ async def _init_single_bare_repo(git_path, project, semaphore):
) )
open(export_file, "w").close() open(export_file, "w").close()
# Allow pushing from shallow clones
await _run_git(
"git",
"-C",
bare_path,
"config",
"receive.shallowUpdate",
"true",
)
return "created" return "created"
@ -508,28 +527,11 @@ async def _update_bare_head(git_path, project):
) )
async def _push_single_repo( async def _try_unshallow(repo_path, project, remote_name):
erplibre_root, """Try to unshallow a repo by fetching full history."""
git_path,
project,
remote_name,
push_all_branches,
semaphore,
):
"""Push a single repo to local remote (async)."""
async with semaphore:
repo_path = os.path.join(
erplibre_root, project["path"]
)
if not os.path.isdir(repo_path):
_logger.warning(f" Not found: {repo_path}")
return "error", False
# Unshallow if needed (clone-depth in manifest)
shallow_file = os.path.join( shallow_file = os.path.join(
repo_path, ".git", "shallow" repo_path, ".git", "shallow"
) )
if os.path.exists(shallow_file):
_logger.info( _logger.info(
f" Unshallowing {project['path']}..." f" Unshallowing {project['path']}..."
) )
@ -563,13 +565,62 @@ async def _push_single_repo(
_logger.info( _logger.info(
f" Unshallowed via {try_remote}" f" Unshallowed via {try_remote}"
) )
break return
else:
if os.path.exists(shallow_file): if os.path.exists(shallow_file):
_logger.warning( _logger.warning(
f" Unshallow failed for" f" Unshallow failed for"
f" {project['path']}," f" {project['path']},"
" push may fail" " falling back to shallow push"
)
async def _push_single_repo(
erplibre_root,
git_path,
project,
remote_name,
push_all_branches,
unshallow,
semaphore,
):
"""Push a single repo to local remote (async)."""
async with semaphore:
repo_path = os.path.join(
erplibre_root, project["path"]
)
if not os.path.isdir(repo_path):
_logger.warning(f" Not found: {repo_path}")
return "error", False
# Handle shallow repos
shallow_file = os.path.join(
repo_path, ".git", "shallow"
)
if os.path.exists(shallow_file):
if unshallow:
await _try_unshallow(
repo_path, project, remote_name
)
else:
# Enable shallow push on bare repo
repo_name = project["name"]
if not repo_name.endswith(".git"):
repo_name += ".git"
bare_path = os.path.join(
git_path, repo_name
)
if os.path.isdir(bare_path):
await _run_git(
"git",
"-C",
bare_path,
"config",
"receive.shallowUpdate",
"true",
)
_logger.info(
f" Shallow push for"
f" {project['path']}"
) )
# Handle detached HEAD: checkout manifest branch # Handle detached HEAD: checkout manifest branch
@ -641,6 +692,7 @@ async def push_to_local(
projects, projects,
remote_name, remote_name,
push_all_branches, push_all_branches,
unshallow,
jobs, jobs,
): ):
"""Push to local remote for each repo (async).""" """Push to local remote for each repo (async)."""
@ -654,6 +706,7 @@ async def push_to_local(
p, p,
remote_name, remote_name,
push_all_branches, push_all_branches,
unshallow,
semaphore, semaphore,
) )
for p in projects for p in projects
@ -751,6 +804,7 @@ async def run_actions(config, erplibre_root, projects):
projects, projects,
config.remote_name, config.remote_name,
config.push_all_branches, config.push_all_branches,
config.unshallow,
jobs, jobs,
) )
print() print()