import subprocess

S = "a2f335f81e6a67f9aa9ea4e6e4bdfab44a1f9200"
f = ".github/workflows/ci.yml"

show = subprocess.run(["git", "show", f"{S}:{f}"], capture_output=True).stdout
blob = subprocess.run(["git", "cat-file", "blob", f"{S}:{f}"], capture_output=True).stdout

print(f"git show      : bytes={len(show):6} CR={show.count(chr(13).encode()):5}")
print(f"cat-file blob : bytes={len(blob):6} CR={blob.count(chr(13).encode()):5}")
print(f"identical     : {show == blob}")
print()

# And the inline-quoting trap, demonstrated rather than asserted:
# an EMPTY grep pattern matches every line and returns the LINE COUNT.
n = subprocess.run(["bash", "-c", f"git cat-file blob {S}:{f} | grep -c ''"],
                   capture_output=True, text=True).stdout.strip()
real = subprocess.run(["bash", "-c", f"git cat-file blob {S}:{f} | grep -c $'\\r'"],
                      capture_output=True, text=True).stdout.strip()
print(f"grep -c ''      (empty pattern) -> {n}   <- equals the line count")
print(f"grep -c $'\\r'   (real CR)       -> {real}")
