pedroborges / kirby-autogit

⬢ Saves every change made via Kirby Panel to a Git repository
149 stars 23 forks source link

What happens with submodules on pull? #28

Closed fitzage closed 6 years ago

fitzage commented 6 years ago

When my kirby site has autogit triggered and pulls new content from github, what happens if that new content involves an updated version of the submodules I'm using for plugins and such? Does this pull involve an update of the submodules, or do I need to do something else for that?

fitzage commented 6 years ago

Maybe I need to add a post-merge git hook to update the submodules?

fitzage commented 6 years ago

Or maybe something like this https://gist.github.com/digitaljhelms/f74eaf56835262d6bf3f

pedroborges commented 6 years ago

When Auto Git webhook receives a request and runs git pull, it also triggers a custom Kirby event you can listen to:

// inside site/config.php or site/plugin/{any-file-name}.php

kirby()->hook('autogit.pull', function () {
    // purge Kirby cache
    // update Algolia index
});

Unfortunately, as of now there's no way to run another Git command inside that closure. So that Git hook you found is the best option now.

fitzage commented 6 years ago

Hmmm…so I can't feed that hook a system command to trigger a script that would do the update?

pedroborges commented 6 years ago

You can, I said that as of now that's not supported by Auto Git out of the box.

It would be something like this (I can't test it now so please let me know if it works for you):

kirby()->hook('autogit.pull', function () {
    $command = 'cd ' . escapeshellarg(realpath(kirby()->roots()->content())) . ' && git submodule update --init --recursive';

    if (DIRECTORY_SEPARATOR == '/') {
        $command = 'LC_ALL=en_US.UTF-8 ' . $command;
    }

    exec($command, $output, $returnValue);
});

This is based on the execute protected method (see it) which Auto Git depends on.

fitzage commented 6 years ago

This did not work (I'm not sure why), but I'll pursue the other approach for now, thanks.

fitzage commented 6 years ago

Of course now I'm second guessing myself, and wondering if I actually deployed the config change before attempting to do the submodule change.

Note: tested again, and nope, doesn't work.

Of course neither does the "post-rewrite" hook I linked to, but "post-merge" works with that same script.