Skip to content

Commit

Permalink
How am I this incompetent.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmchilton committed Nov 28, 2022
1 parent 3077d1e commit f8105c5
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions lib/tool_shed/util/hg_util.py
Expand Up @@ -26,17 +26,27 @@
INITIAL_CHANGELOG_HASH = "000000000000"


def _debug_hg_status(cwd: str) -> str:
try:
return unicodify(subprocess.check_output(["hg", "status"], stderr=subprocess.STDOUT, cwd=cwd))
except subprocess.CalledProcessError as cpe:
return f"*Failed to execute hg status - output was {unicodify(cpe.output)}"


def _debug_hg_log(cwd: str) -> str:
try:
return unicodify(subprocess.check_output(["hg", "log"], stderr=subprocess.STDOUT, cwd=cwd))
except subprocess.CalledProcessError as cpe:
return f"*Failed to execute hg log - output was {unicodify(cpe.output)}"


def handle_hg_exception(message: str, e: Exception, cwd: str) -> Exception:
message += f": {unicodify(e)}"
if isinstance(e, subprocess.CalledProcessError):
message += f"\nOutput was [{unicodify(e.output)}]"
try:
status_str = "\nstatus: " + unicodify(subprocess.check_output(["hg", "status"], stderr=subprocess.STDOUT, cwd=cwd))
except subprocess.CalledProcessError as cpe:
status_str = f"\nFailed to hg status - output was {unicodify(cpe.output)}"
except Exception as ge:
status_str = f"\nFailed to execute hg status - {unicodify(ge)}"
message += status_str
message += f"\nHG Status: {_debug_hg_status(cwd)}"
message += f"\nHG Log: {_debug_hg_log(cwd)}"
log.exception(message)
return Exception(message)


Expand All @@ -63,11 +73,17 @@ def archive_repository_revision(app, repository, archive_dir, changeset_revision

def commit_changeset(repo_path, full_path_to_changeset, username, message):
try:
log.info(f"About to execute hg commit of repo {repo_path}")
log.info(f"HG Status: {_debug_hg_status(repo_path)}")
log.info(f"HG Log: {_debug_hg_log(repo_path)}")
subprocess.check_output(
["hg", "commit", "-u", username, "-m", message, full_path_to_changeset],
stderr=subprocess.STDOUT,
cwd=repo_path,
)
log.info("POST COMMIT!!!!")
log.info(f"HG Status: {_debug_hg_status(repo_path)}")
log.info(f"HG Log: {_debug_hg_log(repo_path)}")
except subprocess.CalledProcessError as cpe:
if cpe.returncode == 1 and "nothing changed" in unicodify(cpe.output):
error_message = f"Error committing '{full_path_to_changeset}' to repository"
Expand Down

0 comments on commit f8105c5

Please sign in to comment.