Automated rollback of commit 03ee90a351737979e3a78b48f1590ca7da7c54e9.

*** Reason for rollback ***

Causing multiple CI failures:

https://github.com/bazelbuild/bazel/issues/27982

https://buildkite.com/bazel/bazel-at-head-plus-downstream/builds/5143#019b2926-7bd0-4681-9e27-8e904882eab5

*** Original change description ***

list_source_repository: fix source not updating after deletion

Tell the repo rule to watch the workspace and rerun would be the best
way for us to get accurate data.

The repo rule is only used for //src/test/shell/bazel:srcs_test so users
who don't run this test would not have to re-run the repo rule for each
change.

Closes #27938.

PiperOrigin-RevId: 845657127
Change-Id: I09e6b4a41c94fa3aa2cb1c24342925452ae44428
diff --git a/src/test/shell/bazel/list_source_repository.bzl b/src/test/shell/bazel/list_source_repository.bzl
index a57662c..3ad96d1 100644
--- a/src/test/shell/bazel/list_source_repository.bzl
+++ b/src/test/shell/bazel/list_source_repository.bzl
@@ -22,6 +22,13 @@
     workspace = rctx.path(Label("//:BUILD")).dirname
     srcs_excludes = "XXXXXXXXXXXXXX1268778dfsdf4"
 
+    # Depending in ~/.git/logs/HEAD is a trick to depends on something that
+    # change every time the workspace content change.
+    r = rctx.execute(["test", "-f", "%s/.git/logs/HEAD" % workspace])
+    if r.return_code == 0:
+        # We only add the dependency if it exists.
+        unused_var = rctx.path(Label("//:.git/logs/HEAD"))  # pylint: disable=unused-variable
+
     if "SRCS_EXCLUDES" in rctx.os.environ:
         srcs_excludes = rctx.os.environ["SRCS_EXCLUDES"]
     r = rctx.execute(["find", "-L", str(workspace), "-type", "f"])
@@ -41,8 +48,6 @@
 )
 """ % srcs_excludes)
 
-    rctx.watch_tree(workspace)
-
 list_source_repository = repository_rule(
     implementation = _impl,
     environ = ["SRCS_EXCLUDES"],