Skip to content

Commit 09fd344

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]>
1 parent 532e1a9 commit 09fd344

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

bazelisk.sh

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

0 commit comments

Comments
 (0)