本文整理汇总了Python中git.Repo.rev_parse方法的典型用法代码示例。如果您正苦于以下问题:Python Repo.rev_parse方法的具体用法?Python Repo.rev_parse怎么用?Python Repo.rev_parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类git.Repo
的用法示例。
在下文中一共展示了Repo.rev_parse方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: git_iterator
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import rev_parse [as 别名]
def git_iterator(args, options):
if not HAS_GIT:
raise ValueError('Git has not been enabled for this checkstyle library!')
repo = Repo()
diff_commit = repo.rev_parse(options.diff or repo.git.merge_base('master', 'HEAD'))
for filename, line_filter in filter(None, map(tuple_from_diff, diff_commit.diff(None))):
yield os.path.join(repo.working_tree_dir, filename), line_filter
示例2: git_iterator
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import rev_parse [as 别名]
def git_iterator(args, options):
if not HAS_GIT:
raise ValueError('Git has not been enabled for this checkstyle library!')
repo = Repo()
diff_commit = repo.rev_parse(options.diff or 'master')
for filename, line_filter in filter(None, map(tuple_from_diff, diff_commit.diff(None))):
yield filename, line_filter
示例3: print_about_page
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import rev_parse [as 别名]
def print_about_page(ydk_root, py_api_doc_gen):
repo = Repo(ydk_root)
remote = repo.remote().name
branch = repo.active_branch.name
url = repo.remote().url.split('://')[-1].split('.git')[0]
commit_id = repo.rev_parse(remote + '/' + branch).hexsha
# modify about_ydk.rst page
for line in fileinput.input(os.path.join(py_api_doc_gen, 'about_ydk.rst'), 'r+w'):
if 'git clone repo-url' in line:
print line.replace('repo-url', 'https://{0}.git'.format(url)),
elif 'git checkout commit-id' in line:
print line.replace('commit-id', '{}'.format(commit_id))
else:
print line,
示例4: print_about_ydk_page
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import rev_parse [as 别名]
def print_about_ydk_page(ydk_root, py_api_doc_gen):
repo = Repo(ydk_root)
remote = repo.remote().name
branch = repo.active_branch.name
url = repo.remote().url.split('://')[-1].split('.git')[0]
commit_id = repo.rev_parse(remote + '/' + branch).hexsha
contents = ''
with open(os.path.join(py_api_doc_gen, 'about_ydk.rst'), 'r+w') as about_file:
contents = about_file.read()
contents = contents.replace('git clone repo-url', 'git clone https://{0}.git'.format(url))
contents = contents.replace('git checkout commit-id', 'git checkout {0}'.format(commit_id))
with open(os.path.join(py_api_doc_gen, 'about_ydk.rst'), 'w') as about_file:
about_file.write(contents)
示例5: generate_documentation
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import rev_parse [as 别名]
def generate_documentation(output_directory, ydk_root):
py_api_doc_gen = output_directory + '/python/docsgen'
py_api_doc = output_directory + '/python/docs_expanded'
execfile(os.path.join(output_directory, 'python', 'ydk', '_version.py'))
os.mkdir(py_api_doc)
# set documentation version and release from setup.py setting
version_number = locals()['__version__']
release = 'release={}'.format(version_number)
version = 'version={}'.format(version_number[:version_number.rfind(".")])
# print commit id page
repo = Repo(ydk_root)
remote = repo.remote().name
branch = repo.active_branch.name
url = repo.remote().url.split('://')[-1].split('.git')[0]
commit_id = repo.rev_parse(remote + '/' + branch).hexsha
with open(os.path.join(py_api_doc_gen, 'commit_id.rst'), 'w') as id_file:
id_file.write('Commit id\n'
'=========\n'
'\n'
'This ydk-py is generated from `this commit '
'<https://{}/commit/{}>`_.'.format(url, commit_id)
)
# build docs
# logger.debug('Building docs using sphinx-build...\n')
print('\nBuilding docs using sphinx-build...\n')
p = subprocess.Popen(['sphinx-build',
'-D', version,
'-D', release,
py_api_doc_gen, py_api_doc],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stdout, stderr = p.communicate()
logger.debug(stdout)
logger.error(stderr)
print >> sys.stderr, stderr
print(stdout)
print('*' * 28 + '\n' + 'DOCUMENTATION ERRORS/WARNINGS\n' +
'*' * 28 + '\n' + stderr)
示例6: render
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import rev_parse [as 别名]
def render(self, context):
try:
r = Repo(BASE_DIR)
version = r.rev_parse("HEAD").hexsha
context['git'] = {
"shortHexSha": version[0:7],
"hexSha": version,
"shortRemote": "https://github.com",
"remote": "https://github.com/rubienr/network-monitoring"
}
except Exception:
context['git'] = {
"shortHexSha": None,
"hexSha": None,
"shortRemote": None,
"remote": None,
}
return ""
示例7: find_submit_commit
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import rev_parse [as 别名]
def find_submit_commit(args, repo):
deadline = datetime.datetime.strptime(args.timestamp, "%Y-%m-%dT%H:%M:%S")
tz = timezone('US/Eastern')
deadline = tz.localize(deadline)
print "DEADLINE: {}".format(deadline)
commit = Repo.rev_parse(repo, "HEAD")
commit_time = datetime.datetime.fromtimestamp(commit.committed_date)
commit_time = tz.localize(commit_time)
while commit_time > deadline:
parents = commit.parents
if len(parents) == 0:
# No more valid commits. No submission :(
print "No valid commit found"
return None
commit = parents[0]
commit_time = datetime.datetime.fromtimestamp(commit.committed_date)
commit_time = tz.localize(commit_time)
print "SUBMITTED: {}".format(commit_time)
sha = commit.name_rev.split()[0]
print "SUBMIT COMMIT: {}".format(sha)
return sha
示例8: GitFlow
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import rev_parse [as 别名]
#.........这里部分代码省略.........
"""
return len(self.repo.index.diff(self.repo.head.commit)) > 0
@requires_repo
def require_no_merge_conflict(self):
"""
Raises :exc:`MergeConflict` if the current working directory
contains a merge conflict.
"""
try:
git.Reference(self.repo, 'MERGE_HEAD', check_path=False).commit
# reference exists, so there is a merge conflict
raise MergeConflict()
except ValueError:
# no such reference, so there is no merge conflict
pass
def is_merged_into(self, commit, target_branch):
"""
Checks whether `commit` is successfully merged into branch
`target_branch`.
:param commit:
The commit or branch that ought to be merged. This may be
a full branch-name, a commit-hexsha or any of branch-,
head-, reference- or commit-object.
:param target_branch:
The branch which should contain the commit. This may be a
full branch-name, or any of branch-, head- or
reference-object.
"""
try:
commit = self.repo.rev_parse(str(commit))
except (git.BadObject, git.BadName):
raise BadObjectError(commit)
if isinstance(target_branch, git.RemoteReference):
target_branch = 'remotes/' + target_branch.name
elif isinstance(target_branch, git.SymbolicReference):
target_branch = target_branch.name
# :todo: implement this more efficiently
return target_branch in [
b.lstrip('* ')
for b in self.git.branch('-a', '--contains', commit).splitlines()]
def must_be_uptodate(self, branch, fetch):
remote_branch = self.origin_name(branch)
if remote_branch in self.branch_names(remote=True):
if fetch:
self.origin().fetch(branch)
self.require_branches_equal(branch, remote_branch)
@requires_repo
def _compare_branches(self, branch1, branch2):
"""
Tests whether branches and their 'origin' counterparts have
diverged and need merging first. It returns error codes to
provide more detail, like so:
0 Branch heads point to the same commit
1 First given branch needs fast-forwarding
2 Second given branch needs fast-forwarding
3 Branch needs a real merge
4 There is no merge base, i.e. the branches have no common ancestors
"""
try:
示例9: GitFlow
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import rev_parse [as 别名]
#.........这里部分代码省略.........
active_branch = self.repo.active_branch
b = self.repo.heads[name]
return (name, b.commit.hexsha, b == active_branch)
@requires_repo
def is_dirty(self):
"""
Returns whether or not the current working directory contains
uncommitted changes.
"""
return self.repo.is_dirty()
@requires_repo
def has_staged_commits(self):
"""
Returns whether or not the current repo contains local changes
checked into the index but not committed.
"""
return len(self.repo.index.diff(self.repo.head.commit)) > 0
@requires_repo
def require_no_merge_conflict(self):
"""
Raises :exc:`MergeConflict` if the current working directory
contains a merge conflict.
"""
try:
git.Reference(self.repo, 'MERGE_HEAD', check_path=False).commit
# reference exists, so there is a merge conflict
raise MergeConflict()
except ValueError:
# no such reference, so there is no merge conflict
pass
def is_merged_into(self, commit, target_branch):
"""
Checks whether `commit` is successfully merged into branch
`target_branch`.
:param commit:
The commit or branch that ought to be merged. This may be
a full branch-name, a commit-hexsha or any of branch-,
head-, reference- or commit-object.
:param target_branch:
The branch which should contain the commit. This may be a
full branch-name, or any of branch-, head- or
reference-object.
"""
try:
commit = self.repo.rev_parse(str(commit))
except git.BadObject:
raise BadObjectError(commit)
if isinstance(target_branch, git.RemoteReference):
target_branch = 'remotes/' + target_branch.name
elif isinstance(target_branch, git.SymbolicReference):
target_branch = target_branch.name
# :todo: implement this more efficiently
return target_branch in [
b.lstrip('* ')
for b in self.git.branch('-a', '--contains', commit).splitlines()]
def must_be_uptodate(self, branch):
remote_branch = self.origin_name(branch)
if remote_branch in self.branch_names(remote=True):
self.require_branches_equal(branch, remote_branch)
@requires_repo
def _compare_branches(self, branch1, branch2):
"""
Tests whether branches and their 'origin' counterparts have
diverged and need merging first. It returns error codes to
provide more detail, like so:
0 Branch heads point to the same commit
1 First given branch needs fast-forwarding
2 Second given branch needs fast-forwarding
3 Branch needs a real merge
4 There is no merge base, i.e. the branches have no common ancestors
"""
try:
commit1 = self.repo.rev_parse(branch1)
commit2 = self.repo.rev_parse(branch2)
except git.BadObject, e:
raise NoSuchBranchError('Branch {0} not found'.format(e.args[0]))
if commit1 == commit2:
return 0
try:
base = self.repo.git.merge_base(commit1, commit2)
except GitCommandError:
return 4
if base == commit1:
return 1
elif base == commit2:
return 2
else:
return 3
示例10: open
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import rev_parse [as 别名]
origin = r.remotes.origin
cw = origin.config_writer
cw.set('sparseCheckout', 'true')
cw.release()
fname = 'gen/' + simple_name + '/.git/info/sparse-checkout'
if not os.path.exists(os.path.dirname(fname)):
os.makedirs(os.path.dirname(fname))
with open(fname, 'w') as sparse:
sparse.write(simple_name + '/' + preview_path)
origin.pull(depth=1)
date = datetime.datetime.fromtimestamp(int(r.rev_parse('head').committed_date))
age = (now - date).days
if age > active_age_max:
border = passive
else:
border = active
if os.path.isfile( 'gen/' + simple_name + '/' + preview_path):
f = Image.open('gen/' + simple_name + '/' + preview_path).resize((128, 128)).convert('RGBA')
Image.alpha_composite(f, border).save('gen/' + simple_name + '.png', "PNG")
files.append(('gen/' + simple_name + '.png', repo[1], age))
else:
print(" Don't have preview... skipping.")
print("Accessing imgur API.")
client = ImgurClient(config['imgur']['client-id'], config['imgur']['client-secret'])