original_docstring: 
          Clean stale local refs so they don't appear as fileserver environments
          
docstring: Clean stale local refs so they don't appear as fileserver environments
docstring_tokens: Clean stale local refs so they don ' t appear as fileserver environments
code: def clean_stale_refs(self, local_refs=None):  # pylint: disable=arguments-differ
          '''
          Clean stale local refs so they don't appear as fileserver environments
          '''
          if self.credentials is not None:
              log.debug(
                  'pygit2 does not support detecting stale refs for '
                  'authenticated remotes, saltenvs will not reflect '
                  'branches/tags removed from remote \'{0}\''
                  .format(self.id)
              )
              return []
          if local_refs is None:
              local_refs = self.repo.listall_references()
          remote_refs = []
          cmd_str = 'git ls-remote origin'
          cmd = subprocess.Popen(
              shlex.split(cmd_str),
              close_fds=not salt.utils.is_windows(),
              cwd=self.repo.workdir,
              stdout=subprocess.PIPE,
              stderr=subprocess.STDOUT)
          output = cmd.communicate()[0]
          if cmd.returncode != 0:
              log.warning(
                  'Failed to list remote references for {0} remote \'{1}\'. '
                  'Output from \'{2}\' follows:\n{3}'.format(
                      self.role,
                      self.id,
                      cmd_str,
                      output
                  )
              )
              return []
          for line in salt.utils.itertools.split(output, '\n'):
              try:
                  # Rename heads to match the remote ref names from
                  # pygit2.Repository.listall_references()
                  remote_refs.append(
                      line.split()[-1].replace(b'refs/heads/',
                                               b'refs/remotes/origin/')
                  )
              except IndexError:
                  continue
          cleaned = []
          if remote_refs:
              for ref in local_refs:
                  if ref.startswith('refs/heads/'):
                      # Local head, ignore it
                      continue
                  elif ref not in remote_refs:
                      self.repo.lookup_reference(ref).delete()
                      cleaned.append(ref)
          if cleaned:
              log.debug('{0} cleaned the following stale refs: {1}'
                        .format(self.role, cleaned))
          return cleaned
code_tokens: def clean_stale_refs ( self , local_refs = None ) : if self . credentials is not None : log . debug ( 'pygit2 does not support detecting stale refs for ' 'authenticated remotes, saltenvs will not reflect ' 'branches/tags removed from remote \'{0}\'' . format ( self . id ) ) return [ ] if local_refs is None : local_refs = self . repo . listall_references ( ) remote_refs = [ ] cmd_str = 'git ls-remote origin' cmd = subprocess . Popen ( shlex . split ( cmd_str ) , close_fds = not salt . utils . is_windows ( ) , cwd = self . repo . workdir , stdout = subprocess . PIPE , stderr = subprocess . STDOUT ) output = cmd . communicate ( ) [ 0 ] if cmd . returncode != 0 : log . warning ( 'Failed to list remote references for {0} remote \'{1}\'. ' 'Output from \'{2}\' follows:\n{3}' . format ( self . role , self . id , cmd_str , output ) ) return [ ] for line in salt . utils . itertools . split ( output , '\n' ) : try : remote_refs . append ( line . split ( ) [ - 1 ] . replace ( b'refs/heads/' , b'refs/remotes/origin/' ) ) except IndexError : continue cleaned = [ ] if remote_refs : for ref in local_refs : if ref . startswith ( 'refs/heads/' ) : continue elif ref not in remote_refs : self . repo . lookup_reference ( ref ) . delete ( ) cleaned . append ( ref ) if cleaned : log . debug ( '{0} cleaned the following stale refs: {1}' . format ( self . role , cleaned ) ) return cleaned
short_docstring: Clean stale local refs so they don't appear as fileserver environments
short_docstring_tokens: Clean stale local refs so they don ' t appear as fileserver environments
comment: # pylint: disable=arguments-differ$SEP$'''
          Clean stale local refs so they don't appear as fileserver environments
          '''$SEP$# Rename heads to match the remote ref names from$SEP$# pygit2.Repository.listall_references()$SEP$# Local head, ignore it