From 1f3021e8b5ea8271f470ca2d23321c8adabd8237 Mon Sep 17 00:00:00 2001 From: Jesse Leite Date: Wed, 26 Feb 2025 18:18:11 -0500 Subject: [PATCH] Preserve `.git` repository. --- src/StarterKits/Exporter.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/StarterKits/Exporter.php b/src/StarterKits/Exporter.php index f3f635d4cb..fd2bbf0d55 100644 --- a/src/StarterKits/Exporter.php +++ b/src/StarterKits/Exporter.php @@ -153,7 +153,9 @@ protected function clearExportPath() return $this; } - $this->files->cleanDirectory($this->exportPath); + $this->preserveGitRepository(function () { + $this->files->cleanDirectory($this->exportPath); + }); return $this; } @@ -257,4 +259,20 @@ protected function exportPackage(): self return $this; } + + /** + * Prevent filesystem callback from affecting .git repository. + */ + protected function preserveGitRepository($callback): void + { + $this->files->makeDirectory(storage_path('statamic/tmp'), 0777, true, true); + + $this->files->moveDirectory($this->exportPath.'/.git', storage_path('statamic/tmp/.git')); + + $callback(); + + $this->files->moveDirectory(storage_path('statamic/tmp/.git'), $this->exportPath.'/.git'); + + $this->files->deleteDirectory(storage_path('statamic/tmp')); + } }