From 51d09cb0b24c0a3f1dd5526254e6dad4adfe11c0 Mon Sep 17 00:00:00 2001 From: Sam Thursfield Date: Wed, 3 Dec 2014 14:38:31 +0000 Subject: Document that GitDirectory.get_config() can raise an exception Also fix wrong indent. --- morphlib/gitdir.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/morphlib/gitdir.py b/morphlib/gitdir.py index ed71e422..4c3efbd3 100644 --- a/morphlib/gitdir.py +++ b/morphlib/gitdir.py @@ -485,11 +485,15 @@ class GitDirectory(object): self._config[key] = value def get_config(self, key): - '''Return value for a git repository configuration variable.''' + '''Return value for a git repository configuration variable. + + If the variable is unset, this will raise cliapp.AppException. + + ''' if key not in self._config: - value = morphlib.git.gitcmd(self._runcmd, 'config', '-z', key) - self._config[key] = value.rstrip('\0') + value = morphlib.git.gitcmd(self._runcmd, 'config', '-z', key) + self._config[key] = value.rstrip('\0') return self._config[key] def get_remote(self, *args, **kwargs): -- cgit v1.2.1 From 39f708721adee1539e503f6cb2035f70288367e9 Mon Sep 17 00:00:00 2001 From: Sam Thursfield Date: Wed, 3 Dec 2014 14:39:57 +0000 Subject: Gracefully handle Git repos in system branches with missing config Previously if there were repos present in the system branch that weren't put there with `morph edit` or had lost their Morph-specific configuration entries somehow you might see this error: ERROR: Command failed: git config -z morph.repository --- morphlib/sysbranchdir.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/morphlib/sysbranchdir.py b/morphlib/sysbranchdir.py index 4351c6b3..4dbc5f6c 100644 --- a/morphlib/sysbranchdir.py +++ b/morphlib/sysbranchdir.py @@ -72,7 +72,11 @@ class SystemBranchDirectory(object): def _find_git_directory(self, repo_url): for gd in self.list_git_directories(): - if gd.get_config('morph.repository') == repo_url: + try: + gd_repo_url = gd.get_config('morph.repository') + except cliapp.AppException: # pragma: no cover + continue + if gd_repo_url == repo_url: return gd.dirname return None -- cgit v1.2.1 From e7110f6551d25ac290f48abaa3a58262a98ba6e3 Mon Sep 17 00:00:00 2001 From: Sam Thursfield Date: Wed, 3 Dec 2014 14:42:23 +0000 Subject: Fix finding Git directories to include in a temporary build ref When running 'morph build' the code looks through all the Git repos in a system branch, to see which are involved in the build. These are then checked for local changes and have temporary build refs created in them. Due to a mistake in the logic, this would give up if it found a repo that came from elsewhere but was inside the system branch directory. So in the past some legitimate repos might have been ignored sometimes. --- morphlib/buildbranch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/morphlib/buildbranch.py b/morphlib/buildbranch.py index 2d529133..09f6e104 100644 --- a/morphlib/buildbranch.py +++ b/morphlib/buildbranch.py @@ -66,7 +66,7 @@ class BuildBranch(object): repo_uuid = gd.get_config('morph.uuid') except cliapp.AppException: # Not a repository cloned by morph, ignore - break + continue build_ref = os.path.join('refs/heads', build_ref_prefix, branch_uuid, repo_uuid) # index is commit of workspace + uncommitted changes may want -- cgit v1.2.1 From b9af32ba9f60b66ef1487438f97a37c54bf95b3b Mon Sep 17 00:00:00 2001 From: Sam Thursfield Date: Wed, 3 Dec 2014 12:10:21 +0000 Subject: Give a better error when no repos are found in a system branch Previously, if no repos were found Morph would raise 'ValueError: need more than 0 values to unpack' and leave the user with a traceback. --- morphlib/buildbranch.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/morphlib/buildbranch.py b/morphlib/buildbranch.py index 09f6e104..2482bc9a 100644 --- a/morphlib/buildbranch.py +++ b/morphlib/buildbranch.py @@ -35,6 +35,15 @@ class BuildBranchCleanupError(cliapp.AppException): % locals()) +class NoReposError(cliapp.AppException): + def __init__(self, bb, ignored): + self.bb = bb + cliapp.AppException.__init__( + self, "No repos were found in system branch (ignored %i which " + "didn't have the right morph.uuid setting)" % (ignored)) + + + class BuildBranch(object): '''Represent the sources modified in a system branch. @@ -61,7 +70,7 @@ class BuildBranch(object): self._branch_root = sb.get_config('branch.root') branch_uuid = sb.get_config('branch.uuid') - for gd in sb.list_git_directories(): + for count, gd in enumerate(sb.list_git_directories()): try: repo_uuid = gd.get_config('morph.uuid') except cliapp.AppException: @@ -76,6 +85,9 @@ class BuildBranch(object): index.set_to_tree(gd.resolve_ref_to_tree(gd.HEAD)) self._to_push[gd] = (build_ref, index) + if len(self._to_push) == 0: + raise NoReposError(self, count) + rootinfo, = ((gd, index) for gd, (build_ref, index) in self._to_push.iteritems() if gd.get_config('morph.repository') == self._branch_root) -- cgit v1.2.1