From e42abfeeed459c211431e751a967ebbc66052be2 Mon Sep 17 00:00:00 2001 From: Elementaryfire89 <55189072+elementaryfire89@users.noreply.github.com> Date: Fri, 17 Mar 2023 15:30:10 +0100 Subject: [PATCH] Get remote last commit Id Function with the purpose of obtain remote last commit id that can be used whit getLastCommitID to verify that the local repository is up to date with the latest commit --- src/GitRepository.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/GitRepository.php b/src/GitRepository.php index 2ef6f83..1fa674c 100644 --- a/src/GitRepository.php +++ b/src/GitRepository.php @@ -620,4 +620,17 @@ protected function run(...$args) return $result; } + /** + * Returns last commit ID on remote + * `git log origin master --pretty=format:"%H" -n 1` + * @return CommitId + * @throws GitException + */ + + public function getLastRemoteCommitId($remote) + { + $result = $this->run('log', $remote, '--pretty=format:%H', '-n', '1'); + $lastLine = $result->getOutputLastLine(); + return new CommitId((string) $lastLine); + } }