Python git.exc() Examples
The following are 3
code examples of git.exc().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
git
, or try the search function
.
Example #1
Source File: utils.py From mlflow with Apache License 2.0 | 6 votes |
def _fetch_git_repo(uri, version, dst_dir): """ Clone the git repo at ``uri`` into ``dst_dir``, checking out commit ``version`` (or defaulting to the head commit of the repository's master branch if version is unspecified). Assumes authentication parameters are specified by the environment, e.g. by a Git credential helper. """ # We defer importing git until the last moment, because the import requires that the git # executable is availble on the PATH, so we only want to fail if we actually need it. import git repo = git.Repo.init(dst_dir) origin = repo.create_remote("origin", uri) origin.fetch() if version is not None: try: repo.git.checkout(version) except git.exc.GitCommandError as e: raise ExecutionException("Unable to checkout version '%s' of git repo %s" "- please ensure that the version exists in the repo. " "Error: %s" % (version, uri, e)) else: repo.create_head("master", origin.refs.master) repo.heads.master.checkout() repo.submodule_update(init=True, recursive=True)
Example #2
Source File: utils.py From mlflow with Apache License 2.0 | 5 votes |
def _get_git_repo_url(work_dir): from git import Repo from git.exc import GitCommandError, InvalidGitRepositoryError try: repo = Repo(work_dir, search_parent_directories=True) remote_urls = [remote.url for remote in repo.remotes] if len(remote_urls) == 0: return None except GitCommandError: return None except InvalidGitRepositoryError: return None return remote_urls[0]
Example #3
Source File: utils.py From mlflow with Apache License 2.0 | 5 votes |
def _is_valid_branch_name(work_dir, version): """ Returns True if the ``version`` is the name of a branch in a Git project. ``work_dir`` must be the working directory in a git repo. """ if version is not None: from git import Repo from git.exc import GitCommandError repo = Repo(work_dir, search_parent_directories=True) try: return repo.git.rev_parse("--verify", "refs/heads/%s" % version) != '' except GitCommandError: return False return False