You are not logged in.

#1 2021-02-14 14:07:02

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,734
Website

git to retrieve the number of commits from a purely remote repo?

Is it possible to use git to retrieve the number of commits from a purely remote repo?

For example, I can grab the last commit hash to a purely remote repo this way:

% git ls-remote -h https://github.com/torvalds/linux      
358feceebbf68f33c44c6650d14455389e65282d	refs/heads/master

I want to see the number of commits in a like fashion.  For example:

% git COMMAND ... https://github.com/torvalds/linux
984,205

Last edited by graysky (2021-02-14 14:09:21)

Offline

#2 2021-02-15 03:40:00

eschwartz
Fellow
Registered: 2014-08-08
Posts: 4,097

Re: git to retrieve the number of commits from a purely remote repo?

Not really, though if you have ssh interactive shell access on the remote you could run git describe remotely.

What's the purpose of this?


Managing AUR repos The Right Way -- aurpublish (now a standalone tool)

Offline

#3 2021-02-15 12:05:00

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,734
Website

Re: git to retrieve the number of commits from a purely remote repo?

I want to have a script pull the latest commit hash (which I can via piping the output above into awk) and also the total number of commits remotely.  I too do not think it is possible.

Offline

#4 2021-02-16 02:04:09

eschwartz
Fellow
Registered: 2014-08-08
Posts: 4,097

Re: git to retrieve the number of commits from a purely remote repo?

That's not the purpose of this, that's the mechanism you intend to use in the course of achieving your purpose.

This xyproblem thing is always pretty annoying.


Managing AUR repos The Right Way -- aurpublish (now a standalone tool)

Offline

#5 2021-10-16 12:19:47

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,734
Website

Re: git to retrieve the number of commits from a purely remote repo?

I ended up hacking a grep/head/sed solution together but it's ugly.

URL='https://github.com/graysky2/xbmc'
BRANCH=gs-gbm_nexus

newcommit=$(git ls-remote -h "$URL" "$BRANCH" | awk '{print $1}')
newcount=$(curl -v --stderr - "$URL"/tree/"$BRANCH" | grep -B 1 "Commits on $BRANCH" | head -n1 | sed -e s'/^.*<strong>//' -e 's/<\/strong>//' -e 's/,//')

echo $newcommit
echo $newcount

Offline

Board footer

Powered by FluxBB