code: def _check_git_state(session, version_tag):
      """Check state of the git repository, prior to making the release."""
      # Ensure the upstream remote pushes to the correct URL.
      allowed_upstreams = [
          "git@github.com:pypa/packaging.git",
          "https://github.com/pypa/packaging.git",
      ]
      result = subprocess.run(
          ["git", "remote", "get-url", "--push", "upstream"],
          capture_output=True,
          encoding="utf-8",
      )
      if result.stdout.rstrip() not in allowed_upstreams:
          session.error(
              f"git remote `upstream` is not one of {allowed_upstreams}"
          )
      # Ensure we're on main branch for cutting a release.
      result = subprocess.run(
          ["git", "rev-parse", "--abbrev-ref", "HEAD"],
          capture_output=True,
          encoding="utf-8",
      )
      if result.stdout != "main\n":
          session.error(f"Not on main branch: {result.stdout!r}")
  
      # Ensure there are no uncommitted changes.
      result = subprocess.run(
          ["git", "status", "--porcelain"],
          capture_output=True,
          encoding="utf-8",
      )
      if result.stdout:
          print(result.stdout, end="", file=sys.stderr)
          session.error("The working tree has uncommitted changes")
  
      # Ensure this tag doesn't exist already.
      result = subprocess.run(
          ["git", "rev-parse", version_tag],
          capture_output=True,
          encoding="utf-8",
      )
      if not result.returncode:
          session.error(
              f"Tag already exists! {version_tag} -- {result.stdout!r}"
          )
  
      # Back up the current git reference, in a tag that's easy to clean up.
      _release_backup_tag = "auto/release-start-" + str(
          int(time.time())
      )
      session.run("git", "tag", _release_backup_tag, external=True)
  
imports: import contextlib
  import datetime
  import difflib
  import glob
  import os
  import re
  import shutil
  import subprocess
  import sys
  import tempfile
  import textwrap
  import time
  import webbrowser
  from pathlib import Path
  import nox
label_desc: Use image node_id 7 for calling a global function with example usage: _check_git_state(session, version_tag) without return types