Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ylt6/8d750addfdd76745f705 to your computer and use it in GitHub Desktop.
Save ylt6/8d750addfdd76745f705 to your computer and use it in GitHub Desktop.
Find out the last commit for specific file using rugged
def last_commit_for_path_within_head_repo(path)
# equal to `git rev-list --max-count 1 HEAD #{path}`
walker = Rugged::Walker.new(Rugged:Repository)
walker.sorting(Rugged::SORT_DATE)
walker.push(head_commit)
walker.hide(base_commit)
walker.each { |commit|
return commit.oid if commit.diff(paths: [path]).size > 0
}
base_commit
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment