Skip to content
Extraits de code Groupes Projets
Valider 548cb829 rédigé par Thomas Steur's avatar Thomas Steur
Parcourir les fichiers

commit only if there is something to commit

parent ebfdc858
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -38,9 +38,16 @@ class GitCommit extends Command ...@@ -38,9 +38,16 @@ class GitCommit extends Command
return; return;
} }
$cmd = sprintf("grep path .gitmodules | sed 's/.*= //'"); if (!$this->hasUnpushedCommits()) {
$submodules = shell_exec($cmd); $dialog = $this->getHelperSet()->get('dialog');
$submodules = explode("\n", $submodules); $question = '<question>No unpushed commits, do you just want to converge submodules?</question>';
if (!$dialog->askConfirmation($output, $question, false)) {
$output->writeln('<info>Cool, nothing done. Stage files using "git add" and try again.</info>');
return;
}
}
$submodules = $this->getSubmodulePaths();
foreach ($submodules as $submodule) { foreach ($submodules as $submodule) {
if (empty($submodule)) { if (empty($submodule)) {
...@@ -63,8 +70,10 @@ class GitCommit extends Command ...@@ -63,8 +70,10 @@ class GitCommit extends Command
$this->passthru($cmd, $output); $this->passthru($cmd, $output);
} }
$cmd = sprintf('cd %s && git commit -m "%s"', PIWIK_DOCUMENT_ROOT, $commitMessage); if ($this->hasUnpushedCommits()) {
$this->passthru($cmd, $output); $cmd = sprintf('cd %s && git commit -m "%s"', PIWIK_DOCUMENT_ROOT, $commitMessage);
$this->passthru($cmd, $output);
}
foreach ($submodules as $submodule) { foreach ($submodules as $submodule) {
if (empty($submodule)) { if (empty($submodule)) {
...@@ -75,8 +84,10 @@ class GitCommit extends Command ...@@ -75,8 +84,10 @@ class GitCommit extends Command
$this->passthru($cmd, $output); $this->passthru($cmd, $output);
} }
$cmd = sprintf('cd %s && git commit -m "Converged submodules"', PIWIK_DOCUMENT_ROOT); if ($this->hasUnpushedCommits()) {
$this->passthru($cmd, $output); $cmd = sprintf('cd %s && git commit -m "Converged submodules"', PIWIK_DOCUMENT_ROOT);
$this->passthru($cmd, $output);
}
} }
private function passthru($cmd, OutputInterface $output) private function passthru($cmd, OutputInterface $output)
...@@ -84,4 +95,25 @@ class GitCommit extends Command ...@@ -84,4 +95,25 @@ class GitCommit extends Command
$output->writeln('Executing command: ' . $cmd); $output->writeln('Executing command: ' . $cmd);
passthru($cmd); passthru($cmd);
} }
private function hasUnpushedCommits()
{
$cmd = sprintf('cd %s && git log @{u}..',PIWIK_DOCUMENT_ROOT);
$hasUnpushedCommits = shell_exec($cmd);
$hasUnpushedCommits = trim($hasUnpushedCommits);
return !empty($hasUnpushedCommits);
}
/**
* @return array
*/
private function getSubmodulePaths()
{
$cmd = sprintf("grep path .gitmodules | sed 's/.*= //'");
$submodules = shell_exec($cmd);
$submodules = explode("\n", $submodules);
return $submodules;
}
} }
\ No newline at end of file
...@@ -34,4 +34,13 @@ class GitPush extends Command ...@@ -34,4 +34,13 @@ class GitPush extends Command
$output->writeln('Executing command: ' . $cmd); $output->writeln('Executing command: ' . $cmd);
passthru($cmd); passthru($cmd);
} }
private function hasUnpushedCommits()
{
$cmd = sprintf('cd %s && git log @{u}..',PIWIK_DOCUMENT_ROOT);
$hasUnpushedCommits = shell_exec($cmd);
$hasUnpushedCommits = trim($hasUnpushedCommits);
return !empty($hasUnpushedCommits);
}
} }
\ No newline at end of file
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter