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 TypeMethodDescriptionvoid
Add origin url to the git repository in workingDirectorycreateLocalCommandBuilder
(String... commands) createRemoteCommandBuilder
(GitRepositoryAccessData gitRepositoryAccessData, @Nullable Path sshIdentityFile, String... commands) createRemoteCommandBuilder
(GitRepositoryAccessData gitRepositoryAccessData, String... commands) createRemoteCommandBuilderForSubmodules
(GitRepositoryAccessData gitRepositoryAccessData, @Nullable Path sshIdentityFile, String... commands) @NotNull CommitContext
extractCommit
(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 String
getIdentityFileCmdSwitch
(Path identityFile) getPossibleBranchNameForCheckout
(File workingDirectory, String revision, String configuredBranchName) getRemoteRefs
(@NotNull GitRepositoryAccessData accessData) @NotNull List<TagAndRevision>
getRemoteTags
(@NotNull GitRepositoryAccessData accessData) @NotNull String
protected String
getSshCommand
(boolean proxied, @Nullable Path identityFile) boolean
isAncestor
(Path gitWorkspace, GitHash rev1, GitHash rev2) protected boolean
void
reportProxyError
(String message, Throwable exception) void
runCheckoutCommand
(@NotNull File workingDirectory, String revision, String configuredBranchName, boolean withLfs) void
runCheckoutCommandForBranchOrRevision
(@NotNull File workingDirectory, String destination, boolean disableLfs) void
runCloneCommand
(@NotNull File workingDirectory, @NotNull File cacheDirectory, @NotNull GitRepositoryAccessData accessData) int
runCommand
(@NotNull GitCommandBuilder commandBuilder, @NotNull File workingDirectory) int
runCommand
(@NotNull GitCommandBuilder commandBuilder, @NotNull File workingDirectory, @NotNull com.atlassian.bamboo.plugins.git.GitCommandProcessor.GitOutputHandler outputHandler) void
runFetchCommand
(@NotNull File workingDirectory, @NotNull GitRepositoryAccessData accessData, String refSpec, boolean useShallow, boolean fetchTagsByDefault) void
runInitCommand
(@NotNull File workingDirectory) Creates .git repository in a given directory.void
runLfsFetchCommand
(@NotNull GitRepositoryAccessData repositoryAccessData, @NotNull File workingDirectory, @NotNull GitRef resolvedRef, @NotNull HashAndSource hashAndSource) void
runLfsLogCommand
(File workingDirectory) void
runLfsPullCommand
(File workingDirectory) void
runLocalCloneCommand
(@NotNull File workingDirectory, @NotNull File cacheDirectory, @NotNull GitRepositoryAccessData accessData) void
runLocalFetchCommand
(@NotNull File workingDirectory, @NotNull GitRepositoryAccessData accessData) 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) void
runMergeCommand
(@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) void
runSubmoduleUpdateCommand
(@NotNull GitRepositoryAccessData gitRepositoryAccessData, @NotNull File workingDirectory, boolean useSubmodulesWithShallowClones) Updates Git submodules, initialising them if necessary, and ensures they are fully fetched if initially shallowvoid
Change origin url of the git repository in workingDirectory to an urlvoid
setOriginToLocalDirectory
(@NotNull File cacheDirectory, @NotNull File workingDirectory) Set origin url of the repository to cache directoryvoid
setSshCommand
(String sshCommand) validateAndPreprocessRepositoryUrl
(String repositoryUrl) Validates and preprocesses a repository URL to ensure it is correctly formatted for use.protected void
validateRepositoryAccessData
(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, @NotNull @NotNull File cacheDirectory, @NotNull @NotNull GitRepositoryAccessData accessData) throws RepositoryException - Throws:
RepositoryException
-
runLocalFetchCommand
public void runLocalFetchCommand(@NotNull @NotNull File workingDirectory, @NotNull @NotNull GitRepositoryAccessData accessData) 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, boolean useSubmodulesWithShallowClones) throws RepositoryException Updates Git submodules, initialising them if necessary, and ensures they are fully fetched if initially shallowIf the
useSubmodulesWithShallowClones
parameter is set tofalse
, this method will detect any submodules that have been previously checked out as shallow and subsequently "unshallow" them by fetching their complete history- Parameters:
gitRepositoryAccessData
- Access data for the Git repository, including authentication detailsworkingDirectory
- The working directory where the Git repository is locateduseSubmodulesWithShallowClones
- Indicates whether shallow clones should be used for submodules- Throws:
RepositoryException
- If there is an error during the operation
-
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) -
createRemoteCommandBuilderForSubmodules
public GitCommandBuilder createRemoteCommandBuilderForSubmodules(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:
reportProxyError
in 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
-