GitRepo API#
You can obtain a [GitApi][hopsworks_common.core.git_api.GitApi] handle via Project.get_git_api. Once you have an API handle, you can use it to obtain GitProvider objects using the following methods:
clone #
clone(
url: str,
path: str,
provider: Literal["GitHub", "GitLab", "BitBucket"]
| None = None,
branch: str = None,
) -> git_repo.GitRepo
Clone a new Git Repo in to Hopsworks Filesystem.
import hopsworks
project = hopsworks.login()
git_api = project.get_git_api()
git_repo = git_api.clone("https://github.com/logicalclocks/hops-examples.git", "Resources", "GitHub")
| PARAMETER | DESCRIPTION |
|---|---|
url | URL to the git repository. TYPE: |
path | Path in Hopsworks Filesystem to clone the repo to. TYPE: |
provider | The git provider where the repo is currently hosted. TYPE: |
branch | The branch to clone, defaults to the configured default branch. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
git_repo.GitRepo | Git repository object. |
| RAISES | DESCRIPTION |
|---|---|
hopsworks.client.exceptions.RestAPIError | If the backend encounters an error when handling the request. |
get_repo #
Get the cloned Git repository.
| PARAMETER | DESCRIPTION |
|---|---|
name | Name of the git repository. TYPE: |
path | Optional path to specify if multiple git repositories with the same name exist in the project. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
git_repo.GitRepo | None | The git repository or |
| RAISES | DESCRIPTION |
|---|---|
hopsworks.client.exceptions.RestAPIError | If the backend encounters an error when handling the request. |
get_repos #
GitRepo #
read_only property #
read_only
If True then the repository functions GitRepo.commit, GitRepo.push and GitRepo.checkout_files are forbidden.
add_remote #
Add a remote for the repo.
import hopsworks
project = hopsworks.login()
git_api = project.get_git_api()
repo = git_api.get_repo("my_repo")
repo.add_remote("upstream", "https://github.com/organization/repo.git")
| PARAMETER | DESCRIPTION |
|---|---|
name | Name of the remote. TYPE: |
url | Url of the remote. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
GitRemote | The created remote. |
| RAISES | DESCRIPTION |
|---|---|
hopsworks.client.exceptions.RestAPIError | If the backend encounters an error when handling the request. |
checkout_branch #
checkout_commit #
checkout_commit(commit: str)
Checkout a commit.
| PARAMETER | DESCRIPTION |
|---|---|
commit | Hash of the commit. TYPE: |
| RAISES | DESCRIPTION |
|---|---|
hopsworks.client.exceptions.RestAPIError | If the backend encounters an error when handling the request. |
checkout_files #
commit #
Add changes and new files, and then commit them.
| PARAMETER | DESCRIPTION |
|---|---|
message | Commit message. TYPE: |
all | Automatically stage files that have been modified and deleted, but new files are not affected. TYPE: |
files | List of new files to add and commit. |
| RAISES | DESCRIPTION |
|---|---|
hopsworks.client.exceptions.RestAPIError | If the backend encounters an error when handling the request. |
delete #
delete()
Delete the git repo from the filesystem.
Potentially dangerous operation
This operation deletes the cloned git repository from the filesystem.
| RAISES | DESCRIPTION |
|---|---|
hopsworks.client.exceptions.RestAPIError | If the backend encounters an error when handling the request |
delete_branch #
delete_branch(branch: str)
Delete a branch from local repository.
| PARAMETER | DESCRIPTION |
|---|---|
branch | Name of the branch to delete. TYPE: |
| RAISES | DESCRIPTION |
|---|---|
hopsworks.client.exceptions.RestAPIError | If the backend encounters an error when handling the request. |
fetch #
get_commits #
Get the commits for the repo and branch.
| PARAMETER | DESCRIPTION |
|---|---|
branch | Name of the branch. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[git_commit.GitCommit] | The list of commits for this repo. |
| RAISES | DESCRIPTION |
|---|---|
hopsworks.client.exceptions.RestAPIError | If the backend encounters an error when handling the request. |
get_remote #
Get a remote by name for the repo.
| PARAMETER | DESCRIPTION |
|---|---|
name | Name of the remote. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
GitRemote | The git remote metadata object or |
| RAISES | DESCRIPTION |
|---|---|
hopsworks.client.exceptions.RestAPIError | If the backend encounters an error when handling the request. |
get_remotes #
pull #
push #
reset #
Reset the branch to a specific commit or to a local branch or to a remote branch.
| PARAMETER | DESCRIPTION |
|---|---|
remote | Name of the remote. TYPE: |
branch | Name of the branch. TYPE: |
commit | Hash of the commit. TYPE: |
| RAISES | DESCRIPTION |
|---|---|
hopsworks.client.exceptions.RestAPIError | If the backend encounters an error when handling the request. |
status #
status()
Get the status of the repo.
| RETURNS | DESCRIPTION |
|---|---|
|
|
| RAISES | DESCRIPTION |
|---|---|
hopsworks.client.exceptions.RestAPIError | If the backend encounters an error when handling the request. |