Skip to content

Instantly share code, notes, and snippets.

@Cerdic
Last active December 16, 2015 22:39
Show Gist options
  • Save Cerdic/5508086 to your computer and use it in GitHub Desktop.
Save Cerdic/5508086 to your computer and use it in GitHub Desktop.
Mon cherry-pick pour svn
#!/usr/bin/php
<?php
// Report d'un commit d'un repertoire sur un autre
// le script fait le merge svn et prepare le log de comit dans log.txt
// mais ne fait pas le commit automatiquement car risque de conflits
// il faut le faire suivre de la commande comit manuelle si le diff est OK
// Syntaxe :
// cherry-pick.php -rNNNN source dest
//
// exemple d'utilisation :
// ./cherry-pick.php -r20468 branches/spip-3.0/ spip/
// svn commit spip/ -F log.txt
$revision = $argv[1];
$source = $argv[2];
$dest = $argv[3];
function exect($c,$echo=true){
$output="";
if ($echo) echo $c."\n";
exec($c,$output);
if ($echo) echo implode("\n",$output)."\n";
return $output;
}
// s'assurer qu'on a pas de modifs locales sur la cible avant de merger
$output="";
exec($c="svn status --ignore-externals $dest",$output);
foreach($output as $o){
if (strncmp($o,"C ",2)==0
OR strncmp($o,"M ",2)==0
OR strncmp($o,"D ",2)==0
OR strncmp($o,"! ",2)==0
){
exect($c);
echo "Report impossible sur $dest : Il y a des modifs locales en attente\n";
die();
}
}
// up
exect("svn up --ignore-externals $source $dest",false);
// log
$output = exect("svn log $revision $source");
array_shift($output);
array_shift($output);
array_pop($output);
$log = trim(implode("\n",$output));
exect("svn merge ".str_replace("-r","-c",$revision)." $source $dest");
$log = "Report de ".trim($revision,"-")." : ".$log;
file_put_contents("log.txt",$log);
$output = exect("svn status --ignore-externals $dest");
// Regarder si il y a des conflits ou anomalies suite au merge
foreach($output as $o){
if (strncmp($o,"C ",2)==0
OR strncmp($o,"! ",2)==0
){
echo "/!\ Erreurs/Conflits lors du merge a resoudre avant de comit\n";
die();
}
}
exect("cat log.txt");
$c = "svn commit $dest -F log.txt";
// echo $c."\n";
// autocomit si pas de conflit :
exect($c);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment