File tree Expand file tree Collapse file tree 2 files changed +28
-3
lines changed
Expand file tree Collapse file tree 2 files changed +28
-3
lines changed Original file line number Diff line number Diff line change @@ -153,7 +153,9 @@ protected function clearExportPath()
153153 return $ this ;
154154 }
155155
156- $ this ->files ->cleanDirectory ($ this ->exportPath );
156+ $ this ->preserveGitRepository (function () {
157+ $ this ->files ->cleanDirectory ($ this ->exportPath );
158+ });
157159
158160 return $ this ;
159161 }
@@ -257,4 +259,20 @@ protected function exportPackage(): self
257259
258260 return $ this ;
259261 }
262+
263+ /**
264+ * Prevent filesystem callback from affecting .git repository.
265+ */
266+ protected function preserveGitRepository ($ callback ): void
267+ {
268+ $ this ->files ->makeDirectory (storage_path ('statamic/tmp ' ), 0777 , true , true );
269+
270+ $ this ->files ->moveDirectory ($ this ->exportPath .'/.git ' , storage_path ('statamic/tmp/.git ' ));
271+
272+ $ callback ();
273+
274+ $ this ->files ->moveDirectory (storage_path ('statamic/tmp/.git ' ), $ this ->exportPath .'/.git ' );
275+
276+ $ this ->files ->deleteDirectory (storage_path ('statamic/tmp ' ));
277+ }
260278}
Original file line number Diff line number Diff line change @@ -173,7 +173,11 @@ public function it_can_clear_target_export_path_with_clear_option()
173173 base_path ('two ' ),
174174 ]);
175175
176- // Imagine this exists from previous export
176+ // Imagine we already have a target a git repo
177+ $ this ->files ->makeDirectory ($ this ->targetPath ('.git ' ), 0777 , true , true );
178+ $ this ->files ->put ($ this ->targetPath ('.git/config ' ), 'Config. ' );
179+
180+ // And imagine this exists from previous export
177181 $ this ->files ->makeDirectory ($ this ->exportPath ('one ' ), 0777 , true , true );
178182 $ this ->files ->put ($ this ->exportPath ('one/file.md ' ), 'One. ' );
179183
@@ -195,10 +199,13 @@ public function it_can_clear_target_export_path_with_clear_option()
195199
196200 $ this ->exportCoolRunnings (['--clear ' => true ]);
197201
198- // But 'one' folder should exist after exporting with `--clear` option
202+ // Our 'one' folder shouldn't exist after exporting with `--clear` option
199203 $ this ->assertFileDoesNotExist ($ this ->exportPath ('one ' ));
200204 $ this ->assertFileExists ($ this ->exportPath ('two ' ));
201205
206+ // But it should not clear `.git` directory
207+ $ this ->assertFileExists ($ this ->targetPath ('.git/config ' ));
208+
202209 $ this ->exportCoolRunnings ();
203210
204211 $ this ->cleanPaths ($ paths );
You can’t perform that action at this time.
0 commit comments