Ascend the directory hierarchy to find a .git or .hg directory.