code: def test_sync_with_pre_commit_hook(tmpdir):
      # Init git and create a pre-commit hook
      git = git_in_tmpdir(tmpdir)
      hook = str(tmpdir.join(".git/hooks/pre-commit"))
      with open(hook, "w") as fp:
          fp.write("#!/bin/sh\n" "jupytext --sync --pre-commit\n")
  
      st = os.stat(hook)
      os.chmod(hook, st.st_mode | stat.S_IEXEC)
  
      # Create a notebook that is not paired
      tmp_ipynb = str(tmpdir.join("notebook.ipynb"))
      tmp_md = str(tmpdir.join("notebook.md"))
      nb = new_notebook(cells=[new_markdown_cell("A short notebook")])
      write(nb, tmp_ipynb)
      assert os.path.isfile(tmp_ipynb)
      assert not os.path.isfile(tmp_md)
  
      git("add", "notebook.ipynb")
      git("status")
      git("commit", "-m", "created")
      git("status")
  
      assert "notebook.ipynb" in git(
          "ls-tree", "-r", "main", "--name-only"
      )
      assert "notebook.md" not in git(
          "ls-tree", "-r", "main", "--name-only"
      )
  
      assert os.path.isfile(tmp_ipynb)
      assert not os.path.exists(tmp_md)
  
      # Pair the notebook
      jupytext(["--set-formats", "ipynb,md", tmp_ipynb])
  
      # Remove the md file (it will be regenerated by the pre-commit hook)
      os.remove(tmp_md)
  
      # Commit the ipynb file
      git("add", "notebook.ipynb")
      git("status")
      git("commit", "-m", "paired")
      git("status")
  
      # The pre-commit script should have created and committed the md file
      assert "notebook.ipynb" in git(
          "ls-tree", "-r", "main", "--name-only"
      )
      assert "notebook.md" in git(
          "ls-tree", "-r", "main", "--name-only"
      )
      assert os.path.isfile(tmp_md)
      nb_md = read(tmp_md)
      compare_notebooks(nb_md, nb)
  
      # Edit the md file
      with open(tmp_md) as fp:
          md_text = fp.read()
  
      with open(tmp_md, "w") as fp:
          fp.write(
              md_text.replace("A short notebook", "Notebook was edited")
          )
  
      # commit the md file
      git("add", "notebook.md")
      git("status")
      git("commit", "-m", "edited md")
      git("status")
  
      # The pre-commit script should have sync and committed the ipynb file
      assert "notebook.ipynb" in git(
          "ls-tree", "-r", "main", "--name-only"
      )
      assert "notebook.md" in git(
          "ls-tree", "-r", "main", "--name-only"
      )
  
      nb = read(tmp_ipynb)
      compare_cells(
          nb.cells,
          [new_markdown_cell("Notebook was edited")],
          compare_ids=False,
      )
  
      # create and commit a jpg file
      tmp_jpg = str(tmpdir.join("image.jpg"))
      with open(tmp_jpg, "wb") as fp:
          fp.write(b"")
      git("add", "image.jpg")
      git("commit", "-m", "added image")
  
file_path: jupytext/tests/external/pre_commit/test_pre_commit_scripts.py
imports: import os
  import stat
  import unittest.mock
  import pytest
  from nbformat.v4.nbbase import new_code_cell, new_markdown_cell, new_notebook
  from jupytext import read, write
  from jupytext.cli import jupytext, system
  from jupytext.compare import compare_cells, compare_notebooks
label_desc: Use image node_id 4 for calling a global function with example usage: test_sync_with_pre_commit_hook(tmpdir) without return types