简体   繁体   English

如何使用 GitPython 获取未发布提交的数量?

[英]How to get count of unpublished commit with GitPython?

With git status I can get information about count of unpublished commits:使用git status我可以获得有关未发布提交计数的信息:

» 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.我想使用 GitPython 获取未发布的提交(或计数)。 I docs I found repo.git.status() , but this is not what I want.我记录了我找到的repo.git.status() ,但这不是我想要的。

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 . BRANCH@{u}语法指的是BRANCH的上游分支。

Thanks to @Chronial and @Clare-Macrae for your feedback Using gitPython ==3.1.11 , I did it like that:感谢 @Chronial 和 @Clare-Macrae 的反馈使用gitPython ==3.1.11 ,我是这样做的:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM