From 136e6bc26241669132382aacaeb1e18d398094f3 Mon Sep 17 00:00:00 2001
From: TravisCarden <traviscarden@236758.no-reply.drupal.org>
Date: Mon, 29 Aug 2022 17:19:51 +0000
Subject: [PATCH] Issue #3306600 by TravisCarden, phenaproxima, rahul_: Speed
 up setup_local_dev.sh Drupal core clone

---
 DEVELOPING.md              | 8 ++++++++
 scripts/setup_local_dev.sh | 7 ++++++-
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/DEVELOPING.md b/DEVELOPING.md
index 8b8d6daffb..9a8e374539 100644
--- a/DEVELOPING.md
+++ b/DEVELOPING.md
@@ -40,10 +40,18 @@ Several details of your setup can be customized via environment variables. Set t
 
 ```shell
 DRUPAL_CORE_BRANCH="9.5.x" # The branch of Drupal core that will be installed.
+DRUPAL_CORE_SHALLOW_CLONE="TRUE" # Whether or not to do a "shallow clone" of Drupal core. (Defaults to TRUE.) See note below.
 AUTOMATIC_UPDATES_BRANCH="8.x-2.x" # The branch of the Automatic Updates module that will be installed.
 SITE_DIRECTORY="auto-updates-dev" # The path to the directory where the dev environment will be installed.
 ```
 
+Note: A shallow Git clone is much smaller and therefore faster, but it removes the ability to do debugging operations such as `git bisect` or `git blame`. To recover these abilities, [you can convert your repository to a full clone after the fact](https://stackoverflow.com/questions/6802145/how-to-convert-a-git-shallow-clone-to-a-full-clone):
+
+```shell
+cd auto-updates-dev
+git fetch --unshallow
+```
+
 ### Alternative setup options
 You can download the setup script first to review its contents or modify it before running it:
 
diff --git a/scripts/setup_local_dev.sh b/scripts/setup_local_dev.sh
index dd009928f1..d3fa24ec13 100755
--- a/scripts/setup_local_dev.sh
+++ b/scripts/setup_local_dev.sh
@@ -16,6 +16,7 @@
 # your terminal session) to override their default values.
 # @see https://www.serverlab.ca/tutorials/linux/administration-linux/how-to-set-environment-variables-in-linux/
 DRUPAL_CORE_BRANCH=${DRUPAL_CORE_BRANCH:="9.5.x"}
+DRUPAL_CORE_SHALLOW_CLONE=${DRUPAL_CORE_SHALLOW_CLONE:="TRUE"}
 AUTOMATIC_UPDATES_BRANCH=${AUTOMATIC_UPDATES_BRANCH:="8.x-2.x"}
 SITE_DIRECTORY=${SITE_DIRECTORY:="auto_updates_dev"}
 SITE_HOST=${SITE_HOST:="$SITE_DIRECTORY.test"}
@@ -49,7 +50,7 @@ fi
 # Prompt for confirmation.
 cat << WARNING
 You are about to create an Automatic Updates development environment at "$SITE_DIRECTORY". This will download
-as much as 400 MB of data and take approximately one minute to complete, depending on your Internet connection.
+as much as 100 MB of data and may take several minutes to complete, depending on your Internet connection.
 
 WARNING
 read -p "Do you want to continue? [yN] " -n 1 -r
@@ -61,9 +62,13 @@ fi
 echo
 
 # Clone Drupal core.
+if [[ "$DRUPAL_CORE_SHALLOW_CLONE" == "TRUE" ]]; then
+  DRUPAL_CORE_CLONE_DEPTH="--depth 1"
+fi
 git clone \
   https://git.drupalcode.org/project/drupal.git \
   --branch "$DRUPAL_CORE_BRANCH" \
+  $DRUPAL_CORE_CLONE_DEPTH \
   "$SITE_DIRECTORY"
 
 cd "$SITE_DIRECTORY" || exit 1
-- 
GitLab