code: def test_gitignore_when_checkout(tmp_dir, dvc, scm):
      tmp_dir.dvc_gen("file_in_a_master", "master", commit="master")
  
      scm.checkout("branch", True)
      ret = main(["checkout", "--force"])
      assert ret == 0
      tmp_dir.dvc_gen("file_in_a_branch", "branch", commit="branch")
  
      scm.checkout("master")
      ret = main(["checkout", "--force"])
      assert ret == 0
  
      ignored = get_gitignore_content()
  
      assert len(ignored) == 1
      assert "/file_in_a_master" in ignored
  
      scm.checkout("branch")
      ret = main(["checkout", "--force"])
      assert ret == 0
      ignored = get_gitignore_content()
      assert "/file_in_a_branch" in ignored
  
imports: import logging
  import os
  import shutil
  import stat
  import textwrap
  import pytest
  from dvc.cli import main
  from dvc.dvcfile import PROJECT_FILE, load_file
  from dvc.exceptions import CheckoutError, CheckoutErrorSuggestGit, NoOutputOrStageError
  from dvc.fs import system
  from dvc.stage.exceptions import StageFileDoesNotExistError
  from dvc.utils import relpath
  from dvc.utils.fs import remove
  from tests.utils import get_gitignore_content
label_desc: Use image node_id 7 for calling a global function with example usage: test_gitignore_when_checkout(tmp_dir, dvc, scm) without return types