Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
17 changes: 12 additions & 5 deletions core/util/git.mk
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,31 @@ __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)

## @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
Expand Down
15 changes: 15 additions & 0 deletions modules/php/php/php.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion modules/php/phpcs/phpcs.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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__

Expand Down
2 changes: 1 addition & 1 deletion modules/php/phpstan/phpstan.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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__

Expand Down
2 changes: 1 addition & 1 deletion modules/php/psalm/psalm.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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__

Expand Down
10 changes: 8 additions & 2 deletions templates/config.tpl.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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/