Class GitOperation

  • All Implemented Interfaces:
    adams.core.logging.LoggingLevelHandler, adams.core.logging.LoggingSupporter, adams.core.SizeOfHandler, Serializable

    public class GitOperation
    extends adams.core.logging.CustomLoggingLevelObject
    Helper class for making git operations simpler.
    Author:
    fracpete (fracpete at waikato dot ac dot nz)
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected org.eclipse.jgit.api.Git m_Git
      the current git instance to use.
      protected Component m_Parent
      the component to use as parent for dialogs.
      protected boolean m_ShowErrors
      whether to show errors in the GUI.
      • Fields inherited from class adams.core.logging.LoggingObject

        m_Logger, m_LoggingIsEnabled, m_LoggingLevel
    • Constructor Summary

      Constructors 
      Constructor Description
      GitOperation()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean add​(File file)
      Adds the specified file.
      boolean add​(File[] files)
      Adds the specified files.
      boolean add​(File[] files, adams.core.MessageCollection errors)
      Adds the specified files.
      boolean add​(File file, adams.core.MessageCollection errors)
      Adds the specified file.
      boolean canAdd​(File file)
      Checks whether the file can be added.
      boolean canAdd​(File[] files)
      Checks whether the files can be added.
      boolean canAdd​(File[] files, adams.core.MessageCollection errors)
      Checks whether the files can be added.
      boolean canAdd​(File file, adams.core.MessageCollection errors)
      Checks whether the file can be added.
      boolean canCommit​(File file)
      Checks whether file can be committed.
      boolean canCommit​(File[] files)
      Checks whether files can be committed.
      boolean canCommit​(File[] files, adams.core.MessageCollection errors)
      Checks whether files can be committed.
      boolean canCommit​(File file, adams.core.MessageCollection errors)
      Checks whether file can be committed.
      boolean canLog​(File file)
      Checks whether a log can be generated.
      boolean canLog​(File file, adams.core.MessageCollection errors)
      Checks whether a log can be generated.
      protected boolean canProceed()
      Checks whether we can proceed with operations.
      boolean canPull()
      Checks whether a pull is possible.
      boolean canPull​(adams.core.MessageCollection errors)
      Checks whether a pull is possible.
      boolean canPush()
      Checks whether a push is possible.
      boolean canPush​(adams.core.MessageCollection errors)
      Checks whether a push is possible.
      boolean canRollback​(File file)
      Checks whether file can be rolled back.
      boolean canRollback​(File[] files)
      Checks whether files can be rolled back.
      boolean canRollback​(File[] files, adams.core.MessageCollection errors)
      Checks whether files can be rolled back.
      boolean canRollback​(File file, adams.core.MessageCollection errors)
      Checks whether file can be rolled back.
      String commit​(File[] files, String user, String email, String message)
      Commits the specified files.
      String commit​(File[] files, String user, String email, String message, adams.core.MessageCollection errors)
      Commits the specified files.
      String commit​(File file, String user, String email, String message)
      Commits the specified file.
      String commit​(File file, String user, String email, String message, adams.core.MessageCollection errors)
      Commits the specified file.
      org.eclipse.jgit.api.Git getGit()
      Returns the git instance in use.
      boolean getShowErrors()
      Returns whether to show error dialogs.
      String log​(File file)
      Generates a log for the specified file.
      String log​(File file, adams.core.MessageCollection errors)
      Generates a log for the specified file.
      String pull()
      Performs a pull on the repo.
      String pull​(adams.core.MessageCollection errors)
      Performs a pull on the repo.
      String push()
      Performs a push on the repo.
      String push​(adams.core.MessageCollection errors)
      Performs a push on the repo.
      boolean rollback​(File file)
      Performs a rollback on a file,
      boolean rollback​(File[] files)
      Performs a rollback on files.
      boolean rollback​(File[] files, adams.core.MessageCollection errors)
      Performs a rollback on files.
      boolean rollback​(File file, adams.core.MessageCollection errors)
      Performs a rollback on a file,
      void setGit​(org.eclipse.jgit.api.Git value)
      Sets the git instance to use.
      void setShowErrors​(boolean value)
      Sets whether to show error dialogs.
      protected <T extends org.eclipse.jgit.api.TransportCommand>
      T
      setTransportConfigCallbackIfNecessary​(T cmd)
      Adds the transport config callback (with sshd factory) if necessary.
      • Methods inherited from class adams.core.logging.CustomLoggingLevelObject

        setLoggingLevel
      • Methods inherited from class adams.core.logging.LoggingObject

        configureLogger, getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
      • Methods inherited from interface adams.core.logging.LoggingLevelHandler

        getLoggingLevel
    • Field Detail

      • m_Git

        protected org.eclipse.jgit.api.Git m_Git
        the current git instance to use.
      • m_ShowErrors

        protected boolean m_ShowErrors
        whether to show errors in the GUI.
      • m_Parent

        protected Component m_Parent
        the component to use as parent for dialogs.
    • Constructor Detail

      • GitOperation

        public GitOperation()
    • Method Detail

      • setGit

        public void setGit​(org.eclipse.jgit.api.Git value)
        Sets the git instance to use.
        Parameters:
        value - the instance to use
      • getGit

        public org.eclipse.jgit.api.Git getGit()
        Returns the git instance in use.
        Returns:
        the instance in use, null if none set
      • setShowErrors

        public void setShowErrors​(boolean value)
        Sets whether to show error dialogs.
        Parameters:
        value - true if to show
      • getShowErrors

        public boolean getShowErrors()
        Returns whether to show error dialogs.
        Returns:
        true if to show
      • canProceed

        protected boolean canProceed()
        Checks whether we can proceed with operations.
        Returns:
        true if able to proceed
      • setTransportConfigCallbackIfNecessary

        protected <T extends org.eclipse.jgit.api.TransportCommand> T setTransportConfigCallbackIfNecessary​(T cmd)
        Adds the transport config callback (with sshd factory) if necessary. If the remote url starts with "git@", then we assume that ssh keys are used.
        Parameters:
        cmd - the command to update
        Returns:
        the updated command
      • canLog

        public boolean canLog​(File file)
        Checks whether a log can be generated.
        Parameters:
        file - the file to generate the log for
        Returns:
        true if log can be generated
      • canLog

        public boolean canLog​(File file,
                              adams.core.MessageCollection errors)
        Checks whether a log can be generated.
        Parameters:
        file - the file to generate the log for
        errors - for collecting errors, can be null
        Returns:
        true if log can be generated
      • log

        public String log​(File file)
        Generates a log for the specified file.
        Parameters:
        file - the file to get the log for
        Returns:
        the log output, null if failed
      • log

        public String log​(File file,
                          adams.core.MessageCollection errors)
        Generates a log for the specified file.
        Parameters:
        file - the file to get the log for
        errors - for storing errors, can be null
        Returns:
        the log output, null if failed
      • canPull

        public boolean canPull()
        Checks whether a pull is possible.
        Returns:
        true if pull possible
      • canPull

        public boolean canPull​(adams.core.MessageCollection errors)
        Checks whether a pull is possible.
        Parameters:
        errors - for collecting errors, can be null
        Returns:
        true if pull possible
      • pull

        public String pull()
        Performs a pull on the repo.
        Returns:
        the pull result, null if failed
      • pull

        public String pull​(adams.core.MessageCollection errors)
        Performs a pull on the repo.
        Parameters:
        errors - for storing errors, can be null
        Returns:
        the pull result, null if failed
      • canPush

        public boolean canPush()
        Checks whether a push is possible.
        Returns:
        true if push possible
      • canPush

        public boolean canPush​(adams.core.MessageCollection errors)
        Checks whether a push is possible.
        Parameters:
        errors - for collecting errors, can be null
        Returns:
        true if push possible
      • push

        public String push()
        Performs a push on the repo.
        Returns:
        the result of the push, null if failed
      • push

        public String push​(adams.core.MessageCollection errors)
        Performs a push on the repo.
        Parameters:
        errors - for collecting errors, can be null
        Returns:
        the result of the push, null if failed
      • canAdd

        public boolean canAdd​(File file)
        Checks whether the file can be added.
        Parameters:
        file - the file to check
        Returns:
        true if can be added
      • canAdd

        public boolean canAdd​(File file,
                              adams.core.MessageCollection errors)
        Checks whether the file can be added.
        Parameters:
        file - the file to check
        errors - for collecting errors, can be null
        Returns:
        true if can be added
      • add

        public boolean add​(File file)
        Adds the specified file.
        Parameters:
        file - the file to add
        Returns:
        true if successful
      • add

        public boolean add​(File file,
                           adams.core.MessageCollection errors)
        Adds the specified file.
        Parameters:
        file - the file to add
        errors - for storing errors, can be null
        Returns:
        true if successful
      • canAdd

        public boolean canAdd​(File[] files)
        Checks whether the files can be added.
        Parameters:
        files - the files to check
        Returns:
        true if can be added
      • canAdd

        public boolean canAdd​(File[] files,
                              adams.core.MessageCollection errors)
        Checks whether the files can be added.
        Parameters:
        files - the files to check
        errors - for collecting errors, can be null
        Returns:
        true if can be added
      • add

        public boolean add​(File[] files)
        Adds the specified files.
        Parameters:
        files - the files to add
        Returns:
        true if successful
      • add

        public boolean add​(File[] files,
                           adams.core.MessageCollection errors)
        Adds the specified files.
        Parameters:
        files - the files to add
        errors - for storing errors, can be null
        Returns:
        true if successful
      • canCommit

        public boolean canCommit​(File file)
        Checks whether file can be committed.
        Parameters:
        file - the file to check
        Returns:
        true if can be committed
      • canCommit

        public boolean canCommit​(File file,
                                 adams.core.MessageCollection errors)
        Checks whether file can be committed.
        Parameters:
        file - the file to check
        errors - for collecting errors, can be null
        Returns:
        true if can be committed
      • commit

        public String commit​(File file,
                             String user,
                             String email,
                             String message)
        Commits the specified file.
        Parameters:
        file - the file to commit
        user - the user to use in the commit
        email - the email to use in the commit
        message - the commit message
        Returns:
        the result string of the commit, null if failed
      • commit

        public String commit​(File file,
                             String user,
                             String email,
                             String message,
                             adams.core.MessageCollection errors)
        Commits the specified file.
        Parameters:
        file - the file to commit
        user - the user to use in the commit
        email - the email to use in the commit
        message - the commit message
        errors - for storing errors, can be null
        Returns:
        the result string of the commit, null if failed
      • canCommit

        public boolean canCommit​(File[] files)
        Checks whether files can be committed.
        Parameters:
        files - the files to check
        Returns:
        true if can be committed
      • canCommit

        public boolean canCommit​(File[] files,
                                 adams.core.MessageCollection errors)
        Checks whether files can be committed.
        Parameters:
        files - the files to check
        errors - for collecting errors, can be null
        Returns:
        true if can be committed
      • commit

        public String commit​(File[] files,
                             String user,
                             String email,
                             String message)
        Commits the specified files.
        Parameters:
        files - the files to commit
        user - the user to use in the commit
        email - the email to use in the commit
        message - the commit message
        Returns:
        the result string of the commit, null if failed
      • commit

        public String commit​(File[] files,
                             String user,
                             String email,
                             String message,
                             adams.core.MessageCollection errors)
        Commits the specified files.
        Parameters:
        files - the files to commit
        user - the user to use in the commit
        email - the email to use in the commit
        message - the commit message
        errors - for storing errors, can be null
        Returns:
        the result string of the commit, null if failed
      • canRollback

        public boolean canRollback​(File file)
        Checks whether file can be rolled back.
        Parameters:
        file - the file to roll back
        Returns:
        true if rollback possible
      • canRollback

        public boolean canRollback​(File file,
                                   adams.core.MessageCollection errors)
        Checks whether file can be rolled back.
        Parameters:
        file - the file to roll back
        errors - for collecting errors, can be null
        Returns:
        true if rollback possible
      • rollback

        public boolean rollback​(File file)
        Performs a rollback on a file,
        Parameters:
        file - the file to revert the changes for
        Returns:
        true if successfully rolled back
      • rollback

        public boolean rollback​(File file,
                                adams.core.MessageCollection errors)
        Performs a rollback on a file,
        Parameters:
        file - the file to revert the changes for
        errors - for collecting errors, can be null
        Returns:
        true if successfully rolled back
      • canRollback

        public boolean canRollback​(File[] files)
        Checks whether files can be rolled back.
        Parameters:
        files - the files to roll back
        Returns:
        true if rollback possible
      • canRollback

        public boolean canRollback​(File[] files,
                                   adams.core.MessageCollection errors)
        Checks whether files can be rolled back.
        Parameters:
        files - the files to roll back
        errors - for collecting errors, can be null
        Returns:
        true if rollback possible
      • rollback

        public boolean rollback​(File[] files)
        Performs a rollback on files.
        Parameters:
        files - the files to revert the changes for
        Returns:
        true if successfully rolled back
      • rollback

        public boolean rollback​(File[] files,
                                adams.core.MessageCollection errors)
        Performs a rollback on files.
        Parameters:
        files - the files to revert the changes for
        errors - for collecting errors, can be null
        Returns:
        true if successfully rolled back