From 8fa25c815a7283bb8959e571c3eef8c3b4fd8681 Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Sat, 13 Aug 2022 23:57:37 +0300 Subject: [PATCH] fix apparent error when running on dev system --- core/utils.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/core/utils.py b/core/utils.py index 228a6ad..521892c 100644 --- a/core/utils.py +++ b/core/utils.py @@ -100,18 +100,28 @@ def only_commit(fname, message): try: cp_add = subprocess.run([git, "add", filename], cwd=cwd, capture_output=True, text=True) if cp_add.returncode != 0: - msgdata = f'Ask a nerd to fix this problem in only_commit().\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) + msgdata = f'Ask a nerd to fix this problem in only_commit().\n--{cp_add.stderr}\n--{cp_add.stdout}\n--return code:{str(cp_add.returncode)}' + raise WriteAndCommitError(f'CANNOT git ADD on server for this file {filename}. Edits saved but not added to git.\n\n' + msgdata) cp_commit = subprocess.run([git, "commit", "-m", message], 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 = f'Ask a nerd to fix this problem in only_commit().\n\n{cp_add.stderr}\n\n{cp_add.stdout}\n\nreturn code:{str(cp_add.returncode)}' - print(msgdata) - raise WriteAndCommitError(f'Error code with git on server for this file {filename}. Edits saved, added to git, but NOT committed.\n\n' + msgdata) + # This produces return code = 1 if it commits OK, but when the local repo still needs to be pushed to origin/loser + # which will be the case when running a test troggle system on a development machine + devok_text ='''On branch master +Your branch is ahead of 'origin/master' by 1 commit. + (use "git push" to publish your local commits) + +nothing to commit, working tree clean +''' + if cp_commit.returncode == 1 and cp_commit.stdout == devok_text: + pass + else: + if cp_commit.returncode != 0 and cp_commit.stdout != 'nothing to commit, working tree clean': + msgdata = f'--Ask a nerd to fix this problem in only_commit().\n--{cp_commit.stderr}\n--"{cp_commit.stdout}"\n--return code:{str(cp_commit.returncode)}' + print(msgdata) + 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.') + raise WriteAndCommitError(f'CANNOT git COMMIT on server for this file {filename}. Subprocess error. Edits not saved.\nAsk a nerd to fix this.') def write_and_commit(files, message): """Writes the content to the filepath and adds and commits the file to git. If this fails, a WriteAndCommitError is raised.