diff options
author | Ben Brown <ben.brown@codethink.co.uk> | 2017-09-07 17:30:11 +0000 |
---|---|---|
committer | Ben Brown <ben.brown@codethink.co.uk> | 2017-09-07 17:30:11 +0000 |
commit | 6ba6ab10b2e6f3328b2fe0ef4fda4b202df9510c (patch) | |
tree | 9adeaf7c2acdbfc06db81831b3c3d4f5f882d595 | |
parent | d68a3068b5d558e148b62acd6bd914a54e6ed091 (diff) | |
parent | 6e6b16afefc3cefa891a8f3af2483f07aaedf9af (diff) | |
download | ybd-6ba6ab10b2e6f3328b2fe0ef4fda4b202df9510c.tar.gz |
Merge branch 'benbrown/warn-sha-not-in-ref' into 'master'
Warn/error if sha is not present in provided ref
Closes #264
See merge request !390
-rwxr-xr-x | ybd/__main__.py | 3 | ||||
-rw-r--r-- | ybd/cache.py | 1 | ||||
-rw-r--r-- | ybd/pots.py | 3 | ||||
-rw-r--r-- | ybd/repos.py | 47 |
4 files changed, 46 insertions, 8 deletions
diff --git a/ybd/__main__.py b/ybd/__main__.py index 7014280..5be770e 100755 --- a/ybd/__main__.py +++ b/ybd/__main__.py @@ -93,13 +93,12 @@ with timer('TOTAL'): log('ARCH', 'No definitions for', config['arch'], exit=True) write_cache_key() + app.defs.save_trees() if config.get('mode', 'normal') == 'keys-only': os._exit(0) cache.cull(config['artifacts']) - app.defs.save_trees() - sandbox.executor = sandboxlib.executor_for_platform() log(config['target'], 'Sandbox using %s' % sandbox.executor) if sandboxlib.chroot == sandbox.executor: diff --git a/ybd/cache.py b/ybd/cache.py index f3b312d..b12d0f3 100644 --- a/ybd/cache.py +++ b/ybd/cache.py @@ -324,6 +324,7 @@ def cull(artifact_dir): def clear(deleted, artifact_dir): artifacts = utils.sorted_ls(artifact_dir) + artifacts[:] = [a for a in artifacts if a != '.trees'] for artifact in artifacts: stat = os.statvfs(artifact_dir) free = stat.f_frsize * stat.f_bavail / 1000000000 diff --git a/ybd/pots.py b/ybd/pots.py index 07bb644..4debe4e 100644 --- a/ybd/pots.py +++ b/ybd/pots.py @@ -21,6 +21,7 @@ from app import config, log from defaults import Defaults from morphs import Morphs from morphdumper import morph_dump +from repos import tracking_branch class Pots(object): @@ -82,7 +83,7 @@ class Pots(object): dn = self._data[path] sha1 = dn.get('sha', dn.get('ref')) tree_entry = self._trees.get(path) - if sha1 and tree_entry: + if sha1 and tree_entry and not tracking_branch(dn): if sha1 == tree_entry[0]: dn['sha'] = tree_entry[0] dn['tree'] = tree_entry[1] diff --git a/ybd/repos.py b/ybd/repos.py index 9674ee9..75685fb 100644 --- a/ybd/repos.py +++ b/ybd/repos.py @@ -98,10 +98,46 @@ def get_last_tag(gitdir): return None +def tracking_branch(dn): + track = app.config.get('track-branches', []) + return (isinstance(track, list) and dn['path'] in track) or track + + +def ensure_ref_contains_sha(dn, gitdir, ref, sha): + check = app.config.get('check-definitions') + if check == 'ignore' or tracking_branch(dn): + return + + with app.chdir(gitdir), open(os.devnull, "w") as fnull: + ref = dn['ref'] + if ref == sha: + return + + def sha_in_ref(): + try: + return bool(check_output(['git', 'for-each-ref', '--contains', + sha, 'refs/*/' + ref], stderr=fnull, + universal_newlines=True).strip()) + except: + return False + + if not sha_in_ref(): + # The sha may currently exist in another branch, + # force an update of the provided ref. + repo_url = get_repo_url(dn['repo']) + call(['git', 'fetch', repo_url, + '+refs/*/{0}:refs/*/{0}'.format(ref)], + stdout=fnull, stderr=fnull) + + if not sha_in_ref(): + exit = check == 'exit' + app.log(dn, 'WARNING: unable to find %s within' % + sha, ref, exit=exit) + + def get_tree(dn): info = get_transport_info(dn['repo']) - track = app.config.get('track-branches', []) - track = (isinstance(track, list) and dn['path'] in track) or track + track = tracking_branch(dn) ref = dn.get('ref') if track else dn.get('sha', dn.get('ref')) gitdir = info['dir'] @@ -130,9 +166,10 @@ def get_tree(dn): try: # Returns a (tree, sha) tuple. - return check_output(['git', 'rev-parse', ref + '^{tree}', ref], - universal_newlines=True).split() - + treesha = check_output(['git', 'rev-parse', ref + '^{tree}', ref], + universal_newlines=True).split() + ensure_ref_contains_sha(dn, gitdir, dn['ref'], treesha[1]) + return treesha except: # either we don't have a git dir, or ref is not unique # or ref does not exist |