1

I am trying to create a git commit and push it to the remote repo every time my client updates their Wordpress plugins or core. I have successfully hooked into the correct filter so I can execute php code once the updates are done, and I can even create a commit, but I have no luck pushing to remote.

I am using the following code:

system ( 'cd '.ABSPATH.'; git add -A;' );
system ( 'cd '.ABSPATH.'; git commit -a -m "Updated plugins via WP";' );
system ( 'cd '.ABSPATH.'; echo `git push`;' );

The first 2 lines work great! They produce output as well. However, the 3rd line does NOT work. And there is no output produced. When I check my repo, the changes have not been pushed to remote. When I manually do git push via terminal/shell, it pushes successfully and it produces output.

I must be missing something obvious?

2
  • 1
    According to you, what's different from the 2 first lines and the last? Commented Oct 2, 2012 at 10:00
  • 1
    Do you intentionally do the push within the backticks? Did you try calling system ( 'cd '.ABSPATH.'; git push;' ); Commented Oct 2, 2012 at 10:01

5 Answers 5

2

https://github.com/kbjr/Git.php

You can try using Git.php to run git commands. While it does not have a push function, you can use the run function like this:

$repo = Git::open(ABSPATH);
$repo->add('-A');
$repo->commit('Updated plugins via WP');
$repo->run('push');
Sign up to request clarification or add additional context in comments.

Comments

1

Not too sure whether using 'system()' is a great idea. However there is SSH2 support in PHP, a great tutorial on how to interact with a server using SSH2 and PHP can be found here:

http://kevin.vanzonneveld.net/techblog/article/make_ssh_connections_with_php/

( It even covers installing the ssh2 library if you haven't got it installed already )

Also you could try some intermediate 'echo''s through the system command just to see whether its still producing output.

Comments

1

Personally, I'd write a simple bash script to do your batch git operations and execute that with proc_open rather than using system. It's better for getting your script output as well as checking for errors and exit code.

http://php.net/manual/en/function.proc-open.php

Comments

0

If you want to see the output, you have to echo it

echo system ( 'cd '.ABSPATH.'; echo `git push`;' );

1 Comment

Tried that, doesn't do anything
0

If you remove the echo and the backticks from the last line, you'll get the code you most likely would also use yourself:

system ( 'cd '.ABSPATH.'; git push ;' );

Note that a push will fail if your server is not running on HEAD. You may need to specify a branch name and need to pull before you push. (I would use pull - commit - push.)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.