Class GitUtils

java.lang.Object
hudson.plugins.git.util.GitUtils
All Implemented Interfaces:
Serializable

public class GitUtils extends Object implements Serializable
See Also:
  • Constructor Details

    • GitUtils

      public GitUtils(@NonNull TaskListener listener, @NonNull org.jenkinsci.plugins.gitclient.GitClient git)
  • Method Details

    • resolveGitTool

      @CheckForNull public static hudson.plugins.git.GitTool resolveGitTool(@CheckForNull String gitTool, @CheckForNull Node builtOn, @CheckForNull EnvVars env, @NonNull TaskListener listener)
      Resolves Git Tool by name.
      Parameters:
      gitTool - Tool name. If null, default tool will be used (if exists)
      builtOn - Node for which the tool should be resolved Can be Jenkins.getInstance() when running on controller
      env - Additional environment variables
      listener - Event listener
      Returns:
      Tool installation or null if it cannot be resolved
      Since:
      4.0.0
    • resolveGitTool

      @CheckForNull public static hudson.plugins.git.GitTool resolveGitTool(@CheckForNull String gitTool, @NonNull TaskListener listener)
      Resolves Git Tool by name in a node-agnostic way. Use resolveGitTool(String, Node, EnvVars, TaskListener) when the node is known
      Parameters:
      gitTool - Tool name. If null, default tool will be used (if exists)
      listener - Event listener
      Returns:
      Tool installation or null if it cannot be resolved
      Since:
      4.0.0
    • workspaceToNode

      public static Node workspaceToNode(FilePath workspace)
    • getAllBranchRevisions

      public Collection<hudson.plugins.git.Revision> getAllBranchRevisions() throws hudson.plugins.git.GitException, IOException, InterruptedException
      Return a list of "Revisions" - where a revision knows about all the branch names that refer to a SHA1.
      Returns:
      list of revisions
      Throws:
      IOException - on input or output error
      hudson.plugins.git.GitException - on git error
      InterruptedException - when interrupted
    • getRevisionContainingBranch

      public hudson.plugins.git.Revision getRevisionContainingBranch(String branchName) throws hudson.plugins.git.GitException, IOException, InterruptedException
      Return the revision containing the branch name.
      Parameters:
      branchName - name of branch to be searched
      Returns:
      revision containing branchName
      Throws:
      IOException - on input or output error
      hudson.plugins.git.GitException - on git error
      InterruptedException - when interrupted
    • getRevisionForSHA1

      public hudson.plugins.git.Revision getRevisionForSHA1(org.eclipse.jgit.lib.ObjectId sha1) throws hudson.plugins.git.GitException, IOException, InterruptedException
      Throws:
      hudson.plugins.git.GitException
      IOException
      InterruptedException
    • sortBranchesForRevision

      public hudson.plugins.git.Revision sortBranchesForRevision(hudson.plugins.git.Revision revision, List<BranchSpec> branchOrder)
    • sortBranchesForRevision

      public hudson.plugins.git.Revision sortBranchesForRevision(hudson.plugins.git.Revision revision, List<BranchSpec> branchOrder, EnvVars env)
    • filterTipBranches

      @WithBridgeMethods(java.util.Collection.class) public List<hudson.plugins.git.Revision> filterTipBranches(Collection<hudson.plugins.git.Revision> revisions) throws hudson.plugins.git.GitException, InterruptedException
      Return a list of 'tip' branches (I.E. branches that aren't included entirely within another branch).
      Parameters:
      revisions - branches to be included in the search for tip branches
      Returns:
      filtered tip branches
      Throws:
      InterruptedException - when interrupted
      hudson.plugins.git.GitException
    • getPollEnvironment

      public static EnvVars getPollEnvironment(AbstractProject p, FilePath ws, Launcher launcher, TaskListener listener) throws IOException, InterruptedException
      Throws:
      IOException
      InterruptedException
    • getPollEnvironment

      public static EnvVars getPollEnvironment(AbstractProject p, FilePath ws, Launcher launcher, TaskListener listener, boolean reuseLastBuildEnv) throws IOException, InterruptedException
      An attempt to generate at least semi-useful EnvVars for polling calls, based on previous build. Cribbed from various places.
      Parameters:
      p - abstract project to be considered
      ws - workspace to be considered
      launcher - launcher to use for calls to nodes
      listener - build log
      reuseLastBuildEnv - true if last build environment should be considered
      Returns:
      environment variables from previous build to be used for polling
      Throws:
      IOException - on input or output error
      InterruptedException - when interrupted
    • fixupNames

      public static String[] fixupNames(String[] names, String[] urls)