Open bobbingwide opened 5 years ago
Well that was a success for WP-a2z.org.
The output shows the result of git status -s
. This is basically the same output as we get from SSH run in public_html
, public_html/wp-content
and any other directory which doesn't have a GIT repo.
We get output since the GIT repo is https://github.com/bobbingwide/WP-a2z
If there wasn't a GIT repository we'd get
fatal: Not a git repository (or any of the parent directories): .git
If we're not allowed to run the git command under shell_exec()
we'd get some other result. TO BE TESTED on other servers.
So now we can go ahead and write the code to perform git pull
within the appropriate folder.
Maybe create a form that will support status
, remote
, pull
etc
Having tried the logic on a site hosted with TSOhost I then extended it to check for GIT repos for each installed plugin ( in the plugin directory ) producing a report of plugins which are apparently git repos.
In some cases, e.g. where the plugin was uploaded using FTP, the "remote" repository turns out to be inaccessible... \github\bobbingwide\oik-batch
instead of https://github.com/bobbingwide/oik-batch
.
Having made further progress, rather than hook into oik options > overview the solution should now use its own admin page ( oik_batch ) to implement Git admin. We'll do it for plugins first, then themes and maybe core and mu-plugins... that's a thought.
Note: It takes a reasonable amount of time to perform GIT commands, so we can't really do too many in one server request. The logic to check if a plugin is a GIT repository needs to be quicker.
Once a plugin has been identified as a GIT plugin then we can perform a Check
action that will invoke more git commands to see if updates are available, and if so apply them.
v1.0.0 has now been installed on wp-a2z.org and Network Activated.
As expected, the checking logic does not work for private repositories which require the username and password to be given. For diy-oik we get the following messages.
remote update: Fetching origin fatal: could not read Username for 'https://github.com':
No such device or address error: Could not fetch origin
fetch: fatal: could not read Username for 'https://github.com':
No such device or address
status: On branch master Your branch is up-to-date with 'origin/master'.
nothing to commit (use -u to show untracked files)
Pull: fatal: could not read Username for 'https://github.com':
No such device or address
Somehow EDD is now ahead
Remote: https://github.com/bobbingwide/easy-digital-downloads
Current: cad0244 Merge branch 'master' of https://github.com/bobbingwide/easy-digital-downloads
...
status: On branch master Your branch is ahead of 'origin/master' by 9 commits. (use "git push" to publish your local commits) nothing to commit (use -u to show untracked files)
So now we need to make it work for themes as well as plugins.
A method called echo() is only supported from PHP 7. After migration oik-plugins.co.uk had reverted to PHP 5.4, so there was a syntax error when echo was encounted as a method name in includes\class-git.php
Workaround: Switch to PHP 7.2... which was what was wanted in the first place.
In oik-plugins.co.uk the plugin called genesis-footer-widgets was uploaded directly from a GIT repository which is not accessible on the Linux server. Checking the plugin produces the following messages.
Remote: \github\bobbingwide\genesis-footer-widgets
Current: error: inflate: data stream error (invalid bit length repeat) fatal: loose object 944bb95b9edaf38cc6e95a81dfd9fd97c9475128 (stored in .git/objects/94/4bb95b9edaf38cc6e95a81dfd9fd97c9475128) is corrupt
Status: error: inflate: data stream error (incorrect data check) fatal: loose object cb5def80b8a4996a2fdb2096b650cbe840532271 (stored in .git/objects/cb/5def80b8a4996a2fdb2096b650cbe840532271) is corrupt
Not safe to pull
Consider adding some logic to deal with problems like this.
We may need to escape the output from the git commands in case there’s HTTP or even JavaScript that could break the display. On core, the diy-oik plugin, the commit SHA was all numeric and got displayed as a telephone number! 1894221
On oik-plugins.com, which didn't have the latest version of oik-batch, I tried ftping the GIT repo from \github\bobbingwide\oik-batch. This enabled oik-batch to work but it could not self check since there were multiple remote repositories and the wrong one was found first. Perhaps it should check for remote called origin
to determine the remote address.
In oik-plugins.co.uk I just got the following:
I’ll probably need to add some logic to check if shell_exec() is disabled.
Currently the nested plugin called oik-wp.php is not expected to be activated. I want to test whether or not I can invoke git commands from a Linux hosted Apache server, rather than SSH. If so, then we should be able to implement
git pull
commands for Git based repos.