add revision attribute to repo class

This patch adds a programmatic attribute 'revision' to the repo class.
This attribute contains the exact revision at the time of the checkout
of a repository. By that, we can avoid the ambiguity of refspecs
containing tags or branch names. Internally, the revision is not yet
used but just made available for future downstream users (e.g. plugins).

Note, that the revision has to be re-queried on each access, as the
Config class re-instantiates the repos for each consumer.

Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
This commit is contained in:
Felix Moessbauer 2022-12-11 08:30:30 +01:00 committed by Jan Kiszka
parent 53369faf55
commit 23dcf955a2

View File

@ -72,6 +72,15 @@ class Repo:
except ValueError:
continue
return self.url
elif item == 'revision':
if not self.refspec:
return None
(_, output) = run_cmd(self.resolve_branch_cmd(),
cwd=self.path, fail=False)
if output:
return output.strip()
return self.refspec
# Default behaviour
raise AttributeError