Package org.craftercms.deployer.utils
Class GitUtils
- java.lang.Object
-
- org.craftercms.commons.git.utils.GitUtils
-
- org.craftercms.deployer.utils.GitUtils
-
public abstract class GitUtils extends org.craftercms.commons.git.utils.GitUtils
Utility methods for Git operations.- Author:
- avasquez
-
-
Field Summary
Fields Modifier and Type Field Description static String
BIG_FILE_THRESHOLD_CONFIG_PARAM
static String
BIG_FILE_THRESHOLD_DEFAULT
static String
COMPRESSION_CONFIG_PARAM
static int
COMPRESSION_DEFAULT
static String
CORE_CONFIG_SECTION
static String
FILE_MODE_CONFIG_PARAM
static boolean
FILE_MODE_DEFAULT
static String
GIT_FOLDER_NAME
static String
GIT_LOCK_NAME
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
cleanup(String repoPath)
Executes a git gc.static org.eclipse.jgit.api.Git
cloneRemoteRepository(String remoteName, String remoteUrl, String branch, org.craftercms.commons.git.auth.GitAuthenticationConfigurator authConfigurator, File localFolder, String bigFileThreshold, Integer compression, Boolean fileMode)
Clones a remote repository into a specific local folder.static void
discardAllChanges(org.eclipse.jgit.api.Git git)
Executes a git reset to discard all uncommitted changesstatic org.eclipse.jgit.api.Git
openRepository(File localRepositoryFolder)
Opens the Git repository at the specified location.static org.eclipse.jgit.api.PullResult
pull(org.eclipse.jgit.api.Git git, String remoteName, String remoteUrl, String branch, org.eclipse.jgit.merge.MergeStrategy mergeStrategy, org.craftercms.commons.git.auth.GitAuthenticationConfigurator authConfigurator)
Execute a Git pull.static Iterable<org.eclipse.jgit.transport.PushResult>
push(org.eclipse.jgit.api.Git git, String remote, boolean pushAll, String localBranch, String remoteBranch, org.craftercms.commons.git.auth.GitAuthenticationConfigurator authConfigurator, boolean force)
Executes a git push.static void
unlock(String repoPath)
-
-
-
Field Detail
-
GIT_FOLDER_NAME
public static final String GIT_FOLDER_NAME
- See Also:
- Constant Field Values
-
GIT_LOCK_NAME
public static final String GIT_LOCK_NAME
- See Also:
- Constant Field Values
-
CORE_CONFIG_SECTION
public static final String CORE_CONFIG_SECTION
- See Also:
- Constant Field Values
-
BIG_FILE_THRESHOLD_CONFIG_PARAM
public static final String BIG_FILE_THRESHOLD_CONFIG_PARAM
- See Also:
- Constant Field Values
-
COMPRESSION_CONFIG_PARAM
public static final String COMPRESSION_CONFIG_PARAM
- See Also:
- Constant Field Values
-
FILE_MODE_CONFIG_PARAM
public static final String FILE_MODE_CONFIG_PARAM
- See Also:
- Constant Field Values
-
BIG_FILE_THRESHOLD_DEFAULT
public static final String BIG_FILE_THRESHOLD_DEFAULT
- See Also:
- Constant Field Values
-
COMPRESSION_DEFAULT
public static final int COMPRESSION_DEFAULT
- See Also:
- Constant Field Values
-
FILE_MODE_DEFAULT
public static final boolean FILE_MODE_DEFAULT
- See Also:
- Constant Field Values
-
-
Method Detail
-
openRepository
public static org.eclipse.jgit.api.Git openRepository(File localRepositoryFolder) throws IOException
Opens the Git repository at the specified location.- Parameters:
localRepositoryFolder
- the folder where the Git repository is- Returns:
- the Git instance used to handle the repository
- Throws:
IOException
- if an error occurs
-
cloneRemoteRepository
public static org.eclipse.jgit.api.Git cloneRemoteRepository(String remoteName, String remoteUrl, String branch, org.craftercms.commons.git.auth.GitAuthenticationConfigurator authConfigurator, File localFolder, String bigFileThreshold, Integer compression, Boolean fileMode) throws org.eclipse.jgit.api.errors.GitAPIException, IOException
Clones a remote repository into a specific local folder.- Parameters:
remoteName
- the name of the remoteremoteUrl
- the URL of the remote. This should be a legal Git URL.branch
- the branch which should be clonedauthConfigurator
- theGitAuthenticationConfigurator
class used to configure the authentication with the remote repositorylocalFolder
- the local folder into which the remote repository should be clonedbigFileThreshold
- the value of the Gitcore.bigFileThreshold
config propertycompression
- the value of the Gitcore.compression
config propertyfileMode
- the value of the Gitcore.fileMode
config property- Returns:
- the Git instance used to handle the cloned repository
- Throws:
org.eclipse.jgit.api.errors.GitAPIException
- if a Git related error occursIOException
- if an IO error occurs
-
pull
public static org.eclipse.jgit.api.PullResult pull(org.eclipse.jgit.api.Git git, String remoteName, String remoteUrl, String branch, org.eclipse.jgit.merge.MergeStrategy mergeStrategy, org.craftercms.commons.git.auth.GitAuthenticationConfigurator authConfigurator) throws org.eclipse.jgit.api.errors.GitAPIException, URISyntaxException
Execute a Git pull.- Parameters:
git
- the Git instance used to handle the repositoryremoteName
- the name of the remote where to pull fromremoteUrl
- the URL of the remote (remote will be set to the URL)branch
- the branch to pullmergeStrategy
- the merge strategy to useauthConfigurator
- theGitAuthenticationConfigurator
class used to configure the authentication with the remote repository- Returns:
- the result of the pull
- Throws:
org.eclipse.jgit.api.errors.GitAPIException
- if a Git related error occursURISyntaxException
- if the remote URL is invalid
-
push
public static Iterable<org.eclipse.jgit.transport.PushResult> push(org.eclipse.jgit.api.Git git, String remote, boolean pushAll, String localBranch, String remoteBranch, org.craftercms.commons.git.auth.GitAuthenticationConfigurator authConfigurator, boolean force) throws org.eclipse.jgit.api.errors.GitAPIException
Executes a git push.- Parameters:
git
- the Git instance used to handle the repositoryremote
- remote name or URLpushAll
- if the push should push all local branchesremoteBranch
- the remote remoteBranch being pushed toauthConfigurator
- theGitAuthenticationConfigurator
class used to configure the authentication with the remote repositoryforce
- sets the force preference for the push- Returns:
- the result of the push
- Throws:
org.eclipse.jgit.api.errors.GitAPIException
- if a Git related error occurs
-
cleanup
public static void cleanup(String repoPath) throws org.eclipse.jgit.api.errors.GitAPIException, IOException
Executes a git gc.- Parameters:
repoPath
- full path of the repository- Throws:
org.eclipse.jgit.api.errors.GitAPIException
- if there is an error running the commandIOException
- if there is an error opening the repository
-
discardAllChanges
public static void discardAllChanges(org.eclipse.jgit.api.Git git) throws org.eclipse.jgit.api.errors.GitAPIException
Executes a git reset to discard all uncommitted changes- Parameters:
git
- the git repository- Throws:
org.eclipse.jgit.api.errors.GitAPIException
- if there is an error performing the reset
-
unlock
public static void unlock(String repoPath) throws IOException
- Throws:
IOException
-
-