code: def set_commit(self, commit, logmsg=None):
          
          # check the type - assume the best if it is a base-string
          invalid_type = False
          if isinstance(commit, Object):
              invalid_type = commit.type != Commit.type
          elif isinstance(commit, SymbolicReference):
              invalid_type = commit.object.type != Commit.type
          else:
              try:
                  invalid_type = self.repo.rev_parse(commit).type != Commit.type
              except (BadObject, BadName):
                  raise ValueError("Invalid object: %s" % commit)
              # END handle exception
          # END verify type
  
          if invalid_type:
              raise ValueError("Need commit, got %r" % commit)
          # END handle raise
  
          # we leave strings to the rev-parse method below
          self.set_object(commit, logmsg)
  
          return self
docs: As set_object, but restricts the type of object to be a Commit
  
          :raise ValueError: If commit is not a Commit object or doesn't point to
              a commit
          :return: self