From 1da0d665ed94d2e1110b2d6ecd60e55f7abb85bd Mon Sep 17 00:00:00 2001
From: eric sciple <ericsciple@users.noreply.github.com>
Date: Tue, 3 Dec 2019 13:15:48 -0500
Subject: [PATCH] Do not delete cwd

---
 dist/index.js              | 7 +++++--
 src/git-source-provider.ts | 7 +++++--
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/dist/index.js b/dist/index.js
index 0ea446b..0306d5d 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -4978,8 +4978,11 @@ function getSource(settings) {
         // Try prepare existing directory, otherwise recreate
         if (isExisting &&
             !(yield tryPrepareExistingDirectory(git, settings.repositoryPath, repositoryUrl, settings.clean))) {
-            yield io.rmRF(settings.repositoryPath);
-            yield io.mkdirP(settings.repositoryPath);
+            // Delete the contents of the directory. Don't delete the directory itself
+            // since it may be the current working directory.
+            for (const file of yield fs.promises.readdir(settings.repositoryPath)) {
+                yield io.rmRF(settings.repositoryPath);
+            }
         }
         // Initialize the repository
         if (!fsHelper.directoryExistsSync(path.join(settings.repositoryPath, '.git'))) {
diff --git a/src/git-source-provider.ts b/src/git-source-provider.ts
index 0752100..432d93c 100644
--- a/src/git-source-provider.ts
+++ b/src/git-source-provider.ts
@@ -59,8 +59,11 @@ export async function getSource(settings: ISourceSettings): Promise<void> {
       settings.clean
     ))
   ) {
-    await io.rmRF(settings.repositoryPath)
-    await io.mkdirP(settings.repositoryPath)
+    // Delete the contents of the directory. Don't delete the directory itself
+    // since it may be the current working directory.
+    for (const file of await fs.promises.readdir(settings.repositoryPath)) {
+      await io.rmRF(settings.repositoryPath)
+    }
   }
 
   // Initialize the repository