Class GitUtils

java.lang.Object
com._1c.g5.v8.dt.common.git.GitUtils

public class GitUtils extends Object
The Git and refactoring mechanism integration utility methods.
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    addFilesToGitIndex(org.eclipse.core.resources.IProject project, Collection<org.eclipse.core.runtime.IPath> oldAbsolutePaths, Collection<org.eclipse.core.runtime.IPath> newAbsolutePaths, boolean cached)
    Adds the files associated with the given new and old absolute paths to the Git index.
    static org.eclipse.jgit.lib.Repository
    getGitRepository(org.eclipse.core.resources.IResource resource)
    Determines the Git repository containing the given resource.
    static org.eclipse.jgit.lib.Repository
    getGitRepository(org.eclipse.core.runtime.IPath path)
    Determines the Git repository containing the given IPath.
    static Optional<org.eclipse.jgit.lib.ObjectId>
    getHeadId(org.eclipse.jgit.lib.Repository repository)
    Returns optional value of the HEAD object ID by git repository
    static org.eclipse.core.resources.IProject[]
    getProjectsInRepository(org.eclipse.jgit.lib.Repository repository)
    Determines projects associated with the given repository.
    static Optional<org.eclipse.jgit.lib.Ref>
    getRefByBranchName(String branchName, org.eclipse.jgit.lib.Repository repository)
    Tries to find Ref associated with symbolic branch name
    static boolean
    Checks whether the branch name is a local branch reference
    static boolean
    isBranchRef(org.eclipse.jgit.lib.Ref ref)
    Checks whether the Ref is a local branch reference
    static boolean
    isDetachedHead(org.eclipse.jgit.lib.Repository repository)
    Checks if given repository is in the 'detached HEAD' state.
    static boolean
    Checks whether the branch name is a remote tracking branch reference
    static boolean
    isTrackingBranchRef(org.eclipse.jgit.lib.Ref ref)
    Checks whether the Ref is a remote tracking branch reference
    static void
    runGitAddCommand(org.eclipse.core.resources.IProject project, Collection<org.eclipse.core.runtime.IPath> absolutePaths)
    Runs Git add command for the files associated with the given absolute paths if the given project in the Git repository.
    static void
    runGitAddCommand(org.eclipse.jgit.lib.Repository repository, Collection<org.eclipse.core.runtime.IPath> absolutePaths)
    Runs Git add command for the given repository and files associated with the given absolute paths.
    static void
    runGitRmCommand(org.eclipse.core.resources.IProject project, Collection<org.eclipse.core.runtime.IPath> absolutePaths, boolean cached)
    Runs Git rm command for the files associated with the given absolute paths if the given project in the Git repository.
    static void
    runGitRmCommand(org.eclipse.jgit.lib.Repository repository, Collection<org.eclipse.core.runtime.IPath> absolutePaths, boolean cached)
    Runs Git rm command for the given repository and files associated with the given absolute paths.
    static String
    toBranchName(org.eclipse.jgit.lib.Ref ref)
    Gets the branch name by Ref
    static String
    toBranchName(org.eclipse.jgit.lib.Ref ref, boolean isShort)
    Gets the branch name by Ref
    static String
    toShortBranchName(String fullBranchName)
    Gets the short branch name by full branch name

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • getGitRepository

      public static org.eclipse.jgit.lib.Repository getGitRepository(org.eclipse.core.resources.IResource resource)
      Determines the Git repository containing the given resource. Should not close the repository after work with it was finished.
      Parameters:
      resource - the resource to get the Git repository for, cannot be null
      Returns:
      the associated with the given resource Git repository or null if no repository associates with the given resource
    • getGitRepository

      public static org.eclipse.jgit.lib.Repository getGitRepository(org.eclipse.core.runtime.IPath path)
      Determines the Git repository containing the given IPath. Should not close the repository after work with it was finished.
      Parameters:
      path - the path to get the Git repository for, cannot be null
      Returns:
      the associated with the given path Git repository or null if no repository associates with the given path
    • getProjectsInRepository

      public static org.eclipse.core.resources.IProject[] getProjectsInRepository(org.eclipse.jgit.lib.Repository repository)
      Determines projects associated with the given repository.
      Parameters:
      repository - the Git repository to lookup projects in, cannot be null
      Returns:
      the projects, associated with the given repository, never null
    • runGitAddCommand

      public static void runGitAddCommand(org.eclipse.jgit.lib.Repository repository, Collection<org.eclipse.core.runtime.IPath> absolutePaths) throws org.eclipse.core.runtime.CoreException
      Runs Git add command for the given repository and files associated with the given absolute paths.
      Parameters:
      repository - the given Git repository, can not be null
      absolutePaths - the given absolute paths to files, can not be null
      Throws:
      org.eclipse.core.runtime.CoreException - if an error occurred while calling Git add command
    • runGitAddCommand

      public static void runGitAddCommand(org.eclipse.core.resources.IProject project, Collection<org.eclipse.core.runtime.IPath> absolutePaths) throws org.eclipse.core.runtime.CoreException
      Runs Git add command for the files associated with the given absolute paths if the given project in the Git repository.
      Parameters:
      project - the project the target files from, can not be null
      absolutePaths - the given absolute paths to files, can not be null
      Throws:
      org.eclipse.core.runtime.CoreException - if an error occurred while finding Git repo or calling Git add command
    • runGitRmCommand

      public static void runGitRmCommand(org.eclipse.jgit.lib.Repository repository, Collection<org.eclipse.core.runtime.IPath> absolutePaths, boolean cached) throws org.eclipse.core.runtime.CoreException
      Runs Git rm command for the given repository and files associated with the given absolute paths.
      Parameters:
      repository - the given Git repository, can not be null
      absolutePaths - the given absolute paths to files, can not be null
      cached - true if files should only be removed from index, false if files should also be deleted from the working directory
      Throws:
      org.eclipse.core.runtime.CoreException - if an error occurred while calling Git rm command
    • runGitRmCommand

      public static void runGitRmCommand(org.eclipse.core.resources.IProject project, Collection<org.eclipse.core.runtime.IPath> absolutePaths, boolean cached) throws org.eclipse.core.runtime.CoreException
      Runs Git rm command for the files associated with the given absolute paths if the given project in the Git repository.
      Parameters:
      project - the project the target files from, can not be null
      absolutePaths - the given absolute paths to files, can not be null
      cached - true if files should only be removed from index, false if files should also be deleted from the working directory
      Throws:
      org.eclipse.core.runtime.CoreException - if an error occurred while finding Git repo or calling Git rm command
    • addFilesToGitIndex

      public static void addFilesToGitIndex(org.eclipse.core.resources.IProject project, Collection<org.eclipse.core.runtime.IPath> oldAbsolutePaths, Collection<org.eclipse.core.runtime.IPath> newAbsolutePaths, boolean cached) throws org.eclipse.core.runtime.CoreException
      Adds the files associated with the given new and old absolute paths to the Git index. Runs Git add command for the new paths and Git rm command for the old paths.
      It is important that the collection of old and new paths are not intersecting.
      Parameters:
      project - the project the target files from, can not be null
      oldAbsolutePaths - the old absolute paths, can not be null
      newAbsolutePaths - the new absolute paths, can not be null
      cached - true if old files should only be removed from index, false if old files should also be deleted from the working directory
      Throws:
      org.eclipse.core.runtime.CoreException - if an error occurred while finding Git repo or adding files to index
    • toBranchName

      public static String toBranchName(org.eclipse.jgit.lib.Ref ref, boolean isShort)
      Gets the branch name by Ref
      Parameters:
      ref - the Ref, cannot be null
      isShort - true if branch name should return w/o refs/heads/ or refs/remotes/ prefix
      Returns:
      the branch name, never null
    • toBranchName

      public static String toBranchName(org.eclipse.jgit.lib.Ref ref)
      Gets the branch name by Ref
      Parameters:
      ref - the Ref, cannot be null
      Returns:
      the branch name, never null
    • getHeadId

      public static Optional<org.eclipse.jgit.lib.ObjectId> getHeadId(org.eclipse.jgit.lib.Repository repository) throws IOException
      Returns optional value of the HEAD object ID by git repository
      Parameters:
      repository - the repository, cannot be null
      Returns:
      optional value of the HEAD object ID, cannot be null, can be Optional.empty()
      Throws:
      IOException
    • getRefByBranchName

      public static Optional<org.eclipse.jgit.lib.Ref> getRefByBranchName(String branchName, org.eclipse.jgit.lib.Repository repository)
      Tries to find Ref associated with symbolic branch name
      Parameters:
      branchName - the branch name, cannot be null, cannot be empty
      repository - the repository reference
      Returns:
      Optional of the Ref, never null, can be empty optional
    • toShortBranchName

      public static String toShortBranchName(String fullBranchName)
      Gets the short branch name by full branch name
      Parameters:
      fullBranchName - the full branch name, cannot be null
      Returns:
      the short branch name, never null
    • isBranchRef

      public static boolean isBranchRef(org.eclipse.jgit.lib.Ref ref)
      Checks whether the Ref is a local branch reference
      Parameters:
      ref - the Ref, cannot be null
      Returns:
      true if the ref is a local branch reference
    • isBranchRef

      public static boolean isBranchRef(String name)
      Checks whether the branch name is a local branch reference
      Parameters:
      name - the branch name, cannot be null
      Returns:
      true if the ref is a local branch reference
    • isTrackingBranchRef

      public static boolean isTrackingBranchRef(org.eclipse.jgit.lib.Ref ref)
      Checks whether the Ref is a remote tracking branch reference
      Parameters:
      ref - the Ref, cannot be null
      Returns:
      true if the ref is a remote tracking branch reference
    • isTrackingBranchRef

      public static boolean isTrackingBranchRef(String name)
      Checks whether the branch name is a remote tracking branch reference
      Parameters:
      name - the branch name, cannot be null
      Returns:
      true if the ref is a remote tracking branch reference
    • isDetachedHead

      public static boolean isDetachedHead(org.eclipse.jgit.lib.Repository repository)
      Checks if given repository is in the 'detached HEAD' state.
      Parameters:
      repository - the repository to check
      Returns:
      true if the repository is in the 'detached HEAD' state, false if it's not or an error occurred
      Since:
      3.2