From 23dcf955a29193ac310f78add6ccfee42c57eee9 Mon Sep 17 00:00:00 2001 From: Felix Moessbauer Date: Sun, 11 Dec 2022 08:30:30 +0100 Subject: [PATCH] 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 Signed-off-by: Jan Kiszka --- kas/repos.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/kas/repos.py b/kas/repos.py index 8921bb4..af0dcae 100644 --- a/kas/repos.py +++ b/kas/repos.py @@ -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