|
1 | 1 | import json |
2 | 2 | import os |
3 | 3 | import time |
| 4 | +from traceback import print_exc |
4 | 5 | from subprocess import check_output, STDOUT |
5 | 6 | from vscode_notebook import SETTINGS_PATH, VERSION |
6 | 7 | from .message import print_err, print_info |
@@ -103,13 +104,28 @@ def do_git_push(self): |
103 | 104 | print_err('notebookbackup remote not found') |
104 | 105 | return False |
105 | 106 | # push to remote |
106 | | - print_info('Pushing to remote') |
107 | 107 | commit_msg = "auto backup " + str(mins) |
108 | | - out = check_output("git add -A && git commit -m \"{}\" && git push notebookbackup master".format(commit_msg), |
109 | | - stderr=STDOUT, shell=True).decode() |
110 | | - print_info('GIT LOG:\n\n' + out) |
| 108 | + # push only if changes |
| 109 | + out = check_output("git status -s", stderr=STDOUT, shell=True).decode() |
| 110 | + if not out: |
| 111 | + print_info('No changes detected, hence skipping git backup') |
| 112 | + return |
| 113 | + # save last push min in advance |
| 114 | + old_mins = self.json['last_git_push'] |
111 | 115 | self.json['last_git_push'] = mins |
112 | 116 | self.save_settings() |
| 117 | + # actual push |
| 118 | + try: |
| 119 | + print_info('Pushing to remote') |
| 120 | + out = check_output("git add -A && git commit -m \"{}\" && git push notebookbackup master".format(commit_msg), |
| 121 | + stderr=STDOUT, shell=True).decode() |
| 122 | + print_info('GIT LOG:\n\n' + out) |
| 123 | + except Exception: |
| 124 | + # revert back |
| 125 | + print_exc() |
| 126 | + print_err('git push did not happen') |
| 127 | + self.json['last_git_push'] = old_mins |
| 128 | + self.save_settings() |
113 | 129 |
|
114 | 130 | @staticmethod |
115 | 131 | def _find_in_array(item, arr): |
|
0 commit comments