Skip to content

Commit eadda05

Browse files
committed
[bazel] Hotswap deprecated sync command in bazelisk.sh
This command has been deprecated when using Bzlmod. It only works with `WORKSPACE` and hybrid mode. For some reason Bazel completely crashes with a JVM exception when you try to use it rather than printing a nice warning. This commit prints a warning that `sync` is deprecated and swaps the command for `fetch` which has almost identical arguments. This is a temporary measure to prevent breaking contributors who have git post-checkout hooks installed which run `bazel sync --configure`. Signed-off-by: James Wainwright <[email protected]> (cherry picked from commit 654a23f)
1 parent 9c03a5d commit eadda05

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

bazelisk.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,25 @@ function main() {
178178
# We are intentionally using $command_template as a format string.
179179
eval "$(printf "$command_template" "$outfile")"
180180
;;
181+
sync)
182+
# The `sync` command has been disabled when using Bzlmod in favour of
183+
# `fetch`. For some reason Bazel crashes when you try to use `sync`
184+
# rather than printing a helpful error message.
185+
#
186+
# When run interactively, print a deprecation error and exit.
187+
# When run in a script, intercept `sync` commands and forward them
188+
# to `fetch` which is more or less identical. This ensures Git hooks
189+
# will continue working on this branch and older branches which do
190+
# not support `bazel fetch --configure` yet.
191+
if [ -t 0 ]; then
192+
echo 'ERROR: The `bazel sync` command has been deprecated.' >&2
193+
echo ' Use `bazel fetch` instead.' >&2
194+
exit 1
195+
else
196+
shift
197+
exec "$file" "${pre_cmd_args[@]}" fetch "$@"
198+
fi
199+
;;
181200
*)
182201
exec "$file" "${pre_cmd_args[@]}" "$@"
183202
;;

0 commit comments

Comments
 (0)