diff --git a/CHANGELOG.md b/CHANGELOG.md index 93b25c7..2fad10a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,18 @@ +## [2.2.9] - 2026-01-04 + +### Fixed +- **PHP staged targets broken in docker mode**: `php/phpcs/staged`, `php/phpstan/staged`, `php/psalm/staged` were not working with docker/docker-compose execution modes + - **Issue 1**: `mb_run_on_staged` appended files outside docker shell quotes, so files were passed to shell instead of the tool + - **Issue 2**: Git staged file paths are relative to repo root, but container may mount a subdirectory + - **Fix**: New `php_run_on_staged` helper gets staged files and passes them inside the invoke call + +### Added +- **`mb_staged_strip_prefix` config** (in `core/util/git.mk`): Global config to strip path prefix from staged files + - Example: Set `mb_staged_strip_prefix := app/` if your code is in `app/` folder mounted as `/app` in container +- **`php_run_on_staged` helper** (in `modules/php/php/php.mk`): Run PHP tools on staged files with proper docker support + - Usage: `$(call php_run_on_staged,vendor/bin/phpcs -s)` +- **`mb_staged_files` now supports prefix stripping**: Pass optional second argument or use global `mb_staged_strip_prefix` + ## [2.2.8] - 2026-01-04 ### Added diff --git a/core/util/git.mk b/core/util/git.mk index 86e45a0..7a7b77d 100644 --- a/core/util/git.mk +++ b/core/util/git.mk @@ -10,6 +10,10 @@ __MB_CORE_UTIL_GIT_MK__ := 1 mb_debug_git ?= $(mb_debug) +## Strip prefix from staged file paths to match container paths +## Example: git shows 'app/src/Foo.php' but container expects 'src/Foo.php' → set to 'app/' +mb_staged_strip_prefix ?=# + ## Check if git is available (set once at load time) ## Note: Can't use mb_cmd_exists or mb_true here as they may not be defined yet mb_git_available := $(shell command -v git >/dev/null 2>&1 && echo 1) @@ -17,17 +21,20 @@ mb_git_available := $(shell command -v git >/dev/null 2>&1 && echo 1) ## @function mb_staged_files ## @description Returns a space-separated list of staged files, optionally filtered by extension ## @arg 1: extension (optional) - File extension to filter (e.g., php, py, go). If empty, returns all staged files. -## @returns Space-separated list of staged files (paths relative to git root) +## @arg 2: strip_prefix (optional) - Path prefix to strip. If empty, uses mb_staged_strip_prefix. +## @returns Space-separated list of staged files (paths relative to git root, with prefix stripped) ## @example $(call mb_staged_files,php) -> src/Foo.php src/Bar.php +## @example $(call mb_staged_files,php,app/) -> strips 'app/' prefix from paths ## @example $(call mb_staged_files) -> all staged files define mb_staged_files $(strip $(if $(mb_git_available), $(eval $0_arg1_ext := $(if $(value 1),$(strip $1),)) - $(if $($0_arg1_ext), - $(shell git diff --cached --name-only --diff-filter=d 2>/dev/null | grep '\.$($0_arg1_ext)$$' || true), - $(shell git diff --cached --name-only --diff-filter=d 2>/dev/null) - ) + $(eval $0_arg2_prefix := $(if $(value 2),$(strip $2),$(mb_staged_strip_prefix))) + $(eval $0_files := $(if $($0_arg1_ext),\ + $(shell git diff --cached --name-only --diff-filter=d 2>/dev/null | grep '\.$($0_arg1_ext)$$' || true),\ + $(shell git diff --cached --name-only --diff-filter=d 2>/dev/null))) + $(if $($0_arg2_prefix),$(patsubst $($0_arg2_prefix)%,%,$($0_files)),$($0_files)) ) ) endef diff --git a/modules/php/php/php.mk b/modules/php/php/php.mk index 9deb787..800dd32 100644 --- a/modules/php/php/php.mk +++ b/modules/php/php/php.mk @@ -42,6 +42,21 @@ $(strip ) endef +## @function php_run_on_staged +## @description Run a PHP tool on staged PHP files only +## @arg 1: command (required) - Command to run (files will be appended) +## @example $(call php_run_on_staged,vendor/bin/phpcs -s) +## @example $(call php_run_on_staged,vendor/bin/phpstan analyse) +define php_run_on_staged +$(strip + $(eval $0_arg1_cmd := $(if $(value 1),$(strip $1),$(call mb_printf_error,$0: command required))) + $(eval $0_files := $(call mb_staged_files,php)) + $(if $($0_files),\ + $(call php_invoke,$($0_arg1_cmd) $($0_files)),\ + $(call mb_printf_info,No staged .php files)) +) +endef + # $1 - Invoker name # $2 - Docker check variable name # $3 - Docker compose service name variable diff --git a/modules/php/phpcs/phpcs.mk b/modules/php/phpcs/phpcs.mk index df93540..8a19c63 100644 --- a/modules/php/phpcs/phpcs.mk +++ b/modules/php/phpcs/phpcs.mk @@ -48,7 +48,7 @@ php/phpcs/fix: ## Run PHP Code Beautifier to auto-fix (phpcs_files= for paths, p $(call php_invoke,$($@_cmd)) php/phpcs/staged: ## Run PHP CodeSniffer on staged PHP files only - $(call mb_run_on_staged,php,$(call php_invoke,$(phpcs_bin) -s)) + $(call php_run_on_staged,$(phpcs_bin) -s) endif # __MB_TEST_DISCOVERY__ diff --git a/modules/php/phpstan/phpstan.mk b/modules/php/phpstan/phpstan.mk index 0b8099e..33cd6fd 100644 --- a/modules/php/phpstan/phpstan.mk +++ b/modules/php/phpstan/phpstan.mk @@ -42,7 +42,7 @@ php/phpstan/analyse: ## Run PHPStan analysis (phpstan_files= for paths, phpstan_ ) php/phpstan/staged: ## Run PHPStan on staged PHP files only - $(call mb_run_on_staged,php,$(call php_invoke,$(phpstan_bin) analyse)) + $(call php_run_on_staged,$(phpstan_bin) analyse) endif # __MB_TEST_DISCOVERY__ diff --git a/modules/php/psalm/psalm.mk b/modules/php/psalm/psalm.mk index cd1099b..7a5c5c1 100644 --- a/modules/php/psalm/psalm.mk +++ b/modules/php/psalm/psalm.mk @@ -41,7 +41,7 @@ php/psalm/analyse: ## Run Psalm analysis (psalm_files= for paths, psalm_args= fo ) php/psalm/staged: ## Run Psalm on staged PHP files only - $(call mb_run_on_staged,php,$(call php_invoke,$(psalm_bin))) + $(call php_run_on_staged,$(psalm_bin)) endif # __MB_TEST_DISCOVERY__ diff --git a/templates/config.tpl.mk b/templates/config.tpl.mk index 4460a5e..2361709 100644 --- a/templates/config.tpl.mk +++ b/templates/config.tpl.mk @@ -7,8 +7,14 @@ ### - mb_project_bindhub_path: Path to the bind.hub folder of the project ### - mb_project_bindhub_modules_path: Path to the modules folder in the bind-hub folder of the project ### - mb_project_path: Path of your project -### NOTE! -### mb_targets_only_project := $(mb_true)# set this to only show targets from the project and its modules mb_project_name := project-name### Please replace project-name with the name of your project mb_project_prefix := project-prefix### Please replace project-prefix with the prefix of your project + +### Optional settings (uncomment to enable): +### Show only project targets (hides MakeBind core AND enabled module targets) +#mb_targets_only_project := $(mb_true) + +### Strip prefix from staged file paths to match container paths +### Example: git shows 'app/src/Foo.php' but container expects 'src/Foo.php' → set to 'app/' +#mb_staged_strip_prefix := app/