本文整理汇总了Python中git.Repo.is_ancestor方法的典型用法代码示例。如果您正苦于以下问题:Python Repo.is_ancestor方法的具体用法?Python Repo.is_ancestor怎么用?Python Repo.is_ancestor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类git.Repo
的用法示例。
在下文中一共展示了Repo.is_ancestor方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Plugin
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import is_ancestor [as 别名]
class Plugin(dork_compose.plugin.Plugin):
def __init__(self, env, name):
dork_compose.plugin.Plugin.__init__(self, env, name)
self.__repo = Repo(self.basedir)
def __commit(self, hash):
try:
return self.__repo.commit(hash)
except BadName:
return None
def snapshot_autosave(self):
return self.__repo.head.commit.hexsha
def snapshot_autoload(self, snapshots=()):
name = None
head = self.__repo.head.commit
distance = -1
for commit in filter(lambda x: x, map(self.__commit, snapshots)):
if self.__repo.is_ancestor(commit.hexsha, head.hexsha):
diff = len(commit.diff(head))
if diff < distance or distance == -1:
name = commit.hexsha
distance = diff
return name
def snapshot_autoclean(self, snapshots=()):
snapshots = filter(lambda x: x, map(self.__commit, snapshots))
names = []
for current in snapshots:
for test in snapshots:
if self.__repo.is_ancestor(test, current) and test != current and test.hexsha not in names:
names.append(test.hexsha)
return names
示例2: checkVersionBranches
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import is_ancestor [as 别名]
def checkVersionBranches(version):
"""Check that the branches for a given version were created properly."""
parser = VersionParser(version)
repo = Repo(os.getcwd(), search_parent_directories=True)
assert not repo.bare
# Verify the branches' existance
if parser.remote_previous_rc_branch not in repo.refs:
raise ValueError("Previous RC branch not found: {}".format(parser.remote_previous_rc_branch))
if parser.remote_base_branch not in repo.refs:
raise ValueError("Base branch not found: {}".format(parser.remote_base_branch))
if parser.remote_rc_branch not in repo.refs:
raise ValueError("RC branch not found: {}".format(parser.remote_rc_branch))
previous_rc = repo.refs[parser.remote_previous_rc_branch]
current_rc_base = repo.refs[parser.remote_base_branch]
current_rc = repo.refs[parser.remote_rc_branch]
master = repo.refs[remote_master_branch]
# Check the base branch is an ancestor of the rc branch
if not repo.is_ancestor(current_rc_base, current_rc):
raise ValueError("{} is not an ancesctor of {}".format(current_rc_base, current_rc))
# Check that the base branch is the merge base of the previous and current RCs
merge_base = repo.merge_base(previous_rc, current_rc)
if current_rc_base.commit not in merge_base:
raise ValueError("Base branch is not the merge base between {} and {}".format(previous_rc, current_rc))
# For patch releases, warn if the base commit is not the previous RC commit
if parser.is_patch_release:
if parser.previous_version not in repo.tags:
logging.warning("The tag {0} does not exist, which suggests {0} has not been released.".format(parser.previous_version))
if current_rc_base.commit != previous_rc.commit:
logging.warning("Previous version has commits not in this patch");
logging.warning("Type \"git diff {}..{}\" to see the commit list".format(current_rc_base, previous_rc));
# Check base branch is part of the previous RC
previous_rc_base_commit = repo.merge_base(previous_rc, master)
if repo.is_ancestor(current_rc_base, previous_rc_base_commit):
raise ValueError("{} is older than {}".format(current_rc_base, previous_rc))
print("[SUCCESS] Checked {}".format(parser.version))
示例3: main
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import is_ancestor [as 别名]
def main():
user_config_file = path.join(path.expanduser('~'), '.fernglas.cfg')
project_config_file = path.join(getcwd(), '.fernglas.cfg')
config = SafeConfigParser()
config.read([user_config_file, project_config_file])
servers = {}
if not config.has_section('main'):
print("No main config found")
exit(1)
if not config.has_option('main', 'servers'):
print("No servers defined")
exit(2)
server_sections = config.get('main', 'servers').split(',')
server_sections = [section.strip() for section in server_sections]
for server in server_sections:
servers[server] = dict(config.items(server))
if 'port' in servers[server]:
servers[server]['port'] = int(servers[server]['port'])
issue = sys.argv[1]
package = run_setup(path.join(getcwd(), 'setup.py'))
package_name = package.get_name()
repo = Repo(getcwd())
latest_issue_commit = repo.git.log(all=True, grep=issue, n=1, format='%H')
if not latest_issue_commit:
print("No commits found for " + issue)
exit(3)
config = SSHConfig()
ssh_config_path = path.expanduser('~/.ssh/config')
if path.exists(ssh_config_path):
try:
config.parse(open(ssh_config_path))
except Exception as e:
print("Could not parse ssh config: " + str(e))
client = SSHClient()
client.load_system_host_keys()
# XXX support ecdsa?
client.set_missing_host_key_policy(AutoAddPolicy())
for key, server in servers.items():
host_config = config.lookup(server['hostname'])
connect_opts = {}
for key_ssh, key_paramiko in SSH_CONFIG_MAPPING.items():
if key_ssh in host_config:
connect_opts[key_paramiko] = host_config[key_ssh]
connect_opts.update(dict(
(opt, servers[key][opt]) for opt in SSH_OPTIONS
if opt in servers[key]))
client.connect(**connect_opts)
stdin, stdout, stderr = client.exec_command('grep {0} {1}'.format(
package_name, server['versions-path']))
deployed_version = stdout.read().strip().replace(package_name, '')\
.replace('=', '').strip()
version_tags = [tag for tag in repo.tags
if tag.name == deployed_version]
tag = version_tags[0]
version_commit = tag.commit.hexsha
status = repo.is_ancestor(latest_issue_commit, version_commit)
print("{0} is {2}deployed to {1}".format(
issue, key, (not status) and 'not ' or ''))
client.close()