Supporto Modifiche: stabilizza sync staging Git

This commit is contained in:
michele 2026-03-30 15:35:09 +00:00
parent 53047a955a
commit 46d21e2a9f
4 changed files with 41 additions and 17 deletions

View File

@ -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'));

View File

@ -107,6 +107,5 @@ public function panel(Panel $panel): Panel
->authMiddleware([
Authenticate::class,
]);
}
}

View File

@ -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 |"

View File

@ -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