diff --git a/lisa/tools/git.py b/lisa/tools/git.py index 01ede6d564..6e2197cf0e 100644 --- a/lisa/tools/git.py +++ b/lisa/tools/git.py @@ -178,6 +178,17 @@ def list_commit_ids(self, cwd: pathlib.PurePath) -> List[str]: ) return filter_ansi_escape(result.stdout).splitlines() + def get_latest_commit_id(self, cwd: pathlib.PurePath) -> str: + result = self.run( + "--no-pager log -n 1 --pretty=format:%h", + shell=True, + cwd=cwd, + force_run=True, + expected_exit_code=0, + expected_exit_code_failure_message="Failed to fetch latest commit id.", + ) + return filter_ansi_escape(result.stdout) + def init_submodules(self, cwd: pathlib.PurePath) -> None: self.run( "submodule update --init", diff --git a/lisa/transformers/kernel_source_installer.py b/lisa/transformers/kernel_source_installer.py index a3eb10f02b..659072847d 100644 --- a/lisa/transformers/kernel_source_installer.py +++ b/lisa/transformers/kernel_source_installer.py @@ -330,8 +330,8 @@ def get_source_code(self) -> PurePath: self._log.info(f"checkout code from: '{runbook.ref}'") git.checkout(ref=runbook.ref, cwd=code_path) - commitids = git.list_commit_ids(cwd=code_path) - self._log.info(f"Kernel HEAD is now at : {commitids[0]}") + latest_commit_id = git.get_latest_commit_id(cwd=code_path) + self._log.info(f"Kernel HEAD is now at : {latest_commit_id}") return code_path