2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2026-02-08 10:26:17 +00:00

Wallet edit now using refactored git add/commit system

This commit is contained in:
2024-12-29 19:35:20 +00:00
parent a3c7f165b9
commit e3a9498656
3 changed files with 34 additions and 75 deletions

View File

@@ -210,7 +210,7 @@ def get_cookie(request):
return editor
def git_string(author_string):
"""Rewrites the supplied editor string intoa git-complient author string
"""Rewrites the supplied editor string into a git-complient author string
Uses a regular expression for a git-compatible author string written mostly by Copilot
valid example "John Doe <john.doe@example.com>"
"""
@@ -259,7 +259,7 @@ def git_add(filename, cwd, commands=[]):
def git_commit(cwd, message, editor, commands=[]):
"""Commits whatever has been Staged by git in this directory
"""Commits whatever has been Staged by git in this directory 'cwd'
"""
git = settings.GIT
print(f"git commit in {cwd}")
@@ -277,25 +277,23 @@ def git_commit(cwd, message, editor, commands=[]):
# which will be the case when running a test troggle system on a development machine
# Several ways of testing if the commit failed
#This produces return code = 1 if it commits OK, but when the repo still needs to be pushed to origin/expoweb
# if (not cp_commit.stdout) or len(cp_commit.stdout) < 2 or cp_commit.stdout.split("\n")[-2] != "nothing to commit, working tree clean":
# if cp_commit.stdout.split("\n")[-2] != "nothing to commit, working tree clean":
# if cp_commit.returncode == 1 and cp_commit.stdout == DEV_OK: # only good for 1 commit ahead of origin/repo
if cp_commit.returncode == 1 and cp_commit.stdout == DEV_OK: # only good for 1 commit ahead of origin/repo
pass
else:
if cp_commit.returncode != 0 and not cp_commit.stdout.strip().endswith(
"nothing to commit, working tree clean"
):
msgdata = f'--Ask a nerd to fix this problem in add_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 in this directory: {cwd}. Edits saved, added to git, but NOT committed.\n\n"
+ msgdata
)
if cp_commit.returncode != 0 and not cp_commit.stdout.strip().endswith(
"nothing to commit, working tree clean"
):
msgdata = f'--Ask a nerd to fix this problem in git_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 in this directory: {cwd}. Edits saved, added to git, but NOT committed.\n\n"
+ msgdata
)
return commands
def add_commit(fname, message, editor=None):
"""Only used to commit a survex file edited and saved in view/survex.py"""
def add_commit(fname, message, editor):
"""Used to commit a survex file edited and saved in view/survex.py
and also contents.json for an edited wallet"""
cwd = fname.parent
filename = fname.name
commands = []
@@ -307,6 +305,7 @@ def add_commit(fname, message, editor=None):
editor = "Anathema Device <a.device@potatohut.expo>"
try:
# print(f"add_commit: {editor=} {filename=} {cwd=}")
commands = git_add(filename, cwd, commands)
commands = git_commit(cwd, message, editor, commands)