Allow retrieval of ahead/behind commits

Proposal to implement #1440.