summaryrefslogtreecommitdiffstats
path: root/core/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'core/utils.py')
-rw-r--r--core/utils.py23
1 files changed, 13 insertions, 10 deletions
diff --git a/core/utils.py b/core/utils.py
index 5b696dd..228a6ad 100644
--- a/core/utils.py
+++ b/core/utils.py
@@ -133,7 +133,7 @@ def write_and_commit(files, message):
kwargs = {"encoding": encoding}
else:
mode = "wb"
- kwargs = {}
+ kwargs = {}
try:
with open(filepath, mode, **kwargs) as f:
print(f'WRITING{cwd}---{filename} ')
@@ -143,18 +143,21 @@ def write_and_commit(files, message):
except PermissionError:
raise WriteAndCommitError(f'CANNOT save this file.\nPERMISSIONS incorrectly set on server for this file {filename}. Ask a nerd to fix this.')
- cp_add = subprocess.run([git, "add", filename], cwd=cwd, capture_output=True, text=True)
- if cp_add.returncode != 0:
- msgdata = 'Ask a nerd to fix this.\n\n' + cp_add.stderr + '\n\n' + cp_add.stdout + '\n\nreturn code: ' + str(cp_add.returncode)
- raise WriteAndCommitError(f'CANNOT git on server for this file {filename}. Edits saved but not added to git.\n\n' + msgdata)
-
+ cp_diff = subprocess.run([git, "diff", filename], cwd=cwd, capture_output=True, text=True)
+ if cp_diff.returncode == 0:
+ cp_add = subprocess.run([git, "add", filename], cwd=cwd, capture_output=True, text=True)
+ if cp_add.returncode != 0:
+ msgdata = 'Ask a nerd to fix this.\n\n' + cp_add.stderr + '\n\n' + cp_add.stdout + '\n\nreturn code: ' + str(cp_add.returncode)
+ raise WriteAndCommitError(f'CANNOT git on server for this file {filename}. Edits saved but not added to git.\n\n' + msgdata)
+ else:
+ print("No change %s" % filepah)
cp_commit = subprocess.run([git, "commit", "-m", message], cwd=cwd, capture_output=True, text=True)
+ cp_status = subprocess.run([git, "status"], cwd=cwd, capture_output=True, text=True)
# This produces return code = 1 if it commits OK, but when the repo still needs to be pushed to origin/expoweb
- if cp_commit.returncode != 0 and cp_commit.stdout != 'nothing to commit, working tree clean':
- msgdata = 'Ask a nerd to fix this.\n\n' + cp_commit.stderr + '\n\n' + cp_commit.stdout + '\n\nreturn code: ' + str(cp_commit.returncode)
- print(msgdata)
+ if cp_status.stdout.split("\n")[-2] != 'nothing to commit, working tree clean':
+ print("FOO: ", cp_status.stdout.split("\n")[-2])
+ msgdata = 'Ask a nerd to fix this.\n\n' + cp_status.stderr + '\n\n' + cp_status.stdout + '\n\nreturn code: ' + str(cp_status.returncode)
raise WriteAndCommitError(f'Error code with git on server for this file {filename}. Edits saved, added to git, but NOT committed.\n\n' + msgdata)
-
except subprocess.SubprocessError:
raise WriteAndCommitError(f'CANNOT git on server for this file {filename}. Subprocess error. Edits not saved.\nAsk a nerd to fix this.')