|
1 | 1 | import type { TemplateConfig } from "../domain.js" |
| 2 | +import { renderEntrypointGitPostPushWrapperInstall } from "./git-post-push-wrapper.js" |
2 | 3 |
|
3 | 4 | const renderAuthLabelResolution = (): string => |
4 | 5 | String.raw`# 2) Ensure GitHub auth vars are available for SSH sessions. |
|
289 | 290 | EOF |
290 | 291 | chmod 0755 "$POST_PUSH_ACTION" |
291 | 292 |
|
292 | | -# 5.5) Install git wrapper so post-push actions run for normal git push invocations. |
293 | | -# Git has no client-side post-push hook, so core.hooksPath alone is insufficient. |
294 | | -GIT_WRAPPER_BIN="/usr/local/bin/git" |
295 | | -GIT_REAL_BIN="$(type -aP git | awk -v wrapper="$GIT_WRAPPER_BIN" '$0 != wrapper { print; exit }')" |
296 | | -if [[ -n "$GIT_REAL_BIN" ]]; then |
297 | | - cat <<'EOF' > "$GIT_WRAPPER_BIN" |
298 | | -#!/usr/bin/env bash |
299 | | -set -euo pipefail |
300 | | -
|
301 | | -# docker-git managed git wrapper |
302 | | -DOCKER_GIT_REAL_GIT_BIN="__DOCKER_GIT_REAL_BIN__" |
303 | | -DOCKER_GIT_POST_PUSH_ACTION="/opt/docker-git/hooks/post-push" |
304 | | -
|
305 | | -docker_git_git_subcommand() { |
306 | | - local expect_value="0" |
307 | | - local arg="" |
308 | | - for arg in "$@"; do |
309 | | - if [[ "$expect_value" == "1" ]]; then |
310 | | - expect_value="0" |
311 | | - continue |
312 | | - fi |
313 | | -
|
314 | | - case "$arg" in |
315 | | - --help|-h|--version|--html-path|--man-path|--info-path|--list-cmds|--list-cmds=*) |
316 | | - return 1 |
317 | | - ;; |
318 | | - -c|-C|--git-dir|--work-tree|--namespace|--exec-path|--super-prefix|--config-env) |
319 | | - expect_value="1" |
320 | | - continue |
321 | | - ;; |
322 | | - --git-dir=*|--work-tree=*|--namespace=*|--exec-path=*|--super-prefix=*|--config-env=*|--bare|--no-pager|--paginate|--literal-pathspecs|--no-literal-pathspecs|--glob-pathspecs|--noglob-pathspecs|--icase-pathspecs|--no-optional-locks|--no-lazy-fetch) |
323 | | - continue |
324 | | - ;; |
325 | | - --) |
326 | | - return 1 |
327 | | - ;; |
328 | | - -*) |
329 | | - continue |
330 | | - ;; |
331 | | - *) |
332 | | - printf "%s" "$arg" |
333 | | - return 0 |
334 | | - ;; |
335 | | - esac |
336 | | - done |
337 | | -
|
338 | | - return 1 |
339 | | -} |
340 | | -
|
341 | | -docker_git_git_push_is_dry_run() { |
342 | | - local expect_value="0" |
343 | | - local parsing_push_args="0" |
344 | | - local arg="" |
345 | | -
|
346 | | - for arg in "$@"; do |
347 | | - if [[ "$parsing_push_args" == "0" ]]; then |
348 | | - if [[ "$expect_value" == "1" ]]; then |
349 | | - expect_value="0" |
350 | | - continue |
351 | | - fi |
352 | | -
|
353 | | - case "$arg" in |
354 | | - -c|-C|--git-dir|--work-tree|--namespace|--exec-path|--super-prefix|--config-env) |
355 | | - expect_value="1" |
356 | | - continue |
357 | | - ;; |
358 | | - --git-dir=*|--work-tree=*|--namespace=*|--exec-path=*|--super-prefix=*|--config-env=*|--bare|--no-pager|--paginate|--literal-pathspecs|--no-literal-pathspecs|--glob-pathspecs|--noglob-pathspecs|--icase-pathspecs|--no-optional-locks|--no-lazy-fetch) |
359 | | - continue |
360 | | - ;; |
361 | | - push) |
362 | | - parsing_push_args="1" |
363 | | - continue |
364 | | - ;; |
365 | | - esac |
366 | | -
|
367 | | - continue |
368 | | - fi |
369 | | -
|
370 | | - case "$arg" in |
371 | | - --) |
372 | | - break |
373 | | - ;; |
374 | | - --dry-run|-n) |
375 | | - return 0 |
376 | | - ;; |
377 | | - esac |
378 | | - done |
379 | | -
|
380 | | - return 1 |
381 | | -} |
382 | | -
|
383 | | -docker_git_post_push_action() { |
384 | | - if [[ "${"${"}DOCKER_GIT_SKIP_POST_PUSH_ACTION:-}" == "1" ]]; then |
385 | | - return 0 |
386 | | - fi |
387 | | -
|
388 | | - if [[ -x "$DOCKER_GIT_POST_PUSH_ACTION" ]]; then |
389 | | - DOCKER_GIT_SKIP_POST_PUSH_ACTION=1 "$DOCKER_GIT_POST_PUSH_ACTION" || true |
390 | | - fi |
391 | | -} |
392 | | -
|
393 | | -subcommand="" |
394 | | -if subcommand="$(docker_git_git_subcommand "$@")" && [[ "$subcommand" == "push" ]]; then |
395 | | - if "$DOCKER_GIT_REAL_GIT_BIN" "$@"; then |
396 | | - status=0 |
397 | | - else |
398 | | - status=$? |
399 | | - fi |
400 | | -
|
401 | | - if [[ "$status" -eq 0 ]] && ! docker_git_git_push_is_dry_run "$@"; then |
402 | | - docker_git_post_push_action |
403 | | - fi |
404 | | -
|
405 | | - exit "$status" |
406 | | -fi |
407 | | -
|
408 | | -exec "$DOCKER_GIT_REAL_GIT_BIN" "$@" |
409 | | -EOF |
410 | | - sed -i "s#__DOCKER_GIT_REAL_BIN__#$GIT_REAL_BIN#g" "$GIT_WRAPPER_BIN" || true |
411 | | - chmod 0755 "$GIT_WRAPPER_BIN" || true |
412 | | -fi |
| 293 | +${renderEntrypointGitPostPushWrapperInstall()} |
413 | 294 |
|
414 | 295 | git config --system core.hooksPath "$HOOKS_DIR" || true |
415 | 296 | git config --global core.hooksPath "$HOOKS_DIR" || true` |
|
0 commit comments