original_docstring: Redoes the last undone change.
  
          This command is *only* available if coBib's git-integration has been enabled via
          `config.database.git` *and* initialized properly (see `cobib.commands.init.InitCommand`).
          If that is the case, this command will re-apply the changes *of a previously undone* command
          (see `cobib.commands.undo.UndoCommand`).
  
          Args:
              args: a sequence of additional arguments used for the execution. The following values
                  are allowed for this command:
                      * **no** additional arguments are required for this subcommand!
              out: the output IO stream. This defaults to `sys.stdout`.
          
docstring: Redoes the last undone change.
  This command is *only* available if coBib's git-integration has been enabled via
  `config.database.git` *and* initialized properly .
  If that is the case, this command will re-apply the changes *of a previously undone* command
  .
docstring_tokens: Redoes the last undone change . This command is * only * available if coBib ' s git - integration has been enabled via ` config . database . git ` * and * initialized properly . If that is the case this command will re - apply the changes * of a previously undone * command .
code: def execute(self, args: List[str], out: IO[Any] = sys.stdout) -> None:
          """Redoes the last undone change.
  
          This command is *only* available if coBib's git-integration has been enabled via
          `config.database.git` *and* initialized properly (see `cobib.commands.init.InitCommand`).
          If that is the case, this command will re-apply the changes *of a previously undone* command
          (see `cobib.commands.undo.UndoCommand`).
  
          Args:
              args: a sequence of additional arguments used for the execution. The following values
                  are allowed for this command:
                      * **no** additional arguments are required for this subcommand!
              out: the output IO stream. This defaults to `sys.stdout`.
          """
          git_tracked = config.database.git
          if not git_tracked:
              msg = (
                  "You must enable coBib's git-tracking in order to use the `Redo` command."
                  "\nPlease refer to the man-page for more information on how to do so."
              )
              LOGGER.error(msg)
              return
  
          file = RelPath(config.database.file).path
          root = file.parent
          if not (root / ".git").exists():
              msg = (
                  "You have configured, but not initialized coBib's git-tracking."
                  "\nPlease consult `cobib init --help` for more information on how to do so."
              )
              LOGGER.error(msg)
              return
  
          LOGGER.debug("Starting Redo command.")
          parser = ArgumentParser(prog="redo", description="Redo subcommand parser.")
  
          try:
              # pylint: disable=unused-variable
              largs = parser.parse_args(args)
          except argparse.ArgumentError as exc:
              LOGGER.error(exc.message)
              return
  
          Event.PreRedoCommand.fire(largs)
  
          LOGGER.debug("Obtaining git log.")
          lines = subprocess.check_output(
              [
                  "git",
                  "--no-pager",
                  "-C",
                  f"{root}",
                  "log",
                  "--oneline",
                  "--no-decorate",
                  "--no-abbrev",
              ]
          )
          redone_shas = set()
          for commit in lines.decode().strip().split("\n"):
              LOGGER.debug("Processing commit %s", commit)
              sha, *message = commit.split()
              if message[0] == "Redo":
                  # Store already redone commit sha
                  LOGGER.debug("Storing redone commit sha: %s", message[-1])
                  redone_shas.add(message[-1])
                  continue
              if sha in redone_shas:
                  LOGGER.info("Skipping %s as it was already redone", sha)
                  continue
              if message[0] == "Undo":
                  LOGGER.debug("Attempting to redo %s.", sha)
                  commands = [
                      f"git -C {root} revert --no-commit {sha}",
                      f"git -C {root} commit --no-gpg-sign --quiet --message 'Redo {sha}'",
                  ]
                  with subprocess.Popen(
                      "; ".join(commands), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE
                  ) as redo:
                      redo.communicate()
                      if redo.returncode != 0:
                          LOGGER.error(  # pragma: no cover
                              "Redo was unsuccessful. Please consult the logs and git history of your"
                              " database for more information."
                          )
                      else:
                          # update Database
                          Database().read()
                  break
          else:
              msg = "Could not find a commit to redo. You must have undone something first!"
              LOGGER.warning(msg)
              sys.exit(1)
  
          Event.PostRedoCommand.fire(root, sha)
code_tokens: def execute ( self , args : List [ str ] , out : IO [ Any ] = sys . stdout ) -> None : git_tracked = config . database . git if not git_tracked : msg = ( "You must enable coBib's git-tracking in order to use the `Redo` command." "\nPlease refer to the man-page for more information on how to do so." ) LOGGER . error ( msg ) return file = RelPath ( config . database . file ) . path root = file . parent if not ( root / ".git" ) . exists ( ) : msg = ( "You have configured, but not initialized coBib's git-tracking." "\nPlease consult `cobib init --help` for more information on how to do so." ) LOGGER . error ( msg ) return LOGGER . debug ( "Starting Redo command." ) parser = ArgumentParser ( prog = "redo" , description = "Redo subcommand parser." ) try : largs = parser . parse_args ( args ) except argparse . ArgumentError as exc : LOGGER . error ( exc . message ) return Event . PreRedoCommand . fire ( largs ) LOGGER . debug ( "Obtaining git log." ) lines = subprocess . check_output ( [ "git" , "--no-pager" , "-C" , f"{root}" , "log" , "--oneline" , "--no-decorate" , "--no-abbrev" , ] ) redone_shas = set ( ) for commit in lines . decode ( ) . strip ( ) . split ( "\n" ) : LOGGER . debug ( "Processing commit %s" , commit ) sha , * message = commit . split ( ) if message [ 0 ] == "Redo" : LOGGER . debug ( "Storing redone commit sha: %s" , message [ - 1 ] ) redone_shas . add ( message [ - 1 ] ) continue if sha in redone_shas : LOGGER . info ( "Skipping %s as it was already redone" , sha ) continue if message [ 0 ] == "Undo" : LOGGER . debug ( "Attempting to redo %s." , sha ) commands = [ f"git -C {root} revert --no-commit {sha}" , f"git -C {root} commit --no-gpg-sign --quiet --message 'Redo {sha}'" , ] with subprocess . Popen ( "; " . join ( commands ) , shell = True , stdout = subprocess . PIPE , stderr = subprocess . PIPE ) as redo : redo . communicate ( ) if redo . returncode != 0 : LOGGER . error ( "Redo was unsuccessful. Please consult the logs and git history of your" " database for more information." ) else : Database ( ) . read ( ) break else : msg = "Could not find a commit to redo. You must have undone something first!" LOGGER . warning ( msg ) sys . exit ( 1 ) Event . PostRedoCommand . fire ( root , sha )
short_docstring: Redoes the last undone change.
short_docstring_tokens: Redoes the last undone change .
comment: """Redoes the last undone change.
  
          This command is *only* available if coBib's git-integration has been enabled via
          `config.database.git` *and* initialized properly (see `cobib.commands.init.InitCommand`).
          If that is the case, this command will re-apply the changes *of a previously undone* command
          (see `cobib.commands.undo.UndoCommand`).
  
          Args:
              args: a sequence of additional arguments used for the execution. The following values
                  are allowed for this command:
                      * **no** additional arguments are required for this subcommand!
              out: the output IO stream. This defaults to `sys.stdout`.
          """$SEP$# pylint: disable=unused-variable$SEP$# Store already redone commit sha$SEP$# pragma: no cover$SEP$# update Database