class_docstr: Operations with repos
class_docstr_tok: ["Operations","with","repos"]
docstr: Initializes the repo and configures its credentials in the project.
  Must be invoked before mounting the repo to a run.
  
  Example:
  
  ```python
  repo=RemoteRepo.from_url(
      repo_url="https://github.com/dstackai/dstack-examples",
      repo_branch="main",
  )
  client.repos.init(repo)
  ```
  
  By default, it uses the default Git credentials configured on the machine.
  You can override these credentials via the `git_identity_file` or `oauth_token` arguments of the `init` method.
  
  Once the repo is initialized, you can pass the repo object to the run:
  
  ```python
  run = client.runs.submit(
      configuration=...,
      repo=repo,
  )
  ```
  
  Args:
      repo: The repo to initialize.
      git_identity_file: The private SSH key path for accessing the remote repo.
      oauth_token: The GitHub OAuth token to access the remote repo.
docstr_tok: ["Initializes","the","repo","and","configures","its","credentials","in","the","project",".","Must","be","invoked","before","mounting","the","repo","to","a","run",".","Example",":","``","`","python","repo=RemoteRepo.from_url","(","repo_url=","''","https",":","\/\/github.com\/dstackai\/dstack-examples","''",",","repo_branch=","''","main","''",",",")","client.repos.init","(","repo",")","``","`","By","default",",","it","uses","the","default","Git","credentials","configured","on","the","machine",".","You","can","override","these","credentials","via","the","`","git_identity_file","`","or","`","oauth_token","`","arguments","of","the","`","init","`","method",".","Once","the","repo","is","initialized",",","you","can","pass","the","repo","object","to","the","run",":","``","`","python","run","=","client.runs.submit","(","configuration=","...",",","repo=repo",",",")","``","`","Args",":","repo",":","The","repo","to","initialize",".","git_identity_file",":","The","private","SSH","key","path","for","accessing","the","remote","repo",".","oauth_token",":","The","GitHub","OAuth","token","to","access","the","remote","repo","."]
code: def init(
      self,
      repo: Repo,
      git_identity_file: Optional[PathLike] = None,
      oauth_token: Optional[str] = None,
  ):
      """
      Initializes the repo and configures its credentials in the project.
      Must be invoked before mounting the repo to a run.
  
      Example:
  
      ```python
      repo=RemoteRepo.from_url(
          repo_url="https://github.com/dstackai/dstack-examples",
          repo_branch="main",
      )
      client.repos.init(repo)
      ```
  
      By default, it uses the default Git credentials configured on the machine.
      You can override these credentials via the `git_identity_file` or `oauth_token` arguments of the `init` method.
  
      Once the repo is initialized, you can pass the repo object to the run:
  
      ```python
      run = client.runs.submit(
          configuration=...,
          repo=repo,
      )
      ```
  
      Args:
          repo: The repo to initialize.
          git_identity_file: The private SSH key path for accessing the remote repo.
          oauth_token: The GitHub OAuth token to access the remote repo.
      """
      creds = None
      if isinstance(repo, RemoteRepo):
          try:
              creds = get_local_repo_credentials(
                  repo_data=repo.run_repo_data,
                  identity_file=git_identity_file,
                  oauth_token=oauth_token,
                  original_hostname=giturlparse.parse(
                      repo.repo_url
                  ).resource,
              )
          except InvalidRepoCredentialsError as e:
              raise ConfigurationError(*e.args)
      self._api_client.repos.init(
          self._project, repo.repo_id, repo.run_repo_data, creds
      )
  
file_path: dstack/src/dstack/api/_public/repos.py
imports: from pathlib import Path
  from typing import Optional, Union
  import giturlparse
  import requests
  from git import InvalidGitRepositoryError
  from dstack._internal.core.errors import ConfigurationError
  from dstack._internal.core.models.repos import LocalRepo, RemoteRepo
  from dstack._internal.core.models.repos.base import Repo, RepoType
  from dstack._internal.core.services.configs import ConfigManager
  from dstack._internal.core.services.repos import InvalidRepoCredentialsError, get_local_repo_credentials, load_repo
  from dstack._internal.utils.crypto import generate_rsa_key_pair
  from dstack._internal.utils.logging import get_logger
  from dstack._internal.utils.path import PathLike
  from dstack.api.server import APIClient
label_desc: Use image node_id 2 for calling the RepoCollection obj's underlying member method code with example usage: obj.init(repo, git_identity_file, oauth_token) without return types