Skip to content

Honor --skip-hooks when given after a subcommand - #1981

Open
tylerbrowndev wants to merge 1 commit into
basecamp:mainfrom
tylerbrowndev:fix-skip-hooks-through-subcommands
Open

tylerbrowndev wants to merge 1 commit into
basecamp:mainfrom
tylerbrowndev:fix-skip-hooks-through-subcommands

Conversation

@tylerbrowndev

Copy link
Copy Markdown

kamal app exec --skip-hooks ... still runs the pre-connect hook.

#1754 (for #1752) added unless options[:skip_hooks] to pre_connect_if_required. That covers commands on Main (kamal deploy --skip-hooks works), but when a class option is given after a subcommand, Thor only puts it in the subcommand's class options. options[:skip_hooks] stays false there, both in pre_connect_if_required and in run_hook. options_with_subcommand_class_options was added for exactly this case (1f83b5f), but the hook checks don't use it.

The existing exec tests call Kamal::Cli::App directly, where the flag does land in options, so they pass either way.

Reproduction (2.12.0 and main)

With exec stubbed to print what it sees:

Command options[:skip_hooks] options_with_subcommand_class_options[:skip_hooks]
kamal deploy --skip-hooks / -H true —
kamal app exec --skip-hooks ... (any position) / -H false true

We hit this from a pre-deploy hook that runs a nested kamal app exec --skip-hooks -d production --roles cron ...: the nested Kamal ran pre-connect again.

Change

  • skip_hooks? reads the flag through options_with_subcommand_class_options; run_hook and pre_connect_if_required use it.
  • Two tests in test/cli/app_test.rb run exec through Kamal::Cli::Main, the way the CLI invokes it: without the flag pre-connect runs, and with --skip-hooks it doesn't. The second fails on main.

bin/test locally: the new tests pass and the run has the same failures as main (the Docker integration tests and the builder tests that need a Docker daemon, which this machine doesn't have).

🤖 Generated with Claude Code

`kamal app exec --skip-hooks ...` still ran the pre-connect hook. Class options
given after a subcommand only reach the subcommand's class options (the case
options_with_subcommand_class_options was added for), but run_hook and
pre_connect_if_required read options[:skip_hooks], which stays false there.
The tests call Kamal::Cli::App directly, where the flag lands in options, so
they didn't catch it.

Check skip_hooks through options_with_subcommand_class_options, and test exec
through Main the way the CLI invokes it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 28, 2026 17:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approved

No active review issues were identified for the fix to honor --skip-hooks after subcommands.

No open issues 🎉

What changed in this PR

Fixes --skip-hooks handling after a subcommand so commands such as kamal app exec --skip-hooks correctly suppress hooks, including pre-connect.

Changes:

  • Adds a shared skip_hooks? helper that reads merged subcommand class options and is used by both hook checks.
  • Adds regression tests through Kamal::Cli::Main to verify that pre-connect runs normally and is skipped when requested.

[!TIP]
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.

File Description
test/​cli/​app_test.rb Tests hook behavior through the main CLI entry point.
lib/​kamal/​cli/​base.rb Uses merged subcommand options when deciding whether to skip hooks.

Review effort: Balanced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants