git-deploy
git-deploy copied to clipboard
=== ERROR: Pushed branch does not match BRANCH ===
I can't understand why it is giving me the error... I successfully pulled manually using git, but the script gives me this error everytime i run it. Any help?
Same here
¿Do you have more info about this?
Hi Edo/Vincenteguerra
I've found the error in the script and solved it, the error happens at line 60 of deploy.php as we're unable to reference the branch properly.
As it looks like JSON Structure from bitbucket/git has changed and cannot read response properly from branch.
Try replacing the whole IF section with following code:
foreach ($json["push"]["changes"] as $change) {
if (
(
isset($change["old"]["type"])
&& isset($change["old"]["name"])
&& $change["old"]["type"] == "branch"
&& $change["old"]["name"] == "master"
)
|| (
isset($change["new"]["type"])
&& isset($change["new"]["name"])
&& $change["new"]["type"] == "branch"
&& $change["new"]["name"] == "master"
)
) {
exec("git pull https://YOUR_GIT_USERNAME:[email protected]/YOUR_GIT_USER/GIT_NAME.git YOUR_BRANCH_NAME");
die("Complete.");
}
}
you can structure your code as per vicenteguerra script as well but i've reduced my script code as i'm just going to pull from specific branch when webhook is called
Same here with bitbucket
Hi @vatsh95 can you send your complete deploy.php?
I have the error"Unexpected 'else' (74, 3)" and "syntax error, unexpected 'else' (T_ELSE) (74, 9)"
As all changes should relate to the same branch I would think, maybe a check like $json['push']['changes'][0]['new']['name'] === BRANCH
is sufficient for bitbucket, as long as BRANCH is set to the raw branch name like 'master'.
@vicenteguerra do you have any plans to support merge request events? With gitlab the property to compare is "target_branch" instead of "ref".
@aanderse can you open a new issue for that?
@JacobDB certainly: https://github.com/vicenteguerra/git-deploy/issues/33
I am using Bitbucket, and I still get an error. Only time is recorded in the log file. 17-04-2019 (03:38:59)
Which part is the problem? :(
##deployer.php // Check for a GitHub signature if (!empty(TOKEN) && isset($_SERVER["HTTP_X_HUB_SIGNATURE"]) && $token !== hash_hmac($algo, $content, TOKEN)) { forbid($file, "X-Hub-Signature does not match TOKEN"); // Check for a GitLab token } elseif (!empty(TOKEN) && isset($_SERVER["HTTP_X_GITLAB_TOKEN"]) && $token !== TOKEN) { forbid($file, "X-GitLab-Token does not match TOKEN"); // Check for a $_GET token } elseif (!empty(TOKEN) && isset($_GET["token"]) && $token !== TOKEN) { forbid($file, "$_GET["token"] does not match TOKEN"); // if none of the above match, but a token exists, exit } elseif (!empty(TOKEN) && !isset($_SERVER["HTTP_X_HUB_SIGNATURE"]) && !isset($_SERVER["HTTP_X_GITLAB_TOKEN"]) && !isset($_GET["token"])) { forbid($file, "No token detected"); } else { // check if pushed branch matches branch specified in config foreach ($json["push"]["changes"] as $change) { if ( ( isset($change["old"]["type"]) && isset($change["old"]["name"]) && $change["old"]["type"] == "branch" && $change["old"]["name"] == "master" ) || ( isset($change["new"]["type"]) && isset($change["new"]["name"]) && $change["new"]["type"] == "branch" && $change["new"]["name"] == "master" ) ) { exec("git pull origin master"); die("Complete."); } } }
I just tried to set this up for a GitHub repository and it's failing. Printing out the array $json returns nothing. Am I missing anything?
I just tried to set this up for a GitHub repository and it's failing. Printing out the array $json returns nothing. Am I missing anything?
This is because I didn't RTFM. Forgot to change the Content Type to json on the Webhooks screen in the repository. Shwoopsie!
Any status updates on this issue? It's still broken for Bitbucket.
Add this line in deployer.php on line 10:
if (isset($json['push']['changes'][0]['new']['name'])&&empty($json['ref'])) $json['ref']=$json['push']['changes'][0]['new']['name'];
That worked for me.
Add this line in deployer.php on line 10:
if (isset($json['push']['changes'][0]['new']['name'])&&empty($json['ref'])) $json['ref']=$json['push']['changes'][0]['new']['name'];
That worked for me.
Could you be more specific with this? On line 10 in deployer.php I see this:
// retrieve the token
What version do you have?
Add this line in deployer.php on line 10:
if (isset($json['push']['changes'][0]['new']['name'])&&empty($json['ref'])) $json['ref']=$json['push']['changes'][0]['new']['name'];
That worked for me.Could you be more specific with this? On line 10 in deployer.php I see this:
// retrieve the token
What version do you have?
I added it before the comment:
$DIR = preg_match("//$/", DIR) ? DIR : DIR . "/";
// bitbucket ref issue https://github.com/vicenteguerra/git-deploy/issues/23 if (isset($json['push']['changes'][0]['new']['name'])&&empty($json['ref'])) $json['ref']=$json['push']['changes'][0]['new']['name'];
// retrieve the token if (!$token && isset($_SERVER["HTTP_X_HUB_SIGNATURE"])) { list($algo, $token) = explode("=", $_SERVER["HTTP_X_HUB_SIGNATURE"], 2) + array("", "");
hey , i was getting the same error , and after a few hours i was trying different changes in the code to figure out what was the problem (fun fact it was me) I realized that i was having the Content type from the github webhook settings set to application/x-www-form-urlencoded. So the "fix" for me was to set the Content type to application/json
hey , i was getting the same error , and after a few hours i was trying different changes in the code to figure out what was the problem (fun fact it was me) I realized that i was having the Content type from the github webhook settings set to application/x-www-form-urlencoded. So the "fix" for me was to set the Content type to application/json
Are you using bitbucket or github ?
hey , i was getting the same error , and after a few hours i was trying different changes in the code to figure out what was the problem (fun fact it was me) I realized that i was having the Content type from the github webhook settings set to application/x-www-form-urlencoded. So the "fix" for me was to set the Content type to application/json
Are you using bitbucket or github ?
Github
Hi,
Same here with gitlab
=== ERROR: Pushed branch does not match BRANCH ===
Hi Edo/Vincenteguerra
I've found the error in the script and solved it, the error happens at line 60 of deploy.php as we're unable to reference the branch properly.
As it looks like JSON Structure from bitbucket/git has changed and cannot read response properly from branch.
Try replacing the whole IF section with following code:
foreach ($json["push"]["changes"] as $change) { if ( ( isset($change["old"]["type"]) && isset($change["old"]["name"]) && $change["old"]["type"] == "branch" && $change["old"]["name"] == "master" ) || ( isset($change["new"]["type"]) && isset($change["new"]["name"]) && $change["new"]["type"] == "branch" && $change["new"]["name"] == "master" ) ) { exec("git pull https://YOUR_GIT_USERNAME:[email protected]/YOUR_GIT_USER/GIT_NAME.git YOUR_BRANCH_NAME"); die("Complete."); } }
you can structure your code as per vicenteguerra script as well but i've reduced my script code as i'm just going to pull from specific branch when webhook is called
Are you talking about deployer.php?