Skip to content

GitRepo API#

Handle#

[source]

get_git_api#

Project.get_git_api()

Get the git repository api for the project.

Returns

GitApi: The Git Api handle


Creation#

[source]

clone#

GitApi.clone(url, path, provider=None, branch=None)

Clone a new Git Repo in to Hopsworks Filesystem.

import hopsworks

connection = hopsworks.connection()

project = connection.get_project()

git_api = project.get_git_api()

git_repo = git_api.clone("https://github.com/logicalclocks/hops-examples.git", "Resources", "GitHub")
Arguments

  • url str: Url to the git repository
  • path str: Path in Hopsworks Filesystem to clone the repo to
  • provider Optional[str]: The git provider where the repo is currently hosted. Valid values are "GitHub", "GitLab" and "BitBucket".
  • branch Optional[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#

[source]

get_repo#

GitApi.get_repo(name, path=None)

Get the cloned Git repository

Arguments

  • name str: Name of git repository
  • path Optional[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

[source]

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#

[source]

creator#

Creator of the git repo


[source]

current_branch#

The current branch for the git repo


[source]

current_commit#

The current commit for the git repo


[source]

id#

Id of the git repo


[source]

name#

Name of the git repo


[source]

path#

Path to the git repo in the Hopsworks Filesystem


[source]

provider#

Git provider for the repo, can be GitHub, GitLab or BitBucket


Methods#

[source]

add_remote#

GitRepo.add_remote(name, url)

Add a remote for the repo

import hopsworks

connection = hopsworks.connection()

project = connection.get_project()

git_api = project.get_git_api()

repo = git_api.get_repo("my_repo")

repo.add_remote("upstream", "https://github.com/organization/repo.git")
Arguments

  • 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.


[source]

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.


[source]

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.


[source]

checkout_files#

GitRepo.checkout_files(files)

Checkout a list of files

Arguments

  • files Union[List[str], List[hopsworks.git_file_status.GitFileStatus]]: list of files or GitFileStatus objects to checkout

Raises

RestAPIError in case the backend fails to checkout the files.


[source]

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 Optional[List[str]]: list of new files to add and commit

Raises

RestAPIError in case the backend fails to perform the commit.


[source]

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.


[source]

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.


[source]

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.


[source]

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.


[source]

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.


[source]

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.


[source]

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.


[source]

status#

GitRepo.status()

Get the status of the repo.

Returns

List[GitFileStatus]

Raises

RestAPIError in case the backend fails to retrieve the status.