fix: derive project machine name from git remote when argument is omitted - #370
Open
mglaman wants to merge 1 commit into
Open
fix: derive project machine name from git remote when argument is omitted#370mglaman wants to merge 1 commit into
mglaman wants to merge 1 commit into
Conversation
…tted
ProjectCommandBase checked InputInterface::hasArgument('project'), which only reports whether the argument is defined on the command, not whether the user passed it. It was always true, so the git remote fallback never ran and the null argument became an empty project name. The parsing now lives in ProjectRemote so it can be unit tested against SSH, HTTPS, and .git-less remote forms, and a missing derivation reports a clear error.
Closes #346
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
mglaman
added a commit
that referenced
this pull request
Aug 28, 2026
Drops the duplicate URL parser in src/Api/Git and moves fromRemotes() and detect() onto ProjectRemote so a single parser handles project remotes. Callers read ->machineName from the value object. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
ProjectCommandBase::initialize()now checks the value of theprojectargument instead of whether the argument exists, so the git remote fallback actually runs when the argument is omitted.mglaman\DrupalOrg\ProjectRemote::tryParse(), a small value object that returnsnullfor anything that is not aproject/remote ongit.drupal.orgorgit.drupalcode.org. It handlesgit@host:project/name.git,ssh://,https://, and.git-less forms.Could not determine the project from the git remote; pass the machine name as an argument.instead ofProject not found.git config --get remote.origin.urlruns as an argv array rather than(array) 'git config ...', which passed the whole string as a single argument.Why
Closes #346.
InputInterface::hasArgument()reports whether the argument is defined on the command, not whether the user passed it. For everyproject:*command it is alwaystrue, so this branch never ran andgetArgument('project') ?? ''produced an empty name:The regex itself was not the cause, but it also required a
.gitsuffix and matched any host, so the parser was rewritten while making it testable.Testing
vendor/bin/phpcs src tests,vendor/bin/phpstan analyse src, andvendor/bin/phpunit(179 tests, 558 assertions) pass.tests/src/ProjectRemoteTest.phpcovers the SSH, ssh://, HTTPS, and.git-less forms plus GitHub, issue fork, and empty remotes returningnull.Reproduction in a throwaway repo with
originset togit@git.drupal.org:project/json_form_widget.git:Before:
After:
Same result with
https://git.drupalcode.org/project/json_form_widget.gitandhttps://git.drupalcode.org/project/json_form_widget. Withoriginset togit@github.com:mglaman/drupalorg-cli.git:🤖 Generated with Claude Code