Python git.NoSuchPathError() Examples
The following are 6
code examples of git.NoSuchPathError().
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: git_context.py From mlflow with Apache License 2.0 | 6 votes |
def _get_git_commit(path): try: import git except ImportError as e: _logger.warning( "Failed to import Git (the Git executable is probably not on your PATH)," " so Git SHA is not available. Error: %s", e) return None try: if os.path.isfile(path): path = os.path.dirname(path) repo = git.Repo(path, search_parent_directories=True) commit = repo.head.commit.hexsha return commit except (git.InvalidGitRepositoryError, git.GitCommandNotFound, ValueError, git.NoSuchPathError): return None
Example #2
Source File: setup.py From airflow with Apache License 2.0 | 5 votes |
def git_version(version_: str) -> str: """ Return a version to identify the state of the underlying git repo. The version will indicate whether the head of the current git-backed working directory is tied to a release tag or not : it will indicate the former with a 'release:{version}' prefix and the latter with a 'dev0' prefix. Following the prefix will be a sha of the current branch head. Finally, a "dirty" suffix is appended to indicate that uncommitted changes are present. :param str version_: Semver version :return: Found Airflow version in Git repo :rtype: str """ try: import git try: repo = git.Repo(os.path.join(*[my_dir, '.git'])) except git.NoSuchPathError: logger.warning('.git directory not found: Cannot compute the git version') return '' except git.InvalidGitRepositoryError: logger.warning('Invalid .git directory not found: Cannot compute the git version') return '' except ImportError: logger.warning('gitpython not found: Cannot compute the git version.') return '' if repo: sha = repo.head.commit.hexsha if repo.is_dirty(): return '.dev0+{sha}.dirty'.format(sha=sha) # commit is clean return '.release:{version}+{sha}'.format(version=version_, sha=sha) else: return 'no_git_version'
Example #3
Source File: git_utils.py From ops-cli with Apache License 2.0 | 5 votes |
def setup_repo(repo_path, upstream_repo): """ Ensure that the repo is present or clone it from upstream otherwise. """ repo_path = os.path.expanduser(repo_path) try: git.Repo(repo_path, search_parent_directories=True) except git.NoSuchPathError: logger.warning( "Repo '%s' not found. Cloning from upstream '%s'", repo_path, upstream_repo ) git.Repo.clone_from(upstream_repo, repo_path)
Example #4
Source File: utils.py From mlflow with Apache License 2.0 | 5 votes |
def _get_git_url_if_present(uri): """ Return the path git_uri#sub_directory if the URI passed is a local path that's part of a Git repo, or returns the original URI otherwise. :param uri: The expanded uri :return: The git_uri#sub_directory if the uri is part of a Git repo, otherwise return the original uri """ if '#' in uri: # Already a URI in git repo format return uri try: from git import Repo, InvalidGitRepositoryError, GitCommandNotFound, NoSuchPathError except ImportError as e: print("Notice: failed to import Git (the git executable is probably not on your PATH)," " so Git SHA is not available. Error: %s" % e, file=sys.stderr) return uri try: # Check whether this is part of a git repo repo = Repo(uri, search_parent_directories=True) # Repo url repo_url = "file://%s" % repo.working_tree_dir # Sub directory rlpath = uri.replace(repo.working_tree_dir, '') if (rlpath == ''): git_path = repo_url elif (rlpath[0] == '/'): git_path = repo_url + '#' + rlpath[1:] else: git_path = repo_url + '#' + rlpath return git_path except (InvalidGitRepositoryError, GitCommandNotFound, ValueError, NoSuchPathError): return uri
Example #5
Source File: vcs.py From polemarch with GNU Affero General Public License v3.0 | 5 votes |
def _get_or_create_repo(self, env: ENV_VARS_TYPE) -> git.Repo: try: repo = self.get_repo() branch = self.target_branch with raise_context(): repo.git.checkout(branch) is_not_detached = not repo.head.is_detached if branch and is_not_detached and repo.active_branch.name != branch: self.delete() raise git.NoSuchPathError except git.NoSuchPathError: repo = self.make_clone(env)[0] return repo
Example #6
Source File: models.py From crane with MIT License | 5 votes |
def check_preconditions(self): from . import settings # avoiding circular imports try: self.repo = git.Repo(environ["CI_PROJECT_DIR"]) except git.NoSuchPathError: click.secho( f"You are not running crane in a Git repository. " "crane is running in limited mode, all hooks have been disabled. " "It is highly recommended you use Git references for your deployments.", err=True, fg="red", ) self.is_limited = True return try: self.new_commit except (gitdb.exc.BadName, ValueError): click.secho( f"The new version you specified, {self.new_version}, is not a valid git reference! " "crane is running in limited mode, all hooks have been disabled. " "It is highly recommended you use Git references for your deployments.", err=True, fg="red", ) self.is_limited = True return for service in self.services: if ( self.old_version not in service.json()["launchConfig"]["imageUuid"] and not settings["new_image"] ): click.secho( "All selected services must have the same commit SHA. " "Please manually change their versions so they are all the same, and then retry the upgrade.", err=True, fg="red", ) raise UpgradeFailed()