Class GitSCM

All Implemented Interfaces:
ExtensionPoint, Describable<SCM>, Serializable

public class GitSCM extends GitSCMBackwardCompatibility
Git SCM.
Author:
Nigel Magnay, Andrew Bayer, Nicolas Deloof, Kohsuke Kawaguchi ... and many others
See Also:
  • Field Details

    • ALLOW_LOCAL_CHECKOUT

      public static boolean ALLOW_LOCAL_CHECKOUT
    • gitTool

      @CheckForNull public String gitTool
    • GIT_BRANCH

      public static final String GIT_BRANCH
      See Also:
    • GIT_LOCAL_BRANCH

      public static final String GIT_LOCAL_BRANCH
      See Also:
    • GIT_CHECKOUT_DIR

      public static final String GIT_CHECKOUT_DIR
      See Also:
    • GIT_COMMIT

      public static final String GIT_COMMIT
      See Also:
    • GIT_PREVIOUS_COMMIT

      public static final String GIT_PREVIOUS_COMMIT
      See Also:
    • GIT_PREVIOUS_SUCCESSFUL_COMMIT

      public static final String GIT_PREVIOUS_SUCCESSFUL_COMMIT
      See Also:
    • GIT_URL

      public static final String GIT_URL
      See Also:
    • GIT_REF

      public static final Pattern GIT_REF
    • VERBOSE

      public static boolean VERBOSE
      Set to true to enable more logging to build's TaskListener. Used by various classes in this package.
    • MAX_CHANGELOG

      public static final int MAX_CHANGELOG
      To avoid pointlessly large changelog, we'll limit the number of changes up to this.
  • Constructor Details

  • Method Details

    • getSubmoduleCfg

      @Deprecated public Collection<SubmoduleConfig> getSubmoduleCfg()
      Deprecated.
    • setSubmoduleCfg

      @DataBoundSetter public void setSubmoduleCfg(Collection<SubmoduleConfig> submoduleCfg)
    • createRepoList

      public static List<UserRemoteConfig> createRepoList(String url, String credentialsId)
    • getExtensions

      All the configured extensions attached to this GitSCM. Going forward this is primarily how we'll support esoteric use cases.
      Since:
      2.0
    • readResolve

      public Object readResolve() throws IOException, hudson.plugins.git.GitException
      Throws:
      IOException
      hudson.plugins.git.GitException
    • getBrowser

      public GitRepositoryBrowser getBrowser()
      Overrides:
      getBrowser in class SCM
    • setBrowser

      public void setBrowser(GitRepositoryBrowser browser)
    • guessBrowser

      public RepositoryBrowser<?> guessBrowser()
      Overrides:
      guessBrowser in class SCM
    • isCreateAccountBasedOnEmail

      public boolean isCreateAccountBasedOnEmail()
    • isUseExistingAccountWithSameEmail

      public boolean isUseExistingAccountWithSameEmail()
    • isHideCredentials

      public boolean isHideCredentials()
    • isAllowSecondFetch

      public boolean isAllowSecondFetch()
    • isDisableGitToolChooser

      public boolean isDisableGitToolChooser()
    • isAddGitTagAction

      public boolean isAddGitTagAction()
    • getBuildChooser

      public BuildChooser getBuildChooser()
    • setBuildChooser

      public void setBuildChooser(BuildChooser buildChooser) throws IOException
      Throws:
      IOException
    • getParamLocalBranch

      @Deprecated public String getParamLocalBranch(Run<?,?> build) throws IOException, InterruptedException
      Deprecated.
      Throws:
      IOException
      InterruptedException
    • getParamLocalBranch

      public String getParamLocalBranch(Run<?,?> build, TaskListener listener) throws IOException, InterruptedException
      Gets the parameter-expanded effective value in the context of the current build.
      Parameters:
      build - run whose local branch name is returned
      listener - build log
      Returns:
      parameter-expanded local branch name in build.
      Throws:
      IOException - on input or output error
      InterruptedException - when interrupted
    • getParamExpandedRepos

      @Deprecated public List<org.eclipse.jgit.transport.RemoteConfig> getParamExpandedRepos(Run<?,?> build) throws hudson.plugins.git.GitException, IOException, InterruptedException
      Deprecated.
      Throws:
      hudson.plugins.git.GitException
      IOException
      InterruptedException
    • getParamExpandedRepos

      public List<org.eclipse.jgit.transport.RemoteConfig> getParamExpandedRepos(Run<?,?> build, TaskListener listener) throws hudson.plugins.git.GitException, IOException, InterruptedException
      Expand parameters in remoteRepositories with the parameter values provided in the given build and return them.
      Parameters:
      build - run whose local branch name is returned
      listener - build log
      Returns:
      can be empty but never null.
      Throws:
      IOException - on input or output error
      InterruptedException - when interrupted
      hudson.plugins.git.GitException
    • getParamExpandedRepo

      public org.eclipse.jgit.transport.RemoteConfig getParamExpandedRepo(EnvVars env, org.eclipse.jgit.transport.RemoteConfig remoteRepository) throws hudson.plugins.git.GitException
      Expand Parameters in the supplied remote repository with the parameter values provided in the given environment variables
      Parameters:
      env - Environment variables with parameter values
      remoteRepository - Remote repository with parameters
      Returns:
      remote repository with expanded parameters
      Throws:
      hudson.plugins.git.GitException
    • getRepositoryByName

      public org.eclipse.jgit.transport.RemoteConfig getRepositoryByName(String repoName)
    • getUserRemoteConfigs

      @Exported public List<UserRemoteConfig> getUserRemoteConfigs()
    • getRepositories

      public List<org.eclipse.jgit.transport.RemoteConfig> getRepositories()
    • deriveLocalBranchName

      public String deriveLocalBranchName(String remoteBranchName)
      Derives a local branch name from the remote branch name by removing the name of the remote from the remote branch name.

      Ex. origin/master becomes master

      Cycles through the list of user remotes looking for a match allowing user to configure an alternate (not origin) name for the remote.

      Parameters:
      remoteBranchName - branch name whose remote repository name will be removed
      Returns:
      a local branch name derived by stripping the remote repository name from the remoteBranchName parameter. If a matching remote is not found, the original remoteBranchName will be returned.
    • getGitTool

      @CheckForNull public String getGitTool()
    • getParameterString

      @NonNull public static String getParameterString(@CheckForNull String original, @NonNull EnvVars env)
    • calcRevisionsFromBuild

      public SCMRevisionState calcRevisionsFromBuild(Run<?,?> abstractBuild, FilePath workspace, Launcher launcher, TaskListener taskListener) throws IOException, InterruptedException
      Overrides:
      calcRevisionsFromBuild in class SCM
      Throws:
      IOException
      InterruptedException
    • requiresWorkspaceForPolling

      public boolean requiresWorkspaceForPolling()
      Overrides:
      requiresWorkspaceForPolling in class SCM
    • compareRemoteRevisionWith

      public PollingResult compareRemoteRevisionWith(Job<?,?> project, Launcher launcher, FilePath workspace, TaskListener listener, SCMRevisionState baseline) throws IOException, InterruptedException
      Overrides:
      compareRemoteRevisionWith in class SCM
      Throws:
      IOException
      InterruptedException
    • createClient

      @NonNull public org.jenkinsci.plugins.gitclient.GitClient createClient(TaskListener listener, EnvVars environment, @NonNull Run<?,?> build, FilePath workspace) throws hudson.plugins.git.GitException, IOException, InterruptedException
      Allows Builders and Publishers to access a configured GitClient object to perform additional git operations.
      Parameters:
      listener - build log
      environment - environment variables to be used
      build - run context for the returned GitClient
      workspace - client workspace
      Returns:
      git client for additional git operations
      Throws:
      IOException - on input or output error
      InterruptedException - when interrupted
      hudson.plugins.git.GitException
    • createClient

      @NonNull public org.jenkinsci.plugins.gitclient.GitClient createClient(TaskListener listener, EnvVars environment, @NonNull Run<?,?> build, FilePath workspace, org.jenkinsci.plugins.gitclient.UnsupportedCommand postBuildUnsupportedCommand) throws hudson.plugins.git.GitException, IOException, InterruptedException
      Allows Publisher and other post build actions to access a configured GitClient. The post build action can use the postBuildUnsupportedCommand argument to control the selection of a git tool by GitToolChooser.
      Parameters:
      listener - build log
      environment - environment variables to be used
      build - run context for the returned GitClient
      workspace - client workspace
      postBuildUnsupportedCommand - passed by caller to control choice of git tool by GitTooChooser
      Returns:
      git client for additional git operations
      Throws:
      IOException - on input or output error
      InterruptedException - when interrupted
      hudson.plugins.git.GitException
    • resolveGitTool

      @CheckForNull public hudson.plugins.git.GitTool resolveGitTool(TaskListener listener)
    • getGitExe

      public String getGitExe(Node builtOn, TaskListener listener)
    • getGitExe

      public String getGitExe(Node builtOn, EnvVars env, TaskListener listener)
      Exposing so that we can get this from GitPublisher.
      Parameters:
      builtOn - node where build was performed
      env - environment variables used in the build
      listener - build log
      Returns:
      git exe for builtOn node, often "Default" or "jgit"
    • getGitTool

      public hudson.plugins.git.GitTool getGitTool(Node builtOn, EnvVars env, TaskListener listener)
    • checkout

      public void checkout(Run<?,?> build, Launcher launcher, FilePath workspace, TaskListener listener, File changelogFile, SCMRevisionState baseline) throws IOException, InterruptedException
      Overrides:
      checkout in class SCM
      Throws:
      IOException
      InterruptedException
    • buildEnvVars

      @Deprecated public void buildEnvVars(AbstractBuild<?,?> build, Map<String,String> env)
      Deprecated.
      Overrides:
      buildEnvVars in class SCM
    • buildEnvironment

      public void buildEnvironment(Run<?,?> build, Map<String,String> env)
      Overrides:
      buildEnvironment in class SCM
    • createChangeLogParser

      public ChangeLogParser createChangeLogParser()
      Specified by:
      createChangeLogParser in class SCM
    • isDoGenerateSubmoduleConfigurations

      @Deprecated public boolean isDoGenerateSubmoduleConfigurations()
      Deprecated.
    • getBranches

      @Exported public List<BranchSpec> getBranches()
    • getKey

      public String getKey()
      Overrides:
      getKey in class SCM
    • getMergeOptions

      @Exported @Deprecated public PreBuildMergeOptions getMergeOptions() throws Descriptor.FormException
      Deprecated.
      Returns:
      pre-build merge options
      Throws:
      Descriptor.FormException - on form error
    • getBuildData

      @Deprecated public BuildData getBuildData(Run build, boolean clone)
      Deprecated.
      Parameters:
      build - run whose build data is returned
      clone - true if returned build data should be copied rather than referenced
      Returns:
      build data for build run
    • copyBuildData

      public BuildData copyBuildData(Run build)
      Like getBuildData(Run), but copy the data into a new object, which is used as the first step for updating the data for the next build.
      Parameters:
      build - run whose BuildData is returned
      Returns:
      copy of build data for build
    • getBuildData

      @CheckForNull public BuildData getBuildData(Run build)
      Find the build log (BuildData) recorded with the last build that completed. BuildData may not be recorded if an exception occurs in the plugin logic.
      Parameters:
      build - run whose build data is returned
      Returns:
      the last recorded build data
    • workingDirectory

      protected FilePath workingDirectory(Job<?,?> context, FilePath workspace, EnvVars environment, TaskListener listener) throws hudson.plugins.git.GitException, IOException, InterruptedException
      Given the workspace, gets the working directory, which will be the workspace if no relative target dir is specified. Otherwise, it'll be "workspace/relativeTargetDir".
      Parameters:
      context - job context for working directory
      workspace - initial FilePath of job workspace
      environment - environment variables used in job context
      listener - build log
      Returns:
      working directory or null if workspace is null
      Throws:
      IOException - on input or output error
      InterruptedException - when interrupted
      hudson.plugins.git.GitException
    • setDoGenerateSubmoduleConfigurations

      @DataBoundSetter public void setDoGenerateSubmoduleConfigurations(boolean ignoredValue)
      Data bound setter for doGenerateSubmoduleConfigurations that intentionally ignores the value passed by the caller. Submodule configuration generation was untested and unlikely to work prior to git plugin 4.6.0. It was removed from git plugin 4.6.0 to improve the experience for Pipeline Syntax users.
      Parameters:
      ignoredValue - ignored because submodule configuration generation is no longer supported
    • getDoGenerateSubmoduleConfigurations

      @Deprecated public boolean getDoGenerateSubmoduleConfigurations()
      Deprecated.
      Returns false, the constant value of doGenerateSubmoduleConfigurations.
      Returns:
      false, the constant value of doGenerateSubmoduleConfigurations.
    • onLoaded

      @Initializer(after=PLUGINS_STARTED) public static void onLoaded()
    • configureXtream

      @Initializer(before=JOB_LOADED) public static void configureXtream()