code: def get_git_revision(repopath):
      
      try:
          git = programs.find_program('git')
          assert git is not None and osp.isdir(osp.join(repopath, '.git'))
          commit = programs.run_program(git, ['rev-parse', '--short', 'HEAD'],
                                        cwd=repopath).communicate()
          commit = commit[0].strip()
          if PY3:
              commit = commit.decode(sys.getdefaultencoding())
  
          # Branch
          branches = programs.run_program(git, ['branch'],
                                          cwd=repopath).communicate()
          branches = branches[0]
          if PY3:
              branches = branches.decode(sys.getdefaultencoding())
          branches = branches.split('\n')
          active_branch = [b for b in branches if b.startswith('*')]
          if len(active_branch) != 1:
              branch = None
          else:
              branch = active_branch[0].split(None, 1)[1]
  
          return commit, branch
      except (subprocess.CalledProcessError, AssertionError, AttributeError,
              OSError):
          return None, None
docs: Return Git revision for the repository located at repopath
      
      Result is a tuple (latest commit hash, branch), with None values on
      error