Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def repo_path():
"""
Get the path to the git_dir of the mainline linux git repository to use.
Typically obtained from the LINUX_GIT environment variable.
"""
try:
search_path = subprocess.check_output(
os.path.join(libdir(), "..",
"linux_git.sh")).decode().strip()
except subprocess.CalledProcessError:
print("Error: Could not determine mainline linux git repository path.",
file=sys.stderr)
sys.exit(1)
return pygit2.discover_repository(search_path)
def init_repository(url=None, only=None, exclude=None):
"""Creates a new Gitless's repository in the cwd.
Args:
url: if given the local repository will be a clone of the remote repository
given by this url.
only: if given, this local repository will consist only of the branches
in this set
exclude: if given, and only is not given, this local repository will
consistent of all branches not in this set
"""
cwd = os.getcwd()
try:
error_on_none(pygit2.discover_repository(cwd))
raise GlError('You are already in a Gitless repository')
except KeyError: # Expected
if not url:
repo = pygit2.init_repository(cwd)
# We also create an initial root commit
git.commit(allow_empty=True, m='Initialize repository')
return repo
try:
git.clone(url, cwd)
except ErrorReturnCode as e:
raise GlError(stderr(e))
# We get all remote branches as well and create local equivalents
# Flags: only branches take precedence over exclude branches.
repo = Repository()
def __init__(self):
self.gitdir = pygit2.discover_repository('.')
self.objmap = os.path.join(self.gitdir, 'objmap')
self.repo = Repository(self.gitdir)
def _path_to_repo(directory: str) -> pygit2.Repository:
repository_path = pygit2.discover_repository(directory, False, UpdateManager.get_git_ceiling_dirs(directory))
return pygit2.Repository(repository_path)
def get_repo(dir):
path = git.discover_repository(dir)
if not path:
return None
return git.Repository(path)
def __init__(self, options, repo_path=None, logger=None):
self.options = options
if logger is None:
self.logger = self.default_logger()
if repo_path is None:
try:
repo_path = pygit2.discover_repository('.')
except KeyError:
abort("Couldn't find a repository in the current directory.")
self.repo = pygit2.Repository(repo_path)
# Nested dict mapping dependents -> dependencies -> files
# causing that dependency -> numbers of lines within that file
# causing that dependency. The first two levels form edges in
# the dependency graph, and the latter two tell us what caused
# those edges.
self.dependencies = {}
# A TODO list (queue) and dict of dependencies which haven't
# yet been recursively followed. Only useful when recursing.
self.todo = []
self.todo_d = {}
def __init__(self):
"""Create a Repository out of the current working repository.
Raises:
NotInRepoError: if there's no current working repository.
"""
try:
path = pygit2.discover_repository(os.getcwd())
except KeyError:
raise NotInRepoError('You are not in a Gitless\'s repository')
self.git_repo = pygit2.Repository(path)
self.remotes = RemoteCollection(self.git_repo.remotes, self)
self.path = self.git_repo.path
self.root = self.path[:-6] # strip trailing /.git/
self.config = self.git_repo.config