boonebgorges / wp-cli-git-helper

Git helper for wp-cli
35 stars 5 forks source link

Fatal error with WordPress as a submodule #1

Open pdewouters opened 9 years ago

pdewouters commented 9 years ago
Fatal error: Uncaught exception 'Exception' with message '"/srv/www/rrr.dev/wordpress" is not a git repository' in /home/vagrant/.wp-cli/commands/gh/vendor/kbjr/Git.php/Git.php:210
Stack trace:
#0 /home/vagrant/.wp-cli/commands/gh/vendor/kbjr/Git.php/Git.php(172): GitRepo->set_repo_path('/srv/www/rrrr...', false, true)
#1 /home/vagrant/.wp-cli/commands/gh/vendor/kbjr/Git.php/Git.php(83): GitRepo->__construct('/srv/www/rrrr...')
#2 /home/vagrant/.wp-cli/commands/gh/wp-cli-git-helper.php(56): Git::open('/srv/www/rrr...')
#3 [internal function]: Git_Helper_Command->__invoke(Array, Array)
#4 phar:///usr/local/bin/wp/php/WP_CLI/Dispatcher/CommandFactory.php(52): call_user_func(Array, Array, Array)
#5 [internal function]: WP_CLI\Dispatcher\CommandFactory::WP_CLI\Dispatcher\{closure}(Array, Array)
#6 phar:///usr/local/bin/wp/php/WP_CLI/Dispatcher/Subcommand.php(293): call_user_func(Object(Closure), Array, Array)
#7 phar:///usr/local/bin/wp/php/WP_CLI/Runner.php(304): WP_CLI\Dispatcher\Subcommand->invoke(Array, Array in /home/vagrant/.wp-cli/commands/gh/vendor/kbjr/Git.php/Git.php on line 210
boonebgorges commented 9 years ago

Thanks for the report. This is happening because your git repo is not located at ABSPATH. For the moment, this is hardcoded into the tool, though there's a note that says to fix it! https://github.com/boonebgorges/wp-cli-git-helper/blob/master/wp-cli-git-helper.php#L55

pdewouters commented 9 years ago

ok thanks!

boonebgorges commented 9 years ago

You got it! A proper fix for this is pretty straightforward - instead of hardcoding ABSPATH here https://github.com/boonebgorges/wp-cli-git-helper/blob/master/wp-cli-git-helper.php#L56, it would be set by an $assoc_args param, which would default to ABSPATH. Pull requests welcome :) Or you can just hardcode the proper path yourself.

pdewouters commented 9 years ago

Sure, I'll do a PR :)

micahjon commented 9 years ago

Just ran into this too. Another solution might be to search recursively from WP_PLUGIN_DIR up the directory tree until a directory is found with a .git folder. This would work for basic installs and ones where Wordpress is a submodule.

micahjon commented 8 years ago

Should I submit a PR for this? Currently I just check if WP_PLUGIN_DIR or it's parent/grandparent directory contains a Git repo, and use the first one I find (or print an error message).

boonebgorges commented 8 years ago

Walking up the tree recursively seems dangerous to me - you wouldn't want to accidentally commit to the incorrect repo. A PR that implements this idea https://github.com/boonebgorges/wp-cli-git-helper/issues/1#issuecomment-67847064 seems safer to me. (You can then define a default for the new flag in your wp-cli.yml file.)