Skip to content

Commit

Permalink
git: improve audit of unknown git modules
Browse files Browse the repository at this point in the history
When auditing recipes, the potential git checkout was not performed by
Bob. Hence, no information is available if submodules shall be checked
out or not. In this case, assume that potentially present submodules
ought to be checked out recursively. Previously, we assumed that
submodules must not be checked out which is a questionable assumption.
  • Loading branch information
jkloetzke committed Nov 3, 2024
1 parent c452796 commit bc52767
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions pym/bob/scm/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -908,11 +908,10 @@ def __statusSubmodule(self, workspacePath, status, shouldExist, base = "."):


def getAuditSpec(self):
extra = {}
if self.__submodules:
extra['submodules'] = self.__submodules
if self.__recurseSubmodules:
extra['recurseSubmodules'] = True
extra = {
'submodules' : self.__submodules,
'recurseSubmodules' : self.__recurseSubmodules,
}
return ("git", self.__dir, extra)

def hasLiveBuildId(self):
Expand Down Expand Up @@ -987,8 +986,11 @@ class GitAudit(ScmAudit):

async def _scanDir(self, workspace, dir, extra):
self.__dir = dir
self.__submodules = extra.get('submodules', False)
self.__recurseSubmodules = extra.get('recurseSubmodules', False)
# In case we scan an unkown directry, the `extra` dict will be empty.
# In this case we assume submodules exist and are checked our
# recursively.
self.__submodules = extra.get('submodules')
self.__recurseSubmodules = extra.get('recurseSubmodules')
dir = os.path.join(workspace, dir)
try:
remotes = (await check_output(["git", "remote", "-v"],
Expand Down Expand Up @@ -1037,7 +1039,8 @@ async def __scanSubmodules(self, dir, shouldExist, base = "."):
# Normalize subset of submodules
if isinstance(shouldExist, list):
shouldExist = set(normPath(p) for p in shouldExist)
elif shouldExist:
elif shouldExist or shouldExist is None:
# If unspecified, we expect all submodules to be present.
shouldExist = set(normPath(p) for p in allPaths.keys())
else:
shouldExist = set()
Expand Down Expand Up @@ -1080,8 +1083,8 @@ def _load(self, data):
self.__commit = data["commit"]
self.__description = data["description"]
self.__dirty = data["dirty"]
self.__submodules = data.get("submodules", False)
self.__recurseSubmodules = data.get("recurseSubmodules", False)
self.__submodules = data.get("submodules")
self.__recurseSubmodules = data.get("recurseSubmodules")

def dump(self):
ret = {
Expand All @@ -1092,10 +1095,10 @@ def dump(self):
"description" : self.__description,
"dirty" : self.__dirty,
}
if self.__submodules:
if self.__submodules is not None:
ret["submodules"] = self.__submodules
if self.__recurseSubmodules:
ret["recurseSubmodules"] = True
if self.__recurseSubmodules is not None:
ret["recurseSubmodules"] = self.__recurseSubmodules
return ret

def getStatusLine(self):
Expand Down

0 comments on commit bc52767

Please sign in to comment.