code: def get_or_create_stage(
      repo: "Repo",
      target: str,
      out: Optional[str] = None,
      to_remote: bool = False,
      force: bool = False,
  ) -> StageInfo:
      if out:
          target = resolve_output(target, out, force=force)
      path, wdir, out = resolve_paths(
          repo, target, always_local=to_remote and not out
      )
  
      try:
          (out_obj,) = repo.find_outs_by_path(target, strict=False)
          stage = out_obj.stage
          if not stage.is_data_source:
              msg = PIPELINE_TRACKED_UPDATE_FMT.format(
                  out=out, stage=stage, path=stage.relpath
              )
              raise DvcException(msg)
          return StageInfo(stage, output_exists=True)
      except OutputNotFoundError:
          stage = repo.stage.create(
              single_stage=True,
              validate=False,
              fname=path,
              wdir=wdir,
              outs=[out],
              force=force,
          )
          return StageInfo(stage, output_exists=False)
  
file_path: dvc/dvc/repo/add.py
imports: import os
  from contextlib import contextmanager
  from typing import TYPE_CHECKING, Dict, Iterator, List, NamedTuple, Optional, Tuple, Union
  from dvc.exceptions import CacheLinkError, DvcException, OutputDuplicationError, OutputNotFoundError, OverlappingOutputPathsError
  from dvc.repo.scm_context import scm_context
  from dvc.ui import ui
  from dvc.utils import glob_targets, resolve_output, resolve_paths
  from .None import locked
label_desc: Use image node_id 2 for calling a global function with example usage: get_or_create_stage(repo, target, out, to_remote, force) and returns: StageInfo, StageInfo