git.bzl: correctly quote shallow_since

...while still accepting that the parameter might be missing; in the
latter case, an empty argument was added, causing that invocation of
git to fail. Note, however, that the problem is of purely aesthetic
nature, as
- the empty argument would only be added if no information about
  shallow cloning can is available
- upon error, a retry without the shallow information would be made
  anyway to support older versions of git.
Nevertheless, let's not call processes in a way we know is bound to
fail; do this by moving the necessary quoting to the definition of
the "shallow" variable, rather than at its interpolation into the
shell command.

Fixes #8384.

Change-Id: Id47e2c511678018c48686ec17ab03a59486bcb84
PiperOrigin-RevId: 250891894
diff --git a/tools/build_defs/repo/git.bzl b/tools/build_defs/repo/git.bzl
index 22692ba..756bd54 100644
--- a/tools/build_defs/repo/git.bzl
+++ b/tools/build_defs/repo/git.bzl
@@ -38,7 +38,7 @@
             fail("shallow_since not allowed if a tag is specified; --depth=1 will be used for tags")
         if ctx.attr.branch:
             fail("shallow_since not allowed if a branch is specified; --depth=1 will be used for branches")
-        shallow = "--shallow-since=%s" % ctx.attr.shallow_since
+        shallow = "--shallow-since='%s'" % ctx.attr.shallow_since
 
     ctx.report_progress("Cloning %s of %s" % (ref, ctx.attr.remote))
     if (ctx.attr.verbose):
@@ -55,10 +55,10 @@
 ( cd {working_dir} &&
     if ! ( cd '{dir_link}' && [[ "$(git rev-parse --git-dir)" == '.git' ]] ) >/dev/null 2>&1; then
       rm -rf '{directory}' '{dir_link}'
-      git clone '{shallow}' '{remote}' '{directory}' || git clone '{remote}' '{directory}'
+      git clone {shallow} '{remote}' '{directory}' || git clone '{remote}' '{directory}'
     fi
     git -C '{directory}' reset --hard {ref} || \
-    ((git -C '{directory}' fetch '{shallow}' origin {ref}:{ref} || \
+    ((git -C '{directory}' fetch {shallow} origin {ref}:{ref} || \
       git -C '{directory}' fetch origin {ref}:{ref}) && git -C '{directory}' reset --hard {ref})
       git -C '{directory}' clean -xdf )
   """.format(