Package com.atlassian.bamboo.plugins.git
Class GitCommandProcessor
java.lang.Object
com.atlassian.bamboo.plugins.git.GitCommandProcessor
- All Implemented Interfaces:
ProxyErrorReceiver,Serializable
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionGitCommandProcessor(@NotNull String gitExecutable, @NotNull BuildLogger buildLogger, @Nullable String passwordToObfuscate, int commandTimeoutInMinutes, boolean maxVerboseOutput, @NotNull TrustedKeyHelper trustedKeyHelper) -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd origin url to the git repository in workingDirectorycreateLocalCommandBuilder(String... commands) createRemoteCommandBuilder(GitRepositoryAccessData gitRepositoryAccessData, @Nullable Path sshIdentityFile, String... commands) createRemoteCommandBuilder(GitRepositoryAccessData gitRepositoryAccessData, String... commands) @NotNull CommitContextextractCommit(File directory, String targetRevision) getBranchForSha(@NotNull File workingDirectory, String revision, String configuredBranch) getCurrentBranch(@NotNull File workingDirectory) getGitVersion(@NotNull File workingDirectory) Checks whether git exist in current system.protected @NotNull StringgetIdentityFileCmdSwitch(Path identityFile) getPossibleBranchNameForCheckout(File workingDirectory, String revision, String configuredBranchName) getRemoteRefs(@NotNull GitRepositoryAccessData accessData) @NotNull List<TagAndRevision>getRemoteTags(@NotNull GitRepositoryAccessData accessData) @NotNull Stringprotected StringgetSshCommand(boolean proxied, @Nullable Path identityFile) booleanisAncestor(Path gitWorkspace, GitHash rev1, GitHash rev2) protected booleanvoidreportProxyError(String message, Throwable exception) voidrunCheckoutCommand(@NotNull File workingDirectory, String revision, String configuredBranchName, boolean withLfs) voidrunCheckoutCommandForBranchOrRevision(@NotNull File workingDirectory, String destination, boolean disableLfs) voidrunCloneCommand(@NotNull File workingDirectory, @NotNull File cacheDirectory, @NotNull GitRepositoryAccessData accessData) intrunCommand(@NotNull GitCommandBuilder commandBuilder, @NotNull File workingDirectory) intrunCommand(@NotNull GitCommandBuilder commandBuilder, @NotNull File workingDirectory, @NotNull com.atlassian.bamboo.plugins.git.GitCommandProcessor.GitOutputHandler outputHandler) voidrunFetchCommand(@NotNull File workingDirectory, @NotNull GitRepositoryAccessData accessData, String refSpec, boolean useShallow, boolean fetchTagsByDefault) voidrunInitCommand(@NotNull File workingDirectory) Creates .git repository in a given directory.voidrunLfsFetchCommand(@NotNull GitRepositoryAccessData repositoryAccessData, @NotNull File workingDirectory, @NotNull GitRef resolvedRef, @NotNull HashAndSource hashAndSource) voidrunLfsLogCommand(File workingDirectory) voidrunLfsPullCommand(File workingDirectory) voidrunLocalCloneCommand(@NotNull File workingDirectory, File cacheDirectory) voidrunLocalFetchCommand(@NotNull File workingDirectory) runLogCommand(File cacheDirectory, @Nullable String lastVcsRevisionKey, String targetRevision, @NotNull Set<String> shallows, int maxCommits, @Nullable String path) runLogCommandXBranch(File cacheDirectory, @NotNull String branchA, String branchB, @NotNull Set<String> shallows, int maxCommits) voidrunMergeCommand(@NotNull GitCommandBuilder commandBuilder, @NotNull File workspaceDir) Returns true if there are modified files in the working directory or repository index after the mergerunStatusCommand(@NotNull File workingDirectory) voidrunSubmoduleUpdateCommand(@NotNull GitRepositoryAccessData gitRepositoryAccessData, @NotNull File workingDirectory) voidChange origin url of the git repository in workingDirectory to an urlvoidsetOriginToLocalDirectory(@NotNull File cacheDirectory, @NotNull File workingDirectory) Set origin url of the repository to cache directoryvoidsetSshCommand(String sshCommand) validateAndPreprocessRepositoryUrl(String repositoryUrl) Validates and preprocesses a repository URL to ensure it is correctly formatted for use.protected voidvalidateRepositoryAccessData(GitRepositoryAccessData gitRepositoryAccessData) Validates and preprocesses the repository URL within the providedGitRepositoryAccessData.
-
Field Details
-
SSH_IGNORE_HOST_KEY_OPTIONS
- See Also:
-
SSH_OPTIONS
- See Also:
-
SSH_DEFAULT
- See Also:
-
SSH_WIN
- See Also:
-
SSH_UNIX
- See Also:
-
-
Constructor Details
-
GitCommandProcessor
public GitCommandProcessor(@NotNull @NotNull String gitExecutable, @NotNull @NotNull BuildLogger buildLogger, @Nullable @Nullable String passwordToObfuscate, int commandTimeoutInMinutes, boolean maxVerboseOutput, @NotNull @NotNull TrustedKeyHelper trustedKeyHelper)
-
-
Method Details
-
isWindows
protected boolean isWindows() -
getSshCommand
-
getIdentityFileCmdSwitch
-
getGitVersion
Checks whether git exist in current system.- Parameters:
workingDirectory- specifies arbitrary directory.- Throws:
RepositoryException- when git wasn't found in current system.
-
runInitCommand
Creates .git repository in a given directory.- Parameters:
workingDirectory- - directory in which we want to create empty repository.- Throws:
RepositoryException- when init command fails
-
isAncestor
- Throws:
RepositoryException
-
runStatusCommand
public List<String> runStatusCommand(@NotNull @NotNull File workingDirectory) throws RepositoryException - Throws:
RepositoryException
-
runFetchCommand
public void runFetchCommand(@NotNull @NotNull File workingDirectory, @NotNull @NotNull GitRepositoryAccessData accessData, String refSpec, boolean useShallow, boolean fetchTagsByDefault) throws RepositoryException - Throws:
RepositoryException
-
runCloneCommand
public void runCloneCommand(@NotNull @NotNull File workingDirectory, @NotNull @NotNull File cacheDirectory, @NotNull @NotNull GitRepositoryAccessData accessData) throws RepositoryException - Throws:
RepositoryException
-
runLocalCloneCommand
public void runLocalCloneCommand(@NotNull @NotNull File workingDirectory, File cacheDirectory) throws RepositoryException - Throws:
RepositoryException
-
runLocalFetchCommand
public void runLocalFetchCommand(@NotNull @NotNull File workingDirectory) throws RepositoryException - Throws:
RepositoryException
-
runCheckoutCommand
public void runCheckoutCommand(@NotNull @NotNull File workingDirectory, String revision, String configuredBranchName, boolean withLfs) throws RepositoryException - Throws:
RepositoryException
-
runCheckoutCommandForBranchOrRevision
public void runCheckoutCommandForBranchOrRevision(@NotNull @NotNull File workingDirectory, String destination, boolean disableLfs) throws RepositoryException - Throws:
RepositoryException
-
runLfsLogCommand
- Throws:
RepositoryException
-
runSubmoduleUpdateCommand
public void runSubmoduleUpdateCommand(@NotNull @NotNull GitRepositoryAccessData gitRepositoryAccessData, @NotNull @NotNull File workingDirectory) throws RepositoryException - Throws:
RepositoryException
-
getShaOf
@NotNull public @NotNull String getShaOf(@NotNull @NotNull File workingDirectory, @NotNull @NotNull String refOrBranchOrHash) throws RepositoryException - Throws:
RepositoryException
-
getShaOf
public Optional<GitHash> getShaOf(@NotNull @NotNull Path workingDirectory, @NotNull @NotNull String refOrBranchOrHash) throws RepositoryException - Throws:
RepositoryException
-
getCurrentBranch
- Throws:
RepositoryException
-
getShaOf
public Optional<GitHash> getShaOf(@NotNull @NotNull File workingDirectory, @NotNull @NotNull String refOrBranchOrHash, @Nullable @Nullable String path) throws RepositoryException - Throws:
RepositoryException
-
getPossibleBranchNameForCheckout
public Pair<String,Boolean> getPossibleBranchNameForCheckout(File workingDirectory, String revision, String configuredBranchName) throws RepositoryException - Throws:
RepositoryException
-
getRemoteRefs
@NotNull public @NotNull com.google.common.collect.ImmutableMap<String,String> getRemoteRefs(@NotNull @NotNull GitRepositoryAccessData accessData) throws RepositoryException - Throws:
RepositoryException
-
getRemoteTags
@NotNull public @NotNull List<TagAndRevision> getRemoteTags(@NotNull @NotNull GitRepositoryAccessData accessData) throws RepositoryException - Throws:
RepositoryException
-
getBranchForSha
@NotNull public @NotNull Optional<String> getBranchForSha(@NotNull @NotNull File workingDirectory, String revision, String configuredBranch) throws RepositoryException - Throws:
RepositoryException
-
setOrigin
public void setOrigin(@NotNull @NotNull String originUrl, @NotNull @NotNull File workingDirectory) throws RepositoryException Change origin url of the git repository in workingDirectory to an url- Parameters:
originUrl-workingDirectory-- Throws:
RepositoryException
-
runLfsPullCommand
- Throws:
RepositoryException
-
runLfsFetchCommand
public void runLfsFetchCommand(@NotNull @NotNull GitRepositoryAccessData repositoryAccessData, @NotNull @NotNull File workingDirectory, @NotNull @NotNull GitRef resolvedRef, @NotNull @NotNull HashAndSource hashAndSource) throws RepositoryException - Throws:
RepositoryException
-
addOrigin
public void addOrigin(@NotNull @NotNull String originUrl, @NotNull @NotNull File workingDirectory) throws RepositoryException Add origin url to the git repository in workingDirectory- Parameters:
originUrl-workingDirectory-- Throws:
RepositoryException
-
setOriginToLocalDirectory
public void setOriginToLocalDirectory(@NotNull @NotNull File cacheDirectory, @NotNull @NotNull File workingDirectory) throws RepositoryException Set origin url of the repository to cache directory- Parameters:
cacheDirectory-workingDirectory-- Throws:
RepositoryException
-
createLocalCommandBuilder
-
createRemoteCommandBuilder
public GitCommandBuilder createRemoteCommandBuilder(GitRepositoryAccessData gitRepositoryAccessData, String... commands) throws RepositoryException - Throws:
RepositoryException
-
createRemoteCommandBuilder
public GitCommandBuilder createRemoteCommandBuilder(GitRepositoryAccessData gitRepositoryAccessData, @Nullable @Nullable Path sshIdentityFile, String... commands) -
validateRepositoryAccessData
protected void validateRepositoryAccessData(GitRepositoryAccessData gitRepositoryAccessData) throws RepositoryException Validates and preprocesses the repository URL within the providedGitRepositoryAccessData.- Parameters:
gitRepositoryAccessData- the data object containing the repository URL to be validated and preprocessed- Throws:
RepositoryException- if the URL is invalid
-
validateAndPreprocessRepositoryUrl
Validates and preprocesses a repository URL to ensure it is correctly formatted for use. The preprocessing steps include: - Checking that the URL not null or empty. - Trimming whitespace and replacing backslashes with their URL-encoded equivalents. - Converting SCP-like syntax (e.g., "user@host:path") to a standard SSH URL format. - Adding a default scheme ("ssh" or "file") if missing. - Converting Windows paths to the "file" scheme. - Validating the URL's scheme against a set of allowed schemes. - Ensuring the port number, if present, is within a valid range.- Parameters:
repositoryUrl- the repository URL to validate and preprocess.- Returns:
- the validated and possibly modified repository URL.
- Throws:
RepositoryException- if the URL is invalid or cannot be parsed.
-
reportProxyError
- Specified by:
reportProxyErrorin interfaceProxyErrorReceiver
-
runCommand
public int runCommand(@NotNull @NotNull GitCommandBuilder commandBuilder, @NotNull @NotNull File workingDirectory) throws RepositoryException - Throws:
RepositoryException
-
runCommand
public int runCommand(@NotNull @NotNull GitCommandBuilder commandBuilder, @NotNull @NotNull File workingDirectory, @NotNull @NotNull com.atlassian.bamboo.plugins.git.GitCommandProcessor.GitOutputHandler outputHandler) throws RepositoryException - Throws:
RepositoryException
-
runMergeCommand
public void runMergeCommand(@NotNull @NotNull GitCommandBuilder commandBuilder, @NotNull @NotNull File workspaceDir) throws RepositoryException Returns true if there are modified files in the working directory or repository index after the merge- Throws:
RepositoryException
-
extractCommit
@NotNull public @NotNull CommitContext extractCommit(File directory, String targetRevision) throws RepositoryException - Throws:
RepositoryException
-
runLogCommandXBranch
public Pair<List<CommitContext>,Integer> runLogCommandXBranch(File cacheDirectory, @NotNull @NotNull String branchA, String branchB, @NotNull @NotNull Set<String> shallows, int maxCommits) throws RepositoryException - Throws:
RepositoryException
-
runLogCommand
public Pair<List<CommitContext>,Integer> runLogCommand(File cacheDirectory, @Nullable @Nullable String lastVcsRevisionKey, String targetRevision, @NotNull @NotNull Set<String> shallows, int maxCommits, @Nullable @Nullable String path) throws RepositoryException - Throws:
RepositoryException
-
setSshCommand
-