code: def detect_vcs():
      
      location = os.path.abspath('.')
      while True:
          for vcs in Git, Mercurial, Bazaar, Subversion:
              if vcs.detect(location):
                  return vcs
          parent = os.path.dirname(location)
          if parent == location:
              raise Failure("Couldn't find version control data"
                            " (git/hg/bzr/svn supported)")
          location = parent
docs: Detect the version control system used for the current directory.