Skip to content

configure: replace git_clean() with scoped temp_clean() - #365

Open
hakre wants to merge 1 commit into
php:masterfrom
hakre:patch-2
Open

hakre wants to merge 1 commit into
php:masterfrom
hakre:patch-2

Conversation

@hakre

@hakre hakre commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

git_clean() unconditionally invoked Git, which fails in build environments that do not provide Git by default and the script stopped with the following diagnostic (shortened):

configure.php on PHP 8.5.13, libxml 2.9.14
...
sh: 1: git: not found
doc-base/temp clean up FAILED.

The safety of 'git clean -fdx temp' comes from its scoping (only untracked files under temp/), not from Git itself.

Replace it with a scoped filesystem cleanup using RecursiveIteratorIterator (CHILD_FIRST, SKIP_DOTS, no symlink following), preserving the committed temp/.gitkeep marker. On failure, emit a warning and continue instead of aborting the build, as suggested in review.

git_status() had the same root cause without the crash: without Git it produced 6x "sh: git: not found" plus an empty listing, and with Git installed but Docker ADD-stripped .git directories (reproducible builds) it produced "fatal: not a git repository" plus the same empty listing. Fixed with an early git --version check (exec with 2>&1, keeping the shell error off the terminal) and a per-repo .git check. Cast shell_exec() results to string to silence trim(null) deprecations on PHP 8.5.

--with-git is removed, following the preference expressed in review for a soft warning over a new configure option.

To verify the behavior, I ran configure multiple times and compared the before and after of three exemplary file-system entries in the doc-base/temp directory.

After the fix, temp_clean() behaves identically regardless of Git:

Git Iteration . .gitkeep debug.xi Build
no 1 old old new ok
no 2 old old new ok
yes 1 old old new ok
yes 2 old old new ok

old = birth time unchanged from the previous iteration,
new = recreated during this iteration.

Before the fix, without Git:

Git Result
no build fails: sh: git: not found, doc-base/temp clean up FAILED

With a Git shim (no-op clean), the build succeeds, but the birth pattern for the three test entries is identical to the after-fix case above — the build recreates everything it needs, so the cleanup made no observable difference in this test.

@alfsb

alfsb commented Dec 1, 2026

Copy link
Copy Markdown
Member

Instead of adding an option that disables git on git_clean(), I would prefer making this function to generate a soft error / warning in case of failure.

The logic behind using git to remove files is to avoid calling some uncontrollable rm -rf on people's hard disks. If there are uses of configure.php that runs without git installed, in "single run scenarios", it's better to document that directly in code.

In git_clean(), first list all files of temp. If there is only a single dot file, then return. If not, git clean should run, and also should fail or, at least, should emit a warning about "missing git, manual build is not idempotent", before continuing.

git_clean() unconditionally invoked Git, which fails in build
environments that do not provide Git by default and the script
stopped with the following diagnostic (shortened):

    configure.php on PHP 8.5.13, libxml 2.9.14
    ...
    sh: 1: git: not found
    doc-base/temp clean up FAILED.

The safety of 'git clean -fdx temp' comes from its scoping
(only untracked files under temp/), not from Git itself.

Replace it with a scoped filesystem cleanup using Recursive-
IteratorIterator (CHILD_FIRST, SKIP_DOTS, no symlink following),
preserving the committed temp/.gitkeep marker. On failure, emit
a warning and continue instead of aborting the build, as
suggested in review.

git_status() had the same root cause without the crash: without
Git it produced 6x "sh: git: not found" plus an empty listing,
and with Git installed but Docker ADD-stripped .git directories
(reproducible builds) it produced "fatal: not a git repository"
plus the same empty listing. Fixed with an early `git --version`
check (exec with 2>&1, keeping the shell error off the terminal)
and a per-repo .git check. Cast shell_exec() results to string
to silence trim(null) deprecations on PHP 8.5.

--with-git is removed, following the preference expressed in
review for a soft warning over a new configure option.
@hakre hakre changed the title configure: add --with-git flag configure: replace git_clean() with scoped temp_clean() Dec 2, 2026
@hakre

hakre commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor Author

Reworked as discussed:

  1. git_clean() → temp_clean() – scoped filesystem cleanup via RecursiveIteratorIterator (CHILD_FIRST, SKIP_DOTS, no symlink following), preserving the committed temp/.gitkeep. Same safety property as git clean -fdx temp: only touches temp/, no rm -rf risk. No Git required. On failure I emit a warning and continue (your "at least [...] a warning [...], before continuing") rather than hard-failing — if you'd rather have the hard failure, say the word; additional output example (minimum required PHP 8.1 version) — hard error could become an additional checkerror() differentiator before checkvalue() independent to the warnings — shortened:

    configure.php on PHP 8.1.0, libxml 2.9.10
    ...
    Checking for temp/ being idempotent cleaned up... yes
    ...
    

    (yes = OK, no = clean up was necessary but could not be established)

  2. git_status() – I went a bit further here, because it turned out to have the same root cause, just without the crash. Without Git it produced 6 × 'sh: git: not found' plus an empty listing; with Git installed but ADD-stripped .git directories (Docker builds) it produced fatal: not a git repository plus the same empty listing. Fixed with an early git --version check and a per-repo .git check. Also cast shell_exec() results to string to silence trim(null) deprecations on PHP 8.5.

  3. --with-git – removed, as you preferred ("Instead of adding an option that disables git on git_clean(), I would prefer making this function to generate a soft error / warning"). temp_clean() now warns instead of failing, and git_status() skips cleanly.

Logs are clean now in all three cases: real checkout with Git, Docker ADD without .git, and no Git at all. The extended maintenance workflow (keeping temp/ around for full inspection) is unaffected — the cleanup still runs when temp/ has content, it just doesn't need Git to do it.

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