{"record":{"id":"514900c4ac004eb0","repo":"rectorphp/rector","slug":"ensure-to-run-compile-from-composer-git-repository","errorCode":null,"errorMessage":"Ensure to run compile from composer git repository clone and that git binary is available.","messagePattern":"Ensure to run compile from composer git repository clone and that git binary is available\\.","errorType":"exception","errorClass":"VersionException","httpStatus":null,"severity":"error","filePath":"src/Application/VersionResolver.php","lineNumber":37,"sourceCode":"     * @api\n     * @var string\n     */\n    public const PACKAGE_VERSION = '83496b5d65035792e7b8eea3bb083e8f3b16bec0';\n    /**\n     * @api\n     * @var string\n     */\n    public const RELEASE_DATE = '2026-08-20 18:50:33';\n    /**\n     * @var int\n     */\n    private const SUCCESS_CODE = 0;\n    public static function resolvePackageVersion(): string\n    {\n        // resolve current tag\n        exec('git tag --points-at', $tagExecOutput, $tagExecResultCode);\n        if ($tagExecResultCode !== self::SUCCESS_CODE) {\n            throw new VersionException('Ensure to run compile from composer git repository clone and that git binary is available.');\n        }\n        if ($tagExecOutput !== []) {\n            $tag = $tagExecOutput[0];\n            if ($tag !== '') {\n                return $tag;\n            }\n        }\n        exec('git log --pretty=\"%H\" -n1 HEAD', $commitHashExecOutput, $commitHashResultCode);\n        if ($commitHashResultCode !== 0) {\n            throw new VersionException('Ensure to run compile from composer git repository clone and that git binary is available.');\n        }\n        $version = trim($commitHashExecOutput[0]);\n        return trim($version, '\"');\n    }\n    public static function resolverReleaseDateTime(): DateTime\n    {\n        exec('git log -n1 --pretty=%ci HEAD', $output, $resultCode);\n        if ($resultCode !== self::SUCCESS_CODE) {","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/rectorphp/rector/blob/408fcb0ff1833e3d26cbc9b04c23a77565814a16/src/Application/VersionResolver.php#L19-L55","documentation":"VersionResolver::resolvePackageVersion() runs during Rector's own compile step (building the phar/scoped release) to bake a version string into the binary. It first shells out to `git tag --points-at`; if git exits with a non-zero code it throws VersionException, because the build requires metadata from a git checkout. The packaged constants (VersionResolver::PACKAGE_VERSION) are pre-baked, so normal end-user runs never execute this path.","triggerScenarios":"Compiling rector.phar (or calling VersionResolver::resolvePackageVersion() manually) outside a git clone: source downloaded as a zip/tarball without a .git directory, git binary not installed or not on PATH, or git refusing to run (e.g. 'detected dubious ownership').","commonSituations":"Building a phar from a GitHub source archive, a CI image without git, or a checkout owned by a different user triggering git's safe.directory check.","solutions":["Compile from a real git clone: git clone https://github.com/rectorphp/rector && build inside it","Ensure git is installed and on PATH: git --version must succeed in the build shell","If git reports dubious ownership, run git config --global --add safe.directory /path/to/rector","Do not call resolvePackageVersion()/resolverReleaseDateTime() in your own tooling; use the pre-baked VersionResolver::PACKAGE_VERSION constant instead"],"exampleFix":"// before: building from an exported source archive\ncurl -L https://github.com/rectorphp/rector/archive/refs/heads/main.tar.gz | tar xz\ncd rector-main && composer compile  # throws VersionException\n\n// after: clone the repository so git metadata exists\ngit clone https://github.com/rectorphp/rector.git\ncd rector && composer compile","handlingStrategy":"validation","validationCode":"// run before compiling\nexec('git rev-parse --git-dir 2>/dev/null', $out, $code);\nif ($code !== 0 || $out === []) {\n    exit('Compile requires a git clone with git on PATH');\n}","typeGuard":null,"tryCatchPattern":"catch \\Rector\\Exception\\VersionException around the compile step and fail the build with a message pointing to 'clone the repo and install git' rather than retrying.","preventionTips":["Always build phars from a full git clone, never from source archives","Include git in build images and keep .git in the build context","Add a pre-compile CI assertion that `git log -n1 HEAD` succeeds"],"tags":["php","rector","git","build","compile","version"],"backgroundTag":"missing-git-repository","analyzedSha":"408fcb0ff1833e3d26cbc9b04c23a77565814a16","analyzedAt":"2026-08-21T05:11:02.643Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}