Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add logic to update Git based components #34

Open
bobbingwide opened this issue Jan 16, 2019 · 11 comments
Open

Add logic to update Git based components #34

bobbingwide opened this issue Jan 16, 2019 · 11 comments
Assignees

Comments

@bobbingwide
Copy link
Owner

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.

@bobbingwide
Copy link
Owner Author

bobbingwide commented Jan 16, 2019

Well that was a success for WP-a2z.org.

image

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

@bobbingwide
Copy link
Owner Author

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.
image

Next steps

  • We'll have to find out how to do a test fetch.
  • We also need to know when it's safe to perform a pull.
  • Convert the plain output into a form.

@bobbingwide bobbingwide changed the title Add logic to test for Git capability Add logic to update Git based plugins Jan 19, 2019
@bobbingwide
Copy link
Owner Author

bobbingwide commented Jan 19, 2019

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.

bobbingwide added a commit that referenced this issue Jan 19, 2019
@bobbingwide
Copy link
Owner Author

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

@bobbingwide
Copy link
Owner Author

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)

@bobbingwide
Copy link
Owner Author

bobbingwide commented Jan 19, 2019

So now we need to make it work for themes as well as plugins.

@bobbingwide
Copy link
Owner Author

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.

@bobbingwide
Copy link
Owner Author

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.

@bobbingwide
Copy link
Owner Author

bobbingwide commented Jan 22, 2019

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

@bobbingwide
Copy link
Owner Author

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.

@bobbingwide bobbingwide changed the title Add logic to update Git based plugins Add logic to update Git based components Jan 23, 2019
@bobbingwide
Copy link
Owner Author

In oik-plugins.co.uk I just got the following:
4C8D68B0-BE0E-498B-B48F-88747FFF5CC6

I’ll probably need to add some logic to check if shell_exec() is disabled.

@bobbingwide bobbingwide self-assigned this Jan 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant