help=f"Optionally, when converting from {p_label('Markdown')} to {p_label('HTML')}, provide the relative or absolute path to a JSON file containing the order in which the files should be arranged in the final produced HTML. If a file is not provided, the default ordering will be used. The default ordering parses first clauses (named {p_label(f'clause-{{number4-20}}')}), then annexes (named {p_label(f'annex-{{lettera-z}}')}). Any files in the source directory not included in the list will be included at the end in alphabetical order. However, any files present in the JSON that are not present in the source directory will cause an error and the script to exit prematurely.",
)
parser.add_argument(
"--diff",
action="store_true",
help="Optionally, when converting from Markdown to HTML, highlight differences between the current Markdown files and the previous version stored on disk. When used with --git, the target branch or commit is used as the comparison source.",
)
parser.add_argument(
"--git",
nargs="?",
const=True,
help="Optionally, when provided, uses Git to get the target branch or commit and use it as the source of the diff when converting from Markdown to HTML. This argument can only be used with the --diff argument.",
f"The provided Git commit hash {p_label(target_to_checkout)} is the same as the current commit in the Git repository at {p_label('--src')}. Please provide a different commit hash to compare against."
)
)
sys.exit(1)
if (
target_is_branch
andcurrent_branch==target_to_checkout
andcurrent_commit_hash==last_remote_commit_hash
):
print(
p_error(
f"The provided Git branch name {p_label(target_to_checkout)} is the same as the current branch in the Git repository at {p_label('--src')}. Please provide a different branch name to compare against."
)
)
sys.exit(1)
# If target_to_checkout is a branch name, get the latest remote commit hash
iftarget_is_branch:
branch_target=target_to_checkout
target_to_checkout=last_remote_commit_hash
ifnottarget_to_checkout:
print(
p_error(
f"Could not retrieve the latest remote commit hash for branch {p_label(branch_target)} in the Git repository at {p_label('--src')}."
f"The base HTML files for commit {p_label(target_to_checkout)}{f'(branch:{p_label(branch_target)})' if branch_target else ''}have already been generated. Using existing files for diff..."
f"Could not stash changes in the Git repository at {p_label('--src')}."
)
)
sys.exit(1)
# Checkout to the target branch/commit
ifnotgit_helper.checkout(SRC,target_to_checkout):
print(
p_error(
f"Could not checkout to commit {p_label(target_to_checkout)}{f'(branch:{p_label(branch_target)})' if branch_target else ''}in the Git repository at {p_label('--src')}."