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

testing git commit command

parent 548cb829
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -34,13 +34,13 @@ class GitCommit extends Command ...@@ -34,13 +34,13 @@ class GitCommit extends Command
$commitMessage = $input->getOption('message'); $commitMessage = $input->getOption('message');
if (empty($commitMessage)) { if (empty($commitMessage)) {
$output->writeln('No message specified'); $output->writeln('No message specified. Use option -m or --message.');
return; return;
} }
if (!$this->hasUnpushedCommits()) { if (!$this->hasChangesToBeCommitted()) {
$dialog = $this->getHelperSet()->get('dialog'); $dialog = $this->getHelperSet()->get('dialog');
$question = '<question>No unpushed commits, do you just want to converge submodules?</question>'; $question = '<question>There are no changes to be commited in the super repo, do you just want to commit and converge submodules?</question>';
if (!$dialog->askConfirmation($output, $question, false)) { if (!$dialog->askConfirmation($output, $question, false)) {
$output->writeln('<info>Cool, nothing done. Stage files using "git add" and try again.</info>'); $output->writeln('<info>Cool, nothing done. Stage files using "git add" and try again.</info>');
return; return;
...@@ -54,9 +54,8 @@ class GitCommit extends Command ...@@ -54,9 +54,8 @@ class GitCommit extends Command
continue; continue;
} }
$cmd = sprintf('cd %s/%s && git status --porcelain', PIWIK_DOCUMENT_ROOT, $submodule); $status = $this->getStatusOfSubmodule($submodule);
$status = trim(shell_exec($cmd)); if (false !== strpos($status, '?? ')) {
if (false !== strpos($status, '??')) {
$output->writeln(sprintf('%s has untracked changes, will ignore. Status: %s', $submodule, $status)); $output->writeln(sprintf('%s has untracked changes, will ignore. Status: %s', $submodule, $status));
continue; continue;
} }
...@@ -70,7 +69,7 @@ class GitCommit extends Command ...@@ -70,7 +69,7 @@ class GitCommit extends Command
$this->passthru($cmd, $output); $this->passthru($cmd, $output);
} }
if ($this->hasUnpushedCommits()) { if ($this->hasChangesToBeCommitted()) {
$cmd = sprintf('cd %s && git commit -m "%s"', PIWIK_DOCUMENT_ROOT, $commitMessage); $cmd = sprintf('cd %s && git commit -m "%s"', PIWIK_DOCUMENT_ROOT, $commitMessage);
$this->passthru($cmd, $output); $this->passthru($cmd, $output);
} }
...@@ -84,7 +83,7 @@ class GitCommit extends Command ...@@ -84,7 +83,7 @@ class GitCommit extends Command
$this->passthru($cmd, $output); $this->passthru($cmd, $output);
} }
if ($this->hasUnpushedCommits()) { if ($this->hasChangesToBeCommitted()) {
$cmd = sprintf('cd %s && git commit -m "Converged submodules"', PIWIK_DOCUMENT_ROOT); $cmd = sprintf('cd %s && git commit -m "Converged submodules"', PIWIK_DOCUMENT_ROOT);
$this->passthru($cmd, $output); $this->passthru($cmd, $output);
} }
...@@ -96,13 +95,23 @@ class GitCommit extends Command ...@@ -96,13 +95,23 @@ class GitCommit extends Command
passthru($cmd); passthru($cmd);
} }
private function hasUnpushedCommits() private function hasChangesToBeCommitted()
{ {
$cmd = sprintf('cd %s && git log @{u}..',PIWIK_DOCUMENT_ROOT); $cmd = sprintf('cd %s && git status --porcelain', PIWIK_DOCUMENT_ROOT);
$hasUnpushedCommits = shell_exec($cmd); $result = shell_exec($cmd);
$hasUnpushedCommits = trim($hasUnpushedCommits); $result = trim($result);
return !empty($hasUnpushedCommits); if (false !== strpos($result, 'M ')) {
// stages
return true;
}
if (false !== strpos($result, 'MM ')) {
// staged and modified
return true;
}
return false;
} }
/** /**
...@@ -116,4 +125,12 @@ class GitCommit extends Command ...@@ -116,4 +125,12 @@ class GitCommit extends Command
return $submodules; return $submodules;
} }
protected function getStatusOfSubmodule($submodule)
{
$cmd = sprintf('cd %s/%s && git status --porcelain', PIWIK_DOCUMENT_ROOT, $submodule);
$status = trim(shell_exec($cmd));
return $status;
}
} }
\ No newline at end of file
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter