Renamed git property to repo object in dvc/scm/git

This commit is contained in:
RahulR19
2019-07-31 21:56:53 +05:30
parent c5c248c098
commit 79557ffb3c
+22 -22
View File
@@ -42,7 +42,7 @@ class Git(Base):
from git.exc import InvalidGitRepositoryError
try:
self.git = git.Repo(self.root_dir)
self.repo = git.Repo(self.root_dir)
except InvalidGitRepositoryError:
msg = "{} is not a git repository"
raise SCMError(msg.format(self.root_dir))
@@ -51,7 +51,7 @@ class Git(Base):
# http://pyinstaller.readthedocs.io/en/stable/runtime-information.html
env = fix_env(None)
libpath = env.get("LD_LIBRARY_PATH", None)
self.git.git.update_environment(LD_LIBRARY_PATH=libpath)
self.repo.git.update_environment(LD_LIBRARY_PATH=libpath)
self.ignored_paths = []
self.files_to_track = set()
@@ -70,7 +70,7 @@ class Git(Base):
@property
def dir(self):
return self.git.git_dir
return self.repo.git_dir
@property
def ignore_file(self):
@@ -167,7 +167,7 @@ class Git(Base):
# NOTE: GitPython is not currently able to handle index version >= 3.
# See https://github.com/iterative/dvc/issues/610 for more details.
try:
self.git.index.add(paths)
self.repo.index.add(paths)
except AssertionError:
msg = (
"failed to add '{}' to git. You can add those files"
@@ -179,41 +179,41 @@ class Git(Base):
logger.exception(msg)
def commit(self, msg):
self.git.index.commit(msg)
self.repo.index.commit(msg)
def checkout(self, branch, create_new=False):
if create_new:
self.git.git.checkout("HEAD", b=branch)
self.repo.git.checkout("HEAD", b=branch)
else:
self.git.git.checkout(branch)
self.repo.git.checkout(branch)
def branch(self, branch):
self.git.git.branch(branch)
self.repo.git.branch(branch)
def tag(self, tag):
self.git.git.tag(tag)
self.repo.git.tag(tag)
def untracked_files(self):
files = self.git.untracked_files
return [os.path.join(self.git.working_dir, fname) for fname in files]
files = self.repo.untracked_files
return [os.path.join(self.repo.working_dir, fname) for fname in files]
def is_tracked(self, path):
# it is equivalent to `bool(self.git.git.ls_files(path))` by
# it is equivalent to `bool(self.repo.git.ls_files(path))` by
# functionality, but ls_files fails on unicode filenames
path = relpath(path, self.root_dir)
return path in [i[0] for i in self.git.index.entries]
return path in [i[0] for i in self.repo.index.entries]
def is_dirty(self):
return self.git.is_dirty()
return self.repo.is_dirty()
def active_branch(self):
return self.git.active_branch.name
return self.repo.active_branch.name
def list_branches(self):
return [h.name for h in self.git.heads]
return [h.name for h in self.repo.heads]
def list_tags(self):
return [t.name for t in self.git.tags]
return [t.name for t in self.repo.tags]
def _install_hook(self, name, cmd):
command = '[ -z "$(git ls-files .dvc)" ] || exec dvc {}'.format(cmd)
@@ -266,7 +266,7 @@ class Git(Base):
return basename == self.ignore_file or Git.GIT_DIR in path_parts
def get_tree(self, rev):
return GitTree(self.git, rev)
return GitTree(self.repo, rev)
def _get_diff_trees(self, a_ref, b_ref):
"""Private method for getting the trees and commit hashes of 2 git
@@ -284,10 +284,10 @@ class Git(Base):
trees = {DIFF_A_TREE: None, DIFF_B_TREE: None}
commits = []
if b_ref is None:
b_ref = self.git.head.commit
b_ref = self.repo.head.commit
try:
a_commit = self.git.git.rev_parse(a_ref, short=True)
b_commit = self.git.git.rev_parse(b_ref, short=True)
a_commit = self.repo.git.rev_parse(a_ref, short=True)
b_commit = self.repo.git.rev_parse(b_ref, short=True)
# See https://gitpython.readthedocs.io
# /en/2.1.11/reference.html#git.objects.base.Object.__str__
commits.append(a_commit)
@@ -322,4 +322,4 @@ class Git(Base):
return diff_dct
def get_rev(self):
return self.git.git.rev_parse("HEAD")
return self.repo.git.rev_parse("HEAD")