2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-11-22 07:11:52 +00:00

beter(?) git error reporting

This commit is contained in:
Philip Sargent 2023-11-10 15:33:04 +02:00
parent 08c56644eb
commit 0c1601e1b0

View File

@ -180,7 +180,9 @@ def write_and_commit(files, message):
cmd_add = [git, "add", filename] cmd_add = [git, "add", filename]
cp_add = subprocess.run(cmd_add, cwd=cwd, capture_output=True, text=True) cp_add = subprocess.run(cmd_add, cwd=cwd, capture_output=True, text=True)
commands.append(cmd_add) commands.append(cmd_add)
git_add_returncode = ""
if cp_add.returncode != 0: if cp_add.returncode != 0:
git_add_returncode = cp_add.returncode
msgdata = ( msgdata = (
"Ask a nerd to fix this.\n\n" "Ask a nerd to fix this.\n\n"
+ cp_add.stderr + cp_add.stderr
@ -190,7 +192,7 @@ def write_and_commit(files, message):
+ str(cp_add.returncode) + str(cp_add.returncode)
) )
raise WriteAndCommitError( raise WriteAndCommitError(
f"CANNOT git on server for this file {filename}. Edits saved but not added to git.\n\n" f"PROBLEM with git on server for {filename}. Edits saved but [possibly] not added to git.\n\n"
+ msgdata + msgdata
) )
else: else:
@ -199,7 +201,7 @@ def write_and_commit(files, message):
cmd_commit = [git, "commit"] + filepaths + ["-m", message] cmd_commit = [git, "commit"] + filepaths + ["-m", message]
cm_status = subprocess.run(cmd_commit, cwd=cwd, capture_output=True, text=True) cm_status = subprocess.run(cmd_commit, cwd=cwd, capture_output=True, text=True)
commands.append(cmd_commit) commands.append(cmd_commit)
if cm_status == 0: if cm_status.returncode != 0:
msgdata = ( msgdata = (
"Commands: " + str(commands) + "Commands: " + str(commands) +
"Ask a nerd to fix this.\n\n" "Ask a nerd to fix this.\n\n"
@ -207,9 +209,10 @@ def write_and_commit(files, message):
+ "\n\n" + "\n\n"
+ "Stdout: " + cp_status.stdout + "Stdout: " + cp_status.stdout
+ "\n\nreturn code: " + str(cp_status.returncode) + "\n\nreturn code: " + str(cp_status.returncode)
+ "\n\ngit add return code in previous operation was: " + git_add_returncode
) )
raise WriteAndCommitError( raise WriteAndCommitError(
f"Error committing. Edits saved, added to git, but NOT committed.\n\n" f"ERROR committing. Edits saved, [maybe] added to git, but NOT committed.\n\n"
+ msgdata + msgdata
) )
cmd_status = [git, "status"] + filepaths cmd_status = [git, "status"] + filepaths
@ -226,7 +229,7 @@ def write_and_commit(files, message):
+ "\n\nreturn code: " + str(cp_status.returncode) + "\n\nreturn code: " + str(cp_status.returncode)
) )
raise WriteAndCommitError( raise WriteAndCommitError(
f"Error code with git on server for this file {filename}. Edits saved, added to git, but NOT committed.\n\n" f"Error code with git on server for this file {filename}. Edits saved, added to git, but NOT committed. Git status not clean.\n\n"
+ msgdata + msgdata
) )
except subprocess.SubprocessError: except subprocess.SubprocessError: