GitRepo API#
Handle#
get_git_api#
Project.get_git_api()
Get the git repository api for the project.
Returns
GitApi
: The Git Api handle
Creation#
clone#
GitApi.clone(url, path, provider=None, branch=None)
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")
- url
str
: Url to the git repository - path
str
: Path in Hopsworks Filesystem to clone the repo to - provider
str
: The git provider where the repo is currently hosted. Valid values are "GitHub", "GitLab" and "BitBucket". - branch
str
: Optional branch to clone, defaults to configured main branch
Returns
GitRepo
: Git repository object
Raises
RestAPIError
: If unable to clone the git repository.
Retrieval#
get_repo#
GitApi.get_repo(name, path=None)
Get the cloned Git repository
Arguments
- name
str
: Name of git repository - path
str
: Optional path to specify if multiple git repos with the same name exists in the project
Returns
GitRepo
: The git repository
Raises
RestAPIError
: If unable to get the git repository
get_repos#
GitApi.get_repos()
Get the existing Git repositories
Returns
List[GitRepo]
: List of git repository objects
Raises
RestAPIError
: If unable to get the repositories
Properties#
creator#
Creator of the git repo
current_branch#
The current branch for the git repo
current_commit#
The current commit for the git repo
id#
Id of the git repo
name#
Name of the git repo
path#
Path to the git repo in the Hopsworks Filesystem
provider#
Git provider for the repo, can be GitHub, GitLab or BitBucket
read_only#
If True then the repository functions GitRepo.commit
, GitRepo.push
and GitRepo.checkout_files
are forbidden.
Methods#
add_remote#
GitRepo.add_remote(name, url)
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")
- name
str
: name of the remote - url
str
: url of the remote
Returns
GitRemote
Raises
RestAPIError
in case the backend fails to add the remote.
checkout_branch#
GitRepo.checkout_branch(branch, create=False)
Checkout a branch
Arguments
- branch
str
: name of the branch - create
bool
: if true will create a new branch and check it out
Raises
RestAPIError
in case the backend fails to retrieve the commits.
checkout_commit#
GitRepo.checkout_commit(commit)
Checkout a commit
Arguments
- commit
str
: hash of the commit
Raises
RestAPIError
in case the backend fails to retrieve the commits.
checkout_files#
GitRepo.checkout_files(files)
Checkout a list of files
Arguments
- files
List[str] | List[hopsworks_common.git_file_status.GitFileStatus]
: list of files or GitFileStatus objects to checkout
Raises
RestAPIError
in case the backend fails to checkout the files.
commit#
GitRepo.commit(message, all=True, files=None)
Add changes and new files, and then commit them
Arguments
- message
str
: name of the remote - all
bool
: automatically stage files that have been modified and deleted, but new files are not affected - files
List[str]
: list of new files to add and commit
Raises
RestAPIError
in case the backend fails to perform the commit.
delete#
GitRepo.delete()
Delete the git repo from the filesystem.
Potentially dangerous operation
This operation deletes the cloned git repository from the filesystem.
Raises
RestAPIError
.
delete_branch#
GitRepo.delete_branch(branch)
Delete a branch from local repository
Arguments
- branch
str
: name of the branch
Raises
RestAPIError
in case the backend fails to delete the branch.
get_commits#
GitRepo.get_commits(branch)
Get the commits for the repo and branch.
Arguments
- branch
str
: name of the branch
Returns
List[GitCommit]
Raises
RestAPIError
in case the backend fails to retrieve the commits.
get_remote#
GitRepo.get_remote(name)
Get a remote by name for the repo.
Arguments
- name
str
: name of the remote
Returns
GitRemote
Raises
RestAPIError
in case the backend fails to get the remote.
get_remotes#
GitRepo.get_remotes()
Get the configured remotes for the repo.
Returns
List[GitRemote]
Raises
RestAPIError
in case the backend fails to retrieve the remotes.
pull#
GitRepo.pull(branch, remote="origin")
Pull changes from remote branch
Arguments
- branch
str
: name of the branch - remote
str
: name of the remote
Raises
RestAPIError
in case the backend fails to retrieve the commits.
push#
GitRepo.push(branch, remote="origin")
Push changes to the remote branch
Arguments
- branch
str
: name of the branch - remote
str
: name of the remote
Raises
RestAPIError
in case the backend fails to retrieve the commits.
status#
GitRepo.status()
Get the status of the repo.
Returns
List[GitFileStatus]
Raises
RestAPIError
in case the backend fails to retrieve the status.