Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get count of unpublished commit with GitPython?

With git status I can get information about count of unpublished commits:

» git status             
# On branch master
# Your branch is ahead of 'origin/master' by 2 commits.
#   (use "git push" to publish your local commits)
#
nothing to commit, working directory clean

I want to get unpublished commits (or count) with GitPython. I docs I found repo.git.status(), but this is not what I want.

like image 424
Gr1N Avatar asked Apr 06 '13 10:04

Gr1N


2 Answers

The command you are looking for is:

repo.iter_commits('BRANCH..BRANCH@{u}')

or if you want this as a list:

list(repo.iter_commits('BRANCH..BRANCH@{u}'))

The BRANCH@{u} syntax refers to the upstream branch of BRANCH.

like image 178
Chronial Avatar answered Oct 12 '22 22:10

Chronial


Thanks to @Chronial and @Clare-Macrae for your feedback Using gitPython ==3.1.11, I did it like that:

branch = self.repo.active_branch
unpushed_symbol = '⇡' if list(self.repo.iter_commits(f'{branch}@{{u}}..{branch}')) else constants.NOTHING
unpulled_symbol = '⇣' if list(self.repo.iter_commits(f'{branch}..{branch}@{{u}}')) else constants.NOTHING
like image 38
Édouard Lopez Avatar answered Oct 12 '22 23:10

Édouard Lopez