From 46d21e2a9fee4311be1cfd8bd7acb2357846f8e0 Mon Sep 17 00:00:00 2001 From: michele Date: Mon, 30 Mar 2026 15:35:09 +0000 Subject: [PATCH] Supporto Modifiche: stabilizza sync staging Git --- .../Commands/NetgesconGitSyncCommand.php | 27 +++++++++++++------ .../Filament/AdminFilamentPanelProvider.php | 1 - scripts/ops/netgescon-sync-git-changelog.sh | 21 ++++++++++----- scripts/ops/netgescon-sync-prod-update.sh | 9 ++++++- 4 files changed, 41 insertions(+), 17 deletions(-) diff --git a/app/Console/Commands/NetgesconGitSyncCommand.php b/app/Console/Commands/NetgesconGitSyncCommand.php index 50d4ea8..8a16a5d 100644 --- a/app/Console/Commands/NetgesconGitSyncCommand.php +++ b/app/Console/Commands/NetgesconGitSyncCommand.php @@ -57,7 +57,7 @@ public function handle(): int return self::FAILURE; } - $dirtyResult = Process::path($repoPath)->run(['git', 'status', '--porcelain']); + $dirtyResult = Process::path($repoPath)->run($this->gitCommandArgs($repoPath, ['status', '--porcelain'])); $isDirty = trim((string) $dirtyResult->output()) !== ''; if ($isDirty && ! $force && ! $deploySync) { @@ -82,7 +82,7 @@ public function handle(): int $fetch = Process::path($repoPath) ->timeout(1800) - ->run(['git', 'fetch', $remote]); + ->run($this->gitCommandArgs($repoPath, ['fetch', $remote])); if (! $fetch->successful()) { $this->line(trim((string) ($fetch->errorOutput() !== '' ? $fetch->errorOutput() : $fetch->output()))); @@ -114,7 +114,7 @@ public function handle(): int $worktreeAdd = Process::path($repoPath) ->timeout(1800) - ->run(['git', 'worktree', 'add', '--force', '--detach', $worktreePath, $remoteRef]); + ->run($this->gitCommandArgs($repoPath, ['worktree', 'add', '--force', '--detach', $worktreePath, $remoteRef])); if (! $worktreeAdd->successful()) { $this->line(trim((string) ($worktreeAdd->errorOutput() !== '' ? $worktreeAdd->errorOutput() : $worktreeAdd->output()))); @@ -135,7 +135,7 @@ public function handle(): int } $cleanupWorktree = static function () use ($repoPath, $worktreePath): void { - Process::path($repoPath)->timeout(1800)->run(['git', 'worktree', 'remove', '--force', $worktreePath]); + Process::path($repoPath)->timeout(1800)->run($this->gitCommandArgs($repoPath, ['worktree', 'remove', '--force', $worktreePath])); if (is_dir($worktreePath)) { File::deleteDirectory($worktreePath); } @@ -184,7 +184,7 @@ public function handle(): int if ($currentBranch !== $branch) { $checkout = Process::path($repoPath) ->timeout(1800) - ->run(['git', 'checkout', $branch]); + ->run($this->gitCommandArgs($repoPath, ['checkout', $branch])); if (! $checkout->successful()) { $this->line(trim((string) ($checkout->errorOutput() !== '' ? $checkout->errorOutput() : $checkout->output()))); @@ -209,7 +209,7 @@ public function handle(): int $pull = Process::path($repoPath) ->timeout(1800) - ->run(['git', 'pull', '--ff-only', $remote, $branch]); + ->run($this->gitCommandArgs($repoPath, ['pull', '--ff-only', $remote, $branch])); if (! $pull->successful()) { $this->line(trim((string) ($pull->errorOutput() !== '' ? $pull->errorOutput() : $pull->output()))); @@ -325,7 +325,7 @@ private function runGit(string $path, array $arguments): ?string { $result = Process::path($path) ->timeout(1800) - ->run(array_merge(['git'], $arguments)); + ->run($this->gitCommandArgs($path, $arguments)); if (! $result->successful()) { return null; @@ -342,12 +342,18 @@ private function resolveSourceRepositoryPath(): ?string trim((string) env('NETGESCON_GIT_SYNC_SOURCE_REPO', '')), '/home/michele/netgescon/netgescon-day0', '/home/michele/netgescon/netgescon-laravel', + storage_path('app/support/git-source'), + '/var/www/netgescon-git-source', '/var/www/netgescon_backup_20250722_220433', '/var/www/netgescon_backup_20250722_215454', ]), static fn(string $path): bool => $path !== '')); foreach ($candidates as $candidate) { - if (is_dir($candidate . '/.git')) { + if (! is_dir($candidate . '/.git')) { + continue; + } + + if ($this->runGit($candidate, ['rev-parse', '--git-dir']) !== null) { return $candidate; } } @@ -355,6 +361,11 @@ private function resolveSourceRepositoryPath(): ?string return null; } + private function gitCommandArgs(string $path, array $arguments): array + { + return array_merge(['git', '-c', 'safe.directory=' . $path], $arguments); + } + private function writeProgress(int $percent, string $message, string $status, ?int $exitCode = null): void { $path = trim((string) $this->option('progress-file')); diff --git a/app/Providers/Filament/AdminFilamentPanelProvider.php b/app/Providers/Filament/AdminFilamentPanelProvider.php index a320c44..cade183 100644 --- a/app/Providers/Filament/AdminFilamentPanelProvider.php +++ b/app/Providers/Filament/AdminFilamentPanelProvider.php @@ -107,6 +107,5 @@ public function panel(Panel $panel): Panel ->authMiddleware([ Authenticate::class, ]); - } } diff --git a/scripts/ops/netgescon-sync-git-changelog.sh b/scripts/ops/netgescon-sync-git-changelog.sh index b856656..11f7d4a 100755 --- a/scripts/ops/netgescon-sync-git-changelog.sh +++ b/scripts/ops/netgescon-sync-git-changelog.sh @@ -35,7 +35,14 @@ while [[ $# -gt 0 ]]; do esac done -[[ -d "$REPO_DIR/.git" ]] || { echo "Repo not found: $REPO_DIR" >&2; exit 1; } +git_repo_ok() { + local repo_dir="$1" + + [[ -d "$repo_dir" ]] || return 1 + git -c "safe.directory=$repo_dir" -C "$repo_dir" rev-parse --git-dir >/dev/null 2>&1 +} + +git_repo_ok "$REPO_DIR" || { echo "Repo not found: $REPO_DIR" >&2; exit 1; } classify() { local msg="$1" @@ -69,16 +76,16 @@ mkdir -p "$(dirname "$OUTPUT_FILE")" echo echo "## Milestone Storico" - if [[ -d "$LEGACY_REPO_DIR/.git" ]]; then - first_line="$(git -C "$LEGACY_REPO_DIR" log --reverse --date=format:'%d/%m/%Y' --pretty=format:'%h|%ad|%s' | head -n 1 || true)" + if git_repo_ok "$LEGACY_REPO_DIR"; then + first_line="$(git -c "safe.directory=$LEGACY_REPO_DIR" -C "$LEGACY_REPO_DIR" log --reverse --date=format:'%d/%m/%Y' --pretty=format:'%h|%ad|%s' | head -n 1 || true)" if [[ -n "$first_line" ]]; then IFS='|' read -r fh fd fs <<< "$first_line" echo "- Prima registrazione Git disponibile: **$fd** - \`$fh\` - $fs" fi - if git -C "$LEGACY_REPO_DIR" cat-file -e 1448a3d^{commit} 2>/dev/null; then - cdate="$(git -C "$LEGACY_REPO_DIR" show -s --date=format:'%d/%m/%Y' --pretty=format:'%ad' 1448a3d)" - cmsg="$(git -C "$LEGACY_REPO_DIR" show -s --pretty=format:'%s' 1448a3d)" + if git -c "safe.directory=$LEGACY_REPO_DIR" -C "$LEGACY_REPO_DIR" cat-file -e 1448a3d^{commit} 2>/dev/null; then + cdate="$(git -c "safe.directory=$LEGACY_REPO_DIR" -C "$LEGACY_REPO_DIR" show -s --date=format:'%d/%m/%Y' --pretty=format:'%ad' 1448a3d)" + cmsg="$(git -c "safe.directory=$LEGACY_REPO_DIR" -C "$LEGACY_REPO_DIR" show -s --pretty=format:'%s' 1448a3d)" echo "- Commit storico dichiarato trovato: **$cdate** - \`1448a3d\` - $cmsg" else echo "- Commit storico dichiarato \`1448a3d\`: non presente nel repository locale corrente (possibile storico esterno)." @@ -93,7 +100,7 @@ mkdir -p "$(dirname "$OUTPUT_FILE")" echo "| Data | Commit | Tipo | Messaggio |" echo "| --- | --- | --- | --- |" - git -C "$REPO_DIR" log --date=format:'%d/%m/%Y' --pretty=format:'%h|%ad|%s' -n "$LIMIT" | while IFS='|' read -r hash date msg; do + git -c "safe.directory=$REPO_DIR" -C "$REPO_DIR" log --date=format:'%d/%m/%Y' --pretty=format:'%h|%ad|%s' -n "$LIMIT" | while IFS='|' read -r hash date msg; do kind="$(classify "$msg")" clean_msg="$(printf '%s' "$msg" | sed 's/|/-/g')" echo "| $date | \`$hash\` | $kind | $clean_msg |" diff --git a/scripts/ops/netgescon-sync-prod-update.sh b/scripts/ops/netgescon-sync-prod-update.sh index 52a14d3..e589dfd 100755 --- a/scripts/ops/netgescon-sync-prod-update.sh +++ b/scripts/ops/netgescon-sync-prod-update.sh @@ -63,14 +63,21 @@ if [[ ! -d "$DST_DIR" || ! -f "$DST_DIR/artisan" ]]; then fi RSYNC_ARGS=( - -avh + -rlvh --update --checksum + --no-perms + --no-owner + --no-group + --omit-dir-times + --no-times --exclude=.git/ --exclude=.env --exclude=storage/ --exclude=node_modules/ --exclude=vendor/ + --exclude=bootstrap/cache/ + --exclude=public/build/ ) if [[ "$DRY_RUN" == "yes" ]]; then