@contextmanager
def _prepare_with_rev_range(repo, rev_range):
    # If a rev_range is specified then we need to make sure the working
    # directory is completely clean before continuing.
    if rev_range and working_directory_dirty(repo.working_dir):
        raise GitWorkingDirectoryDirty()

    try:
        head = repo.head.reference
        return_to_normal = head.checkout
    except __HOLE__:
        head = repo.head.commit
        return_to_normal = partial(repo.git.checkout, head.hexsha)

    repo.git.checkout(rev_range.b.hexsha)

    try:
        yield head
    finally:
        return_to_normal()
dataset/ETHPy150Open robmadole/jig/src/jig/gitutils/branches.py/_prepare_with_rev_range