本文整理汇总了Python中git.Git.log方法的典型用法代码示例。如果您正苦于以下问题:Python Git.log方法的具体用法?Python Git.log怎么用?Python Git.log使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类git.Git
的用法示例。
在下文中一共展示了Git.log方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _GitWrapperCommon
# 需要导入模块: from git import Git [as 别名]
# 或者: from git.Git import log [as 别名]
class _GitWrapperCommon(object):
'''
Wrap git module to provide a more stable interface across versions
'''
def __init__(self, repo_path):
self.git = Git()
self.repo = Repo(os.path.abspath('.'))
def is_file_managed_by_git(self, path):
'''
:param path: Path to check
:returns: True if path is managed by git
'''
status, _stdout, _stderr = self.git.execute(
['git', 'ls-files', path, '--error-unmatch'],
with_extended_output=True,
with_exceptions=False)
return status == 0
def is_file_modified(self, path):
'''
Does a file have local changes not yet committed
:returns: True if file has local changes
'''
status, _stdout, _stderr = self.git.execute(
['git', 'diff', '--quiet', 'HEAD', path],
with_extended_output=True,
with_exceptions=False)
return status != 0
def get_commits_following(self, path):
'''
Get all commits including path following the file through
renames
:param path: Path which we will find commits for
:returns: Sequence of commit objects. Newest to oldest
'''
commit_shas = self.git.log(
'--pretty=%H', '--follow', '--', path).splitlines()
return map(self.repo.commit, commit_shas)
def get_commits(self, path, follow=False):
'''
Get all commits including path
:param path: Path which we will find commits for
:param bool follow: If True we will follow path through renames
:returns: Sequence of commit objects. Newest to oldest
'''
if follow:
return self.get_commits_following(path)
else:
return self._get_commits(path)
示例2: _GitWrapperCommon
# 需要导入模块: from git import Git [as 别名]
# 或者: from git.Git import log [as 别名]
class _GitWrapperCommon(object):
"""
Wrap git module to provide a more stable interface across versions
"""
def __init__(self, repo_path):
self.git = Git()
self.repo = Repo(os.path.abspath("."))
def is_file_managed_by_git(self, path):
"""
:param path: Path to check
:returns: True if path is managed by git
"""
status, _stdout, _stderr = self.git.execute(
["git", "ls-files", path, "--error-unmatch"], with_extended_output=True, with_exceptions=False
)
return status == 0
def is_file_modified(self, path):
"""
Does a file have local changes not yet committed
:returns: True if file has local changes
"""
status, _stdout, _stderr = self.git.execute(
["git", "diff", "--quiet", "HEAD", path], with_extended_output=True, with_exceptions=False
)
return status != 0
def get_commits_following(self, path):
"""
Get all commits including path following the file through
renames
:param path: Path which we will find commits for
:returns: Sequence of commit objects. Newest to oldest
"""
commit_shas = self.git.log("--pretty=%H", "--follow", "--", path).splitlines()
return [self.repo.commit(shas) for shas in commit_shas]
def get_commits(self, path, follow=False):
"""
Get all commits including path
:param path: Path which we will find commits for
:param bool follow: If True we will follow path through renames
:returns: Sequence of commit objects. Newest to oldest
"""
if follow:
return self.get_commits_following(path)
else:
return self._get_commits(path)
示例3: _GitWrapperCommon
# 需要导入模块: from git import Git [as 别名]
# 或者: from git.Git import log [as 别名]
class _GitWrapperCommon(object):
'''
Wrap git module to provide a more stable interface across versions
'''
def __init__(self, repo_path):
self.git = Git()
self.git.update_environment(
GIT_CONFIG_NOSYSTEM='true',
HOME=os.getcwd(),
XDG_CONFIG_HOME=os.getcwd()
)
self.repo = Repo(os.path.abspath('.'))
def is_file_managed_by_git(self, path):
'''
:param path: Path to check
:returns: True if path is managed by git
'''
status, _stdout, _stderr = self.git.execute(
['git', 'ls-files', path, '--error-unmatch'],
with_extended_output=True,
with_exceptions=False)
return status == 0
def is_file_modified(self, path):
'''
Does a file have local changes not yet committed
:returns: True if file has local changes
'''
status, _stdout, _stderr = self.git.execute(
['git', 'diff', '--quiet', 'HEAD', path],
with_extended_output=True,
with_exceptions=False)
return status != 0
def get_commits_following(self, path):
'''
Get all commits including path following the file through
renames
:param path: Path which we will find commits for
:returns: Sequence of commit objects. Newest to oldest
'''
return [
commit for commit, _ in self.get_commits_and_names_iter(
path)]
def get_commits_and_names_iter(self, path):
'''
Get all commits including a given path following renames
'''
log_result = self.git.log(
'--pretty=%H',
'--follow',
'--name-only',
'--',
path).splitlines()
for commit_sha, _, filename in grouper(log_result, 3):
yield self.repo.commit(commit_sha), filename
def get_commits(self, path, follow=False):
'''
Get all commits including path
:param path: Path which we will find commits for
:param bool follow: If True we will follow path through renames
:returns: Sequence of commit objects. Newest to oldest
'''
if follow:
return self.get_commits_following(path)
else:
return self._get_commits(path)