def main()

in tools/codegen-diff-revisions.py [0:0]


def main():
    if len(sys.argv) != 3:
        eprint("Usage: codegen-diff-revisions.py <repository root> <base commit sha>")
        sys.exit(1)

    repository_root = sys.argv[1]
    base_commit_sha = sys.argv[2]
    os.chdir(repository_root)
    head_commit_sha = get_cmd_output("git rev-parse HEAD")

    # Make sure the working tree is clean
    if get_cmd_status("git diff --quiet") != 0:
        eprint("working tree is not clean. aborting")
        sys.exit(1)

    if running_in_github_actions():
        eprint(f"Fetching base revision {base_commit_sha} from GitHub...")
        run(f"git fetch --no-tags --progress --no-recurse-submodules --depth=1 origin {base_commit_sha}")

    # Generate code for HEAD
    eprint(f"Creating temporary branch with generated code for the HEAD revision {head_commit_sha}")
    run(f"git checkout {head_commit_sha} -b {HEAD_BRANCH_NAME}")
    generate_and_commit_generated_code(head_commit_sha)

    # Generate code for base
    eprint(f"Creating temporary branch with generated code for the base revision {base_commit_sha}")
    run(f"git checkout {base_commit_sha} -b {BASE_BRANCH_NAME}")
    generate_and_commit_generated_code(base_commit_sha)

    bot_message = make_diffs(base_commit_sha, head_commit_sha)
    write_to_file(f"{OUTPUT_PATH}/bot-message", bot_message)

    # Clean-up that's only really useful when testing the script in local-dev
    if not running_in_github_actions():
        run("git checkout main")
        run(f"git branch -D {BASE_BRANCH_NAME}")
        run(f"git branch -D {HEAD_BRANCH_NAME}")