Check if a branch is empty

天大地大妈咪最大 提交于 2021-02-19 08:15:08

问题


Is there a way to check if a branch is empty using the github API?

/repos/:owner/:repo/branches/:branch returns the last commit, but how do I check if the commit belongs to the same branch or the parent branch?


回答1:


As illustrated in "Find the parent branch of a git branch", a git branch has no "parent branch".

A branch can be empty compared to another, and ahead compared to another:

--x--x (branch1)
      \
       o--o (branch2, branch3)

Here, branch3 could be considered "empty" when compared to branch2, and 2 commits ahead when compared to branch1.

And there is no way to know if branch3 was created from branch2 or branch1.

With the GitHub API, you would need to compare two commits, which can be two branch names:

GET /repos/:owner/:repo/compare/hubot:branchname...octocat:branchname

That would give you fields of interest like:

"status": "behind",
"ahead_by": 1,
"behind_by": 2,

But that status is only relative to "another branch", without easy way to know if that "other branch" is its "parent" or not.



来源:https://stackoverflow.com/questions/37526506/check-if-a-branch-is-empty

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!