rectorphp/rector · error · VersionException
You must ensure to run compile from composer git repository
Error message
You must ensure to run compile from composer git repository clone and that git binary is available.
What it means
VersionResolver::resolverReleaseDateTime() runs `git log -n1 --pretty=%ci HEAD` during the compile step to bake the RELEASE_DATE constant into the built phar. A non-zero exit code from git throws VersionException. Like the other VersionResolver errors, this only affects building Rector itself from source, not running an installed Rector.
Source
Thrown at src/Application/VersionResolver.php:56
}
if ($tagExecOutput !== []) {
$tag = $tagExecOutput[0];
if ($tag !== '') {
return $tag;
}
}
exec('git log --pretty="%H" -n1 HEAD', $commitHashExecOutput, $commitHashResultCode);
if ($commitHashResultCode !== 0) {
throw new VersionException('Ensure to run compile from composer git repository clone and that git binary is available.');
}
$version = trim($commitHashExecOutput[0]);
return trim($version, '"');
}
public static function resolverReleaseDateTime(): DateTime
{
exec('git log -n1 --pretty=%ci HEAD', $output, $resultCode);
if ($resultCode !== self::SUCCESS_CODE) {
throw new VersionException('You must ensure to run compile from composer git repository clone and that git binary is available.');
}
return new DateTime(trim($output[0]));
}
}
View on GitHub (pinned to 408fcb0ff1)
Solutions
- Run the compile from inside a complete git clone with git available: git clone ... && build there
- Install git in the build container and confirm git log -n1 --pretty=%ci HEAD works
- Keep the .git directory in the build context (do not add it to .dockerignore for the compile stage)
- For safe.directory errors, run git config --global --add safe.directory <path>
Example fix
# before: Docker build stage copies source without .git COPY rector-src/ /app/ # .git excluded RUN php compile.php # VersionException # after: clone inside the build stage RUN git clone --depth 1 https://github.com/rectorphp/rector.git /app/rector RUN php /app/rector/compile.php
Defensive patterns
Strategy: validation
Validate before calling
exec('git log -n1 --pretty=%ci HEAD', $date, $code);
if ($code !== 0) {
exit('Cannot resolve release date: build outside a git clone or git unavailable');
} Try / catch
catch \Rector\Exception\VersionException during compile; treat as environment failure (no .git / no git) and abort the packaging job with a clear cause instead of shipping a broken build.
Prevention
- Keep .git in the compile stage (do not strip it in Docker COPY)
- Pin a working git binary in the build image
- Test the full compile path in CI regularly so environment drift is caught early
When it happens
Trigger: Calling resolverReleaseDateTime() (directly or via the compile script) where git cannot run: no .git directory (zip/tarball export), git missing from PATH, git blocked by sandbox policy, or corrupted repository metadata.
Common situations: Packaging Rector into a custom phar in a Docker stage that strips .git; minimal alpine build images without git; automated release tooling running outside the clone.
Related errors
- Ensure to run compile from composer git repository clone and
- "%s" rule is deprecated, as turning a docblock type into a r
- "%s" rule is deprecated, as risky. The "??" and "?:" operato
- "%s" is deprecated as depends on context and personal prefer
- "%s" rule is deprecated, as it is a personal preference that
AI-assisted analysis of rectorphp/rector@408fcb0ff1 (2026-08-21).
Data as JSON: /api/errors/43c70e2f8b0ad601.
Report an issue: GitHub.