Skip to content

Commit

Permalink
Preserve .git repository.
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseleite committed Feb 26, 2025
1 parent 17a5f0d commit 1f3021e
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/StarterKits/Exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ protected function clearExportPath()
return $this;
}

$this->files->cleanDirectory($this->exportPath);
$this->preserveGitRepository(function () {
$this->files->cleanDirectory($this->exportPath);
});

return $this;
}
Expand Down Expand Up @@ -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'));
}
}

0 comments on commit 1f3021e

Please sign in to comment.