Top Description Fields Constructors Methods
org.jabref.logic.git

public Class GitHandler

extends Object
Class Inheritance
Known Direct Subclasses
org.jabref.logic.git.SlrGitHandler
Imports
java.io.File, .IOException, java.net.URISyntaxException, java.nio.file.Files, .Path, java.util.Optional, org.jabref.logic.util.io.FileUtil, org.eclipse.jgit.api.Git, org.eclipse.jgit.api.RmCommand, org.eclipse.jgit.api.Status, org.eclipse.jgit.api.errors.GitAPIException, org.eclipse.jgit.lib.Ref, org.eclipse.jgit.merge.MergeStrategy, org.eclipse.jgit.transport.CredentialsProvider, org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider, org.slf4j.Logger, .LoggerFactory

This class handles the updating of the local and remote git repository that is located at the repository path This provides an easy-to-use interface to manage a git repository

Field Summary

Modifier and TypeField and Description
pack-priv final org.eclipse.jgit.transport.CredentialsProvider
pack-priv String
pack-priv String
pack-priv static final Logger
pack-priv final Path
pack-priv final File

Constructor Summary

AccessConstructor and Description
public
GitHandler(Path
The root of the initialized git repository
repositoryPath
)

Initialize the handler for the given repository

Method Summary

Modifier and TypeMethod and Description
public void
checkoutBranch(String
Name of the branch to check out
branchToCheckout
)

Checkout the branch with the specified name, if it does not exist create it

public boolean

Returns:

Returns true if a new commit was created. This is the case if the repository was not clean on method invocation
createCommitOnCurrentBranch
(String commitMessage, boolean
Whether to amend to the last commit (true), or not (false)
amend
)

Creates a commit on the currently checked out branch

public String
pack-priv Optional<org.eclipse.jgit.lib.Ref>
getRefForBranch(String branchName)

Returns the reference of the specified branch If it does not exist returns an empty optional

pack-priv boolean
isGitRepository()

Returns true if the given path points to a directory that is a git repository (contains a .git folder)

public void
mergeBranches(String
the name of the branch that is merged into
targetBranch
,
String
the name of the branch that gets merged
sourceBranch
,
org.eclipse.jgit.merge.MergeStrategy mergeStrategy)

Merges the source branch into the target branch

public void
public void
pushCommitsToRemoteRepository()

Pushes all commits made to the branch that is tracked by the currently checked out branch.

pack-priv void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

credentialsProviderback to summary
pack-priv final org.eclipse.jgit.transport.CredentialsProvider credentialsProvider
gitPasswordback to summary
pack-priv String gitPassword
gitUsernameback to summary
pack-priv String gitUsername
LOGGERback to summary
pack-priv static final Logger LOGGER
repositoryPathback to summary
pack-priv final Path repositoryPath
repositoryPathAsFileback to summary
pack-priv final File repositoryPathAsFile

Constructor Detail

GitHandlerback to summary
public GitHandler(Path repositoryPath)

Initialize the handler for the given repository

Parameters
repositoryPath:Path

The root of the initialized git repository

Method Detail

checkoutBranchback to summary
public void checkoutBranch(String branchToCheckout) throws IOException, org.eclipse.jgit.api.errors.GitAPIException

Checkout the branch with the specified name, if it does not exist create it

Parameters
branchToCheckout:String

Name of the branch to check out

createCommitOnCurrentBranchback to summary
public boolean createCommitOnCurrentBranch(String commitMessage, boolean amend) throws IOException, org.eclipse.jgit.api.errors.GitAPIException

Creates a commit on the currently checked out branch

Parameters
amend:boolean

Whether to amend to the last commit (true), or not (false)

Returns:boolean

Returns true if a new commit was created. This is the case if the repository was not clean on method invocation

getCurrentlyCheckedOutBranchback to summary
public String getCurrentlyCheckedOutBranch() throws IOException
getRefForBranchback to summary
pack-priv Optional<org.eclipse.jgit.lib.Ref> getRefForBranch(String branchName) throws org.eclipse.jgit.api.errors.GitAPIException, IOException

Returns the reference of the specified branch If it does not exist returns an empty optional

isGitRepositoryback to summary
pack-priv boolean isGitRepository()

Returns true if the given path points to a directory that is a git repository (contains a .git folder)

mergeBranchesback to summary
public void mergeBranches(String targetBranch, String sourceBranch, org.eclipse.jgit.merge.MergeStrategy mergeStrategy) throws IOException, org.eclipse.jgit.api.errors.GitAPIException

Merges the source branch into the target branch

Parameters
targetBranch:String

the name of the branch that is merged into

sourceBranch:String

the name of the branch that gets merged

pullOnCurrentBranchback to summary
public void pullOnCurrentBranch() throws IOException
pushCommitsToRemoteRepositoryback to summary
public void pushCommitsToRemoteRepository() throws IOException

Pushes all commits made to the branch that is tracked by the currently checked out branch. If pushing to remote fails, it fails silently.

setupGitIgnoreback to summary
pack-priv void setupGitIgnore()