darxtrix
darxtrix

Reputation: 2040

List all commits since last release when the tag points to a commit on other branch

I need to list all the commits made to the master branch since my last release. I have to implement this functionality using pygit2. But the situation is a bit different here.

The release is made on the master branch using a tag on a commit to other branch. The naive approach would be to find the sha of the last tagged commit and move down the history from the HEAD till this sha. But this tagged commit is not made to the master branch in my case, it is made to other branch. Interestingly, the following gives the correct output when run over master branch:

$ git log sometag..HEAD --oneline

Here, sometag points to the commit made on the other branch. So, I want to know how could I implement this programmatically, if I have a list of all the commits made on the master branch.

One solution that is coming into my mind is to find the timestamp of the tagged commit and filter my commit list. How does git log is doing this, any ideas?

Upvotes: 1

Views: 2180

Answers (1)

Roman
Roman

Reputation: 6656

I think this will help you: first, we use Repository.walk() to get a Walker (commit iterator), and then we modify it (Walker.hide()) to exclude all commits reachable from sometag:

from pygit2 import Repository
from pygit2 import GIT_SORT_TIME

repo = Repository('.git')
start = repo.revparse_single('refs/heads/master')
release_tag = repo.revparse_single('refs/tags/sometag')

walker = repo.walk(start.id, GIT_SORT_TIME)
walker.hide(release_tag.id)
for commit in walker:
    print commit.message

Upvotes: 4

Related Questions