trilbymedia / grav-plugin-git-sync

Collaboratively Synchronize your Grav `user` folder hosted on GitHub, BitBucket or GitLab
Apache License 2.0
243 stars 58 forks source link

Return code 500. GitSync failed to synchronize #124

Closed lambopedia closed 5 years ago

lambopedia commented 5 years ago

Hello! A couple of days I can not deal with the problem. I set up the plugin exactly as in the video. At changes in a repository (push) the webhook returns an error, a code 500.

{"status":"error","message":"GitSync failed to synchronize"}

I tried to use HTTPS and not use. I tried both "github" and "bitbucked" - the result is one. Now I do not understand in which direction to diagnose the problem.

Please offer something.

w00fz commented 5 years ago

Have you tried running a manual synchronization from your CLI? It seems like it's able to reach your server but it's failing.

lambopedia commented 5 years ago

When manually sending (redeliewer) all the same. Maybe I can see some logs, through which I can understand the source of the problem?

lambopedia commented 5 years ago

I progressed in figuring out the problem. An error occurs in the module /user/plugins/git-sync/classes/GitSync.php in line 353.

if ($this->getConfig('logging', false)) {
                $log_command = Helper::preventReadablePassword($command, $this->password);
                $this->grav['log']->notice('gitsync[command]: ' . $log_command);

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

                $log_output = Helper::preventReadablePassword(implode("\n", $output), $this->password);
                $this->grav['log']->notice('gitsync[output]: ' . $log_output);
            } else {                                   
                exec($command, $output, $returnValue); // <---- HERE
            }

Error message: "On the master branch there is nothing to commit, there are no changes in the working directory"

In general, it is strange, the idea behind the change is to get to the site. What can a mistake mean?

lambopedia commented 5 years ago

Webhook log:

[2018-12-21 21:06:58] grav.NOTICE: gitsync[command]: LC_ALL=en_US.UTF-8 git -C '/home/lambopedia.ru/docs/user/' status pages 2>&1 [] []
[2018-12-21 21:06:58] grav.NOTICE: gitsync[output]: nothin to commit, working tree clean [] []
[2018-12-21 21:06:59] grav.NOTICE: gitsync[command]: LC_ALL=en_US.UTF-8 git -C '/home/lambopedia.ru/docs/user/' add . 2>&1 [] []
[2018-12-21 21:06:59] grav.NOTICE: gitsync[output]:  [] []
[2018-12-21 21:06:59] grav.NOTICE: gitsync[command]: LC_ALL=en_US.UTF-8 git -C '/home/lambopedia.ru/docs/user/' commit --author="lambopedia <lambopedia@ya.ru>" -m '(Grav GitSync) Automatic Commit from lambopedia' 2>&1 [] []
[2018-12-21 21:06:59] grav.NOTICE: gitsync[output]: nothin to commit, working tree clean [] []

How to make git pull command?

lambopedia commented 5 years ago

The error works here:

public function synchronize()
    {
        if (!Helper::isGitInstalled() || !Helper::isGitInitialized()) {
            return true;
        }

        $this->grav->fireEvent('onGitSyncBeforeSynchronize');

        if ($this->git->hasChangesToCommit()) {
            $this->git->commit(); // <------ HERE
        }

        // synchronize with remote
        $this->git->sync();

        $this->grav->fireEvent('onGitSyncAfterSynchronize');

        return true;
    }

Apparently "hasChangesToCommit" for some reason gives the wrong result..

lambopedia commented 5 years ago
        $message = 'nothing to commit';
        $output = $this->execute('status ' . implode(' ', $paths));

        return (substr($output[count($output)-1], 0, strlen($message)) !== $message); // <--- PROBLEM IS HERE
lambopedia commented 5 years ago

In the logs, in fact, this:

[2018-12-21 21:05:50] grav.NOTICE: gitsync[command]: LC_ALL=en_US.UTF-8 git -C '/home/lambopedia.ru/docs/user/' commit --author="lambopedia <lambopedia@ya.ru>" -m '(Grav GitSync) Automatic Commit from lambopedia' 2>&1 [] []
[2018-12-21 21:05:50] grav.NOTICE: gitsync[output]: На ветке master нечего коммитить, нет изменений в рабочем каталоге [] []

I did not know that there is a comparison of the line and translated the message into English.

lambopedia commented 5 years ago

Hmm.. why is this command may not work? LC_ALL=en_US.UTF-8

lambopedia commented 5 years ago

Like this all work:

public function execute($command, $quiet = false)
    {
        try {                                        
            . . .
            if (DIRECTORY_SEPARATOR == '/') {
                // ++ lambopedia 2018.12.23
                //$command = 'LC_ALL=en_US.UTF-8 ' . $command;
                $command = 'LC_ALL=C ' . $command;
                // -- lambopedia 2018.12.23
            }             
           . . .
        } catch (\RuntimeException $e) {
            . . .
        }
    }
w00fz commented 5 years ago

Thanks @lambopedia this is now merged and released. Good catch!