[damned-lies] Revert the commit if git push failed



commit 04d8f8c0c0df4cb803f218a7ea5edd90d5a65726
Author: Claude Paroz <claude 2xlibre net>
Date:   Wed Feb 5 21:00:10 2014 +0100

    Revert the commit if git push failed

 stats/models.py |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)
---
diff --git a/stats/models.py b/stats/models.py
index 717e63d..dbfe4d6 100644
--- a/stats/models.py
+++ b/stats/models.py
@@ -730,8 +730,14 @@ class Branch(models.Model):
                     "cd \"%(dest)s\" && git commit -m \"%(msg)s\" --author \"%(author)s\"" % var_dict,
                     raise_on_error=True)
                 # git push
-                utils.run_shell_command(
-                    "cd \"%(dest)s\" && git push origin %(branch)s" % var_dict, raise_on_error=True)
+                try:
+                    utils.run_shell_command(
+                        "cd \"%(dest)s\" && git push origin %(branch)s" % var_dict, raise_on_error=True)
+                except OSError:
+                    # Revert the commit
+                    utils.run_shell_command(
+                        "cd \"%(dest)s\" && git reset --hard origin/%(branch)s" % var_dict)
+                    raise
         # Finish by updating stats
         self.update_stats(force=False)
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]