public final class GitClient extends Object
Working with this class
A client of the API should follow these steps in order to run a certain git commands:Instances of a git client are provided by GitRepository
. To get one call
GitRepository.createClient()
.
Some git client commands may (or may not) require additional setup of the client to successfully finish their work.
One quite usual use case is setting an instance of GitClientCallback
to the client so commands like push
,
fetch
or pull
may connect to and access a remote repository. To set an instance of GitClientCallback
use GitClient.setCallback(org.netbeans.libs.git.GitClientCallback)
method.
Certain git commands may take a long time to finish and they are capable of notifying the world about the progress in their work.
If you want to be notified about such changes while the command is in process, attach a listener to the client
via GitClient.addNotificationListener(org.netbeans.libs.git.progress.NotificationListener)
.
An example can be the log command. Digging through the history may take a lot of time so if you do not want to wait for the complete result only
and want to present the commit information incrementally as it is accepted one by one into the result, you can do so by adding an instance of
RevisionInfoListener
to the client.
When you have the client correctly set up, you may call any git command we support. The commands are mapped to appropriate methods in GitClient
.
Every method representing a git command accepts as a parameter an instance of ProgressMonitor
. With that class you may affect the flow of commands - it
has the ability to cancel running git commands - and listen for error or information messages the commands produce.
Modifier and Type | Class and Description |
---|---|
static class |
GitClient.CherryPickOperation
Used as a parameter of
GitClient.cherryPick(org.netbeans.libs.git.GitClient.CherryPickOperation, java.lang.String[], org.netbeans.libs.git.progress.ProgressMonitor) to set the behavior of the command. |
static class |
GitClient.DiffMode
Used as a parameter in commands comparing two trees in the repository.
|
static class |
GitClient.RebaseOperationType
Used as a parameter of
GitClient.rebase(GitClient.RebaseOperationType,
String, ProgressMonitor) to set the behavior of the command. |
static class |
GitClient.ResetType
Used as a parameter of
GitClient.reset(java.lang.String, org.netbeans.libs.git.GitClient.ResetType, org.netbeans.libs.git.progress.ProgressMonitor)
to set the behavior of the command. |
Modifier and Type | Field and Description |
---|---|
static String |
INDEX
"Commit" identifier representing the state in the Index.
|
static String |
WORKING_TREE
"Commit" identifier representing the state of the working tree.
|
Modifier and Type | Method and Description |
---|---|
void |
add(File[] roots,
ProgressMonitor monitor)
Adds all files under the given roots to the index
|
void |
addNotificationListener(NotificationListener listener)
Adds a listener of any kind to the client.
|
GitBlameResult |
blame(File file,
String revision,
ProgressMonitor monitor)
Annotates lines of a given file in a given revision and returns the result
with annotate information.
|
boolean |
catFile(File file,
String revision,
OutputStream out,
ProgressMonitor monitor)
Prints file's content in the given revision to output stream
|
boolean |
catIndexEntry(File file,
int stage,
OutputStream out,
ProgressMonitor monitor)
Prints content of an index entry accordant to the given file to the given output stream
|
void |
checkout(File[] roots,
String revision,
boolean recursively,
ProgressMonitor monitor)
Checks out the index into the working copy root.
|
void |
checkoutRevision(String revision,
boolean failOnConflict,
ProgressMonitor monitor)
Checks out a given revision, modifies the Index as well as the Working tree.
|
GitCherryPickResult |
cherryPick(GitClient.CherryPickOperation operation,
String[] revisions,
ProgressMonitor monitor)
Cherry-picks (transplants) selected revisions (commits) onto the current
HEAD.
|
void |
clean(File[] roots,
ProgressMonitor monitor)
Cleans the working tree by recursively removing files that are not under
version control starting from the given roots.
|
GitRevisionInfo |
commit(File[] roots,
String commitMessage,
GitUser author,
GitUser commiter,
boolean amend,
ProgressMonitor monitor)
Commits all changes made in the index to all files under the given roots
|
GitRevisionInfo |
commit(File[] roots,
String commitMessage,
GitUser author,
GitUser commiter,
ProgressMonitor monitor)
Commits all changes made in the index to all files under the given roots
|
void |
copyAfter(File source,
File target,
ProgressMonitor monitor)
The index entries representing files under the source are copied and the newly created entries represent the corresponding files under the target.
|
GitBranch |
createBranch(String branchName,
String revision,
ProgressMonitor monitor)
Creates a new branch with a given name, starting at the given revision
|
GitTag |
createTag(String tagName,
String taggedObject,
String message,
boolean signed,
boolean forceUpdate,
ProgressMonitor monitor)
Creates a tag for any object represented by a given taggedObjectId.
|
void |
deleteBranch(String branchName,
boolean forceDeleteUnmerged,
ProgressMonitor monitor)
Deletes a given branch from the repository
|
void |
deleteTag(String tagName,
ProgressMonitor monitor)
Deletes a given tag from the repository
|
void |
exportCommit(String commit,
OutputStream out,
ProgressMonitor monitor)
Exports a given commit in the format accepted by git am
|
void |
exportDiff(File[] roots,
GitClient.DiffMode mode,
OutputStream out,
ProgressMonitor monitor)
Exports uncommitted changes in files under given roots to the given output stream
|
void |
exportDiff(File[] roots,
String commitBase,
String commitOther,
OutputStream out,
ProgressMonitor monitor)
Exports diff of changes between two trees identified by files and two
commit/revision identifiers.
|
Map<String,GitTransportUpdate> |
fetch(String remote,
List<String> fetchRefSpecifications,
ProgressMonitor monitor)
Fetches remote changes from a remote repository for given reference specifications.
|
Map<String,GitTransportUpdate> |
fetch(String remote,
ProgressMonitor monitor)
Fetches remote changes for references specified in the config file under a given remote.
|
Map<String,GitBranch> |
getBranches(boolean all,
ProgressMonitor monitor)
Returns all known branches from the repository
|
GitRevisionInfo |
getCommonAncestor(String[] revisions,
ProgressMonitor monitor)
Returns a common ancestor for given revisions or
null if none found. |
Map<File,GitStatus> |
getConflicts(File[] roots,
ProgressMonitor monitor)
Similar to
GitClient.getStatus(java.io.File[], org.netbeans.libs.git.progress.ProgressMonitor) , but returns only conflicts. |
GitRevisionInfo |
getPreviousRevision(File file,
String revision,
ProgressMonitor monitor)
Returns an ancestor revision that affected a given file
|
GitRemoteConfig |
getRemote(String remoteName,
ProgressMonitor monitor)
Returns remote configuration set up for this repository identified by a given remoteName
|
Map<String,GitRemoteConfig> |
getRemotes(ProgressMonitor monitor)
Returns all remote configurations set up for this repository
|
GitRepositoryState |
getRepositoryState(ProgressMonitor monitor)
Returns the current state of the repository this client is associated with.
|
Map<File,GitStatus> |
getStatus(File[] roots,
ProgressMonitor monitor)
Compares the working tree with the current HEAD and returns an array of
statuses for files under given roots
|
Map<File,GitStatus> |
getStatus(File[] roots,
String revision,
ProgressMonitor monitor)
Compares working tree with a given revision and returns an array of
statuses for files under given roots
|
Map<File,GitRevisionInfo.GitFileInfo> |
getStatus(File[] roots,
String revisionFirst,
String revisionSecond,
ProgressMonitor monitor)
Compares two different commit trees and returns an array of file
modifications between
revisionFirst and revisionSecond |
Map<File,GitSubmoduleStatus> |
getSubmoduleStatus(File[] roots,
ProgressMonitor monitor)
Scans for any submodules under given roots or in the whole repository and
returns their status.
|
Map<String,GitTag> |
getTags(ProgressMonitor monitor,
boolean allTags)
Returns all tags in the repository
|
GitUser |
getUser()
Returns the user from this clients repository
|
File[] |
ignore(File[] files,
ProgressMonitor monitor)
Ignores given files and add their path into gitignore file.
|
void |
init(ProgressMonitor monitor)
Initializes an empty git repository in a folder specified in the constructor.
|
Map<File,GitSubmoduleStatus> |
initializeSubmodules(File[] roots,
ProgressMonitor monitor)
Initializes submodules and registers them in .git/config file.
|
File[] |
listModifiedIndexEntries(File[] roots,
ProgressMonitor monitor)
Returns files that are marked as modified between the HEAD and Index.
|
Map<String,GitBranch> |
listRemoteBranches(String remoteRepositoryUrl,
ProgressMonitor monitor)
Returns available branches in a given remote repository
|
Map<String,String> |
listRemoteTags(String remoteRepositoryUrl,
ProgressMonitor monitor)
Returns pairs tag name/id from a given remote repository
|
GitRevisionInfo[] |
log(SearchCriteria searchCriteria,
boolean fetchBranchInfo,
ProgressMonitor monitor)
Digs through the repository's history and returns revisions according to
the given search criteria.
|
GitRevisionInfo[] |
log(SearchCriteria searchCriteria,
ProgressMonitor monitor)
Digs through the repository's history and returns revisions according to the given search criteria.
|
GitRevisionInfo |
log(String revision,
ProgressMonitor monitor)
Digs through the repository's history and returns the revision information belonging to the given revision string.
|
GitMergeResult |
merge(String revision,
GitRepository.FastForwardOption fastForward,
ProgressMonitor monitor)
Merges a given revision with the current head.
|
GitMergeResult |
merge(String revision,
ProgressMonitor monitor)
Merges a given revision with the current head.
|
GitPullResult |
pull(String remote,
List<String> fetchRefSpecifications,
String branchToMerge,
ProgressMonitor monitor)
Pulls changes from a remote repository and merges a given remote branch to an active one.
|
GitPushResult |
push(String remote,
List<String> pushRefSpecifications,
List<String> fetchRefSpecifications,
ProgressMonitor monitor)
Pushes changes to a remote repository specified by remote for given reference specifications.
|
GitRebaseResult |
rebase(GitClient.RebaseOperationType operation,
String revision,
ProgressMonitor monitor)
Rebases the current HEAD onto a commit specified by the given revision.
|
void |
release()
Marks this client as released and notifies the repository it does not
have to stay open for this client.
|
void |
remove(File[] roots,
boolean cached,
ProgressMonitor monitor)
Removes given files/folders from the index and/or from the working tree
|
void |
removeNotificationListener(NotificationListener listener)
Removes an already added notification listener.
|
void |
removeRemote(String remote,
ProgressMonitor monitor)
Removes remote configuration from the repository's config file
|
void |
rename(File source,
File target,
boolean after,
ProgressMonitor monitor)
Renames source file or folder to target
|
void |
reset(File[] roots,
String revision,
boolean recursively,
ProgressMonitor monitor)
Updates entries for given files in the index with those from the given revision
|
void |
reset(String revision,
GitClient.ResetType resetType,
ProgressMonitor monitor)
Sets HEAD to the given revision and updates index and working copy accordingly to the given reset type
|
GitRevertResult |
revert(String revision,
String commitMessage,
boolean commit,
ProgressMonitor monitor)
Reverts already committed changes and creates an inverse commit.
|
void |
setCallback(GitClientCallback callback)
Sets credentials callback for this client.
|
void |
setRemote(GitRemoteConfig remoteConfig,
ProgressMonitor monitor)
Sets the remote configuration in the configuration file.
|
GitBranch |
setUpstreamBranch(String localBranchName,
String remoteBranch,
ProgressMonitor monitor)
Sets the upstream branch (tracking) of
localBranchName to
remoteBranch . |
void |
stashApply(int stashIndex,
boolean dropStash,
ProgressMonitor monitor)
Applies a stashed commit identified by the given index to the current
working tree state
|
void |
stashDrop(int stashIndex,
ProgressMonitor monitor)
Deletes the stashed commit identified by the given index (zero-based)
from the stash.
|
void |
stashDropAll(ProgressMonitor monitor)
Drops (deletes) all stashed commits from the stash.
|
GitRevisionInfo[] |
stashList(ProgressMonitor monitor)
Lists saved stashed commits.
|
GitRevisionInfo |
stashSave(String message,
boolean includeUntracked,
ProgressMonitor monitor)
Saves local uncommitted changes to the git stash and resets the working
tree to the HEAD.
|
File[] |
unignore(File[] files,
ProgressMonitor monitor)
Unignores given files
|
GitRefUpdateResult |
updateReference(String referenceName,
String newId,
ProgressMonitor monitor)
Updates a given reference to a new id.
|
Map<File,GitSubmoduleStatus> |
updateSubmodules(File[] roots,
ProgressMonitor monitor)
Updates submodules.
|
public static final String WORKING_TREE
GitClient.exportDiff(java.io.File[], java.lang.String, java.lang.String, java.io.OutputStream, org.netbeans.libs.git.progress.ProgressMonitor)
to diff a working tree state to another commit.public static final String INDEX
GitClient.exportDiff(java.io.File[], java.lang.String, java.lang.String, java.io.OutputStream, org.netbeans.libs.git.progress.ProgressMonitor)
to diff the Index state to another commit.public void add(File[] roots, ProgressMonitor monitor) throws GitException
roots
- files or folders to add recursively to the indexmonitor
- progress monitorGitException
- an unexpected error occurspublic void addNotificationListener(NotificationListener listener)
listener
- a listener to addpublic GitBlameResult blame(File file, String revision, ProgressMonitor monitor) throws GitException.MissingObjectException, GitException
file
- file to be annotatedrevision
- a revision the file should be annotated in or null
for blaming a checked-out file against HEADmonitor
- progress monitorGitException.MissingObjectException
- when the revision revision
cannot be resolved.GitException
- an unexpected error occurspublic boolean catFile(File file, String revision, OutputStream out, ProgressMonitor monitor) throws GitException.MissingObjectException, GitException
file
- file to catrevision
- git revision, never null
out
- output stream to print the content to.monitor
- progress monitortrue
if the file was found in the specified revision and printed to out, otherwise false
GitException.MissingObjectException
- if the given revision does not existGitException
- an unexpected error occurspublic boolean catIndexEntry(File file, int stage, OutputStream out, ProgressMonitor monitor) throws GitException
file
- file whose relevant index entry to catstage
- version of the file in the index. In case of a merge conflict there are usually more
versions of the file. 0
for normal non-conflict version,
1
for the base version,
2
for the first merged version ("ours") and
3
for the second merged version ("theirs").out
- output streammonitor
- progress monitortrue
if the file was found in the index and printed to out, otherwise false
GitException
- an unexpected error occurspublic void checkout(File[] roots, String revision, boolean recursively, ProgressMonitor monitor) throws GitException.MissingObjectException, GitException
revision
- if not null
, index is updated with the revision content before checking out to WCroots
- files/folders to checkoutrecursively
- if set to true
, all files under given roots will be checked out, otherwise only roots and direct file children will be affected.monitor
- progress monitorGitException.MissingObjectException
- missing git object loadedGitException
- an unexpected error occurspublic void checkoutRevision(String revision, boolean failOnConflict, ProgressMonitor monitor) throws GitException.MissingObjectException, GitException
revision
- cannot be null
. If the value equals to anything other than an existing branch name, the revision will be checked out
and the working tree will be in the detached HEAD state.failOnConflict
- if set to false
, the command tries to merge local changes into the new branchmonitor
- progress monitorGitException.MissingObjectException
- missing git object loadedGitException
- an unexpected error occurspublic GitCherryPickResult cherryPick(GitClient.CherryPickOperation operation, String[] revisions, ProgressMonitor monitor) throws GitException
operation
- kind of cherry-pick operation you want to performrevisions
- commits you want to cherry-pick. Makes sense only when
operation
is set to CherryPickOperation.BEGIN
otherwise it's meaningless.monitor
- progress monitorGitException
- an unexpected error occurspublic void clean(File[] roots, ProgressMonitor monitor) throws GitException
roots
- files or folders to recursively remove from disk, versioned files under these files will not be deleted.monitor
- progress monitorGitException
- an unexpected error occurspublic GitRevisionInfo commit(File[] roots, String commitMessage, GitUser author, GitUser commiter, ProgressMonitor monitor) throws GitException
roots
- files or folders to recursively commit.commitMessage
- commit messageauthor
- person who is the author of the changes to be committedcommiter
- person who is committing the changes, may not be the same person as author.monitor
- progress monitorGitException
- an unexpected error occurspublic GitRevisionInfo commit(File[] roots, String commitMessage, GitUser author, GitUser commiter, boolean amend, ProgressMonitor monitor) throws GitException
roots
- files or folders to recursively commit.commitMessage
- commit messageauthor
- person who is the author of the changes to be committedcommiter
- person who is committing the changes, may not be the same person as author.amend
- amends and modifies the last commit instead of adding a completely new commitmonitor
- progress monitorGitException
- an unexpected error occurspublic void copyAfter(File source, File target, ProgressMonitor monitor) throws GitException
source
- source tree to copytarget
- target file or folder the source should be copied onto.monitor
- progress monitorGitException
- an unexpected error occurspublic GitBranch createBranch(String branchName, String revision, ProgressMonitor monitor) throws GitException
branchName
- name that should be assigned to the new branchrevision
- revision that should be referenced by the new branchmonitor
- progress monitorGitException
- an unexpected error occurspublic GitTag createTag(String tagName, String taggedObject, String message, boolean signed, boolean forceUpdate, ProgressMonitor monitor) throws GitException
null
or an empty value and signed set to false
than this method creates a lightweight tag.tagName
- name of the new tagtaggedObject
- object to tagmessage
- tag messagesigned
- if the tag should be signed. Currently unsupported.forceUpdate
- if a tag with the same name already exists, the method fails and throws an exception unless this is set to true
. In that case the
old tag is replaced with the new one.monitor
- progress monitorGitException
- an unexpected error occurspublic void deleteBranch(String branchName, boolean forceDeleteUnmerged, ProgressMonitor monitor) throws GitException.NotMergedException, GitException
branchName
- name of a branch to delete.forceDeleteUnmerged
- if set to true
then trying to delete an unmerged branch will not fail but will forcibly delete the branchmonitor
- progress monitorGitException.NotMergedException
- branch has not been fully merged yet and forceDeleteUnmerged is set to false
GitException
- an unexpected error occurspublic void deleteTag(String tagName, ProgressMonitor monitor) throws GitException
tagName
- name of a tag to deletemonitor
- progress monitorGitException
- an unexpected error occurspublic void exportCommit(String commit, OutputStream out, ProgressMonitor monitor) throws GitException
commit
- id of a commit whose diff to exportout
- output stream the diff will be printed tomonitor
- progress monitorGitException
- an unexpected error occurspublic void exportDiff(File[] roots, GitClient.DiffMode mode, OutputStream out, ProgressMonitor monitor) throws GitException
roots
- the diff will be exported only for modified files under these roots, can be empty to export all modifications in the whole working treemode
- defines the compared treesout
- output stream the diff will be printed tomonitor
- progress monitorGitException
- an unexpected error occurspublic void exportDiff(File[] roots, String commitBase, String commitOther, OutputStream out, ProgressMonitor monitor) throws GitException
roots
- the diff will be exported only for files under these roots,
can be empty to export all modifications in the whole tree.commitBase
- first commit identifier, may be also
GitClient.WORKING_TREE
or GitClient.INDEX
.commitOther
- second commit identifier, may be also
GitClient.WORKING_TREE
or GitClient.INDEX
.out
- output stream the diff will be printed tomonitor
- progress monitorGitException
- an unexpected error occurspublic Map<String,GitTransportUpdate> fetch(String remote, ProgressMonitor monitor) throws GitException.AuthorizationException, GitException
remote
- should be a name of a remote set up in the repository config filemonitor
- progress monitorGitException.AuthorizationException
- when the authentication or authorization failsGitException
- an unexpected error occurspublic Map<String,GitTransportUpdate> fetch(String remote, List<String> fetchRefSpecifications, ProgressMonitor monitor) throws GitException.AuthorizationException, GitException
remote
- preferably a name of a remote, but can also be directly a URL of a remote repositoryfetchRefSpecifications
- list of reference specifications describing the objects to fetch from the remote repositorymonitor
- progress monitorGitException.AuthorizationException
- when the authentication or authorization failsGitException
- an unexpected error occurspublic Map<String,GitBranch> getBranches(boolean all, ProgressMonitor monitor) throws GitException
all
- if false
then only local (and no remote) branches will be returnedmonitor
- progress monitorGitException
- an unexpected error occurspublic Map<String,GitTag> getTags(ProgressMonitor monitor, boolean allTags) throws GitException
monitor
- progress monitorallTags
- if set to false
, only commit tags, otherwise tags for all objects are returnedGitException
- an unexpected error occurspublic GitRevisionInfo getCommonAncestor(String[] revisions, ProgressMonitor monitor) throws GitException
null
if none found.revisions
- revisions whose common ancestor to searchmonitor
- progress monitornull
if none found.GitException
- an unexpected error occurspublic GitRevisionInfo getPreviousRevision(File file, String revision, ProgressMonitor monitor) throws GitException
file
- limit the result only on revision that actually modified somehow the filerevision
- revision to start search from, only its ancestors will be investigatedmonitor
- progress monitornull
if none found.GitException
- an unexpected error occurspublic Map<File,GitStatus> getConflicts(File[] roots, ProgressMonitor monitor) throws GitException
GitClient.getStatus(java.io.File[], org.netbeans.libs.git.progress.ProgressMonitor)
, but returns only conflicts.roots
- files to search the conflicts undermonitor
- progress monitorGitException
- an unexpected error occurspublic Map<File,GitStatus> getStatus(File[] roots, ProgressMonitor monitor) throws GitException
roots
- root folders or files to search undermonitor
- progress monitorGitException
- an unexpected error occurspublic Map<File,GitStatus> getStatus(File[] roots, String revision, ProgressMonitor monitor) throws GitException
roots
- root folders or files to search underrevision
- revision to compare with the working tree. If set
to null
HEAD will be used instead.monitor
- progress monitorGitException
- an unexpected error occurspublic Map<File,GitRevisionInfo.GitFileInfo> getStatus(File[] roots, String revisionFirst, String revisionSecond, ProgressMonitor monitor) throws GitException
revisionFirst
and revisionSecond
roots
- root folders or files to search underrevisionFirst
- first revision to comparerevisionSecond
- second revision to comparemonitor
- progress monitorGitException
- an unexpected error occurspublic Map<File,GitSubmoduleStatus> getSubmoduleStatus(File[] roots, ProgressMonitor monitor) throws GitException
roots
- files to search for submodules. If empty all submodules will
be returnedmonitor
- command progress monitorGitException
- an unexpected error occurspublic GitRemoteConfig getRemote(String remoteName, ProgressMonitor monitor) throws GitException
remoteName
- name under which the remote is stored in repository's config filemonitor
- progress monitornull
if no remote with such name was foundGitException
- an unexpected error occurspublic Map<String,GitRemoteConfig> getRemotes(ProgressMonitor monitor) throws GitException
monitor
- progress monitorGitException
- an unexpected error occurspublic GitRepositoryState getRepositoryState(ProgressMonitor monitor) throws GitException
monitor
- progress monitorGitException
- an unexpected error occurspublic GitUser getUser() throws GitException
GitException
- an unexpected error occurspublic File[] ignore(File[] files, ProgressMonitor monitor) throws GitException
files
- files to ignoremonitor
- progress monitorGitException
- an unexpected error occurspublic void init(ProgressMonitor monitor) throws GitException
monitor
- progress monitorGitException
- if the repository could not be created either because it already exists inside workDir
or cannot be created for other reasons.public Map<File,GitSubmoduleStatus> initializeSubmodules(File[] roots, ProgressMonitor monitor) throws GitException
roots
- modules to initializemonitor
- progress monitorGitException
- an unexpected error occurspublic File[] listModifiedIndexEntries(File[] roots, ProgressMonitor monitor) throws GitException
roots
- files or folders to search for modified files.monitor
- progress monitorGitException
- an unexpected error occurspublic Map<String,GitBranch> listRemoteBranches(String remoteRepositoryUrl, ProgressMonitor monitor) throws GitException.AuthorizationException, GitException
remoteRepositoryUrl
- url of the remote repositorymonitor
- progress monitorGitException.AuthorizationException
- when the authentication or authorization failsGitException
- an unexpected error occurspublic Map<String,String> listRemoteTags(String remoteRepositoryUrl, ProgressMonitor monitor) throws GitException.AuthorizationException, GitException
remoteRepositoryUrl
- url of the remote repositorymonitor
- progress monitorGitException.AuthorizationException
- when the authentication or authorization failsGitException
- an unexpected error occurspublic GitRevisionInfo log(String revision, ProgressMonitor monitor) throws GitException.MissingObjectException, GitException
revision
- revision to search in the historymonitor
- progress monitorGitException.MissingObjectException
- no such revision existsGitException
- an unexpected error occurspublic GitRevisionInfo[] log(SearchCriteria searchCriteria, ProgressMonitor monitor) throws GitException.MissingObjectException, GitException
GitClient.log(org.netbeans.libs.git.SearchCriteria, boolean, org.netbeans.libs.git.progress.ProgressMonitor)
if you want to get such knowledge.searchCriteria
- criteria filtering the returned revisionsmonitor
- progress monitorGitException.MissingObjectException
- revision specified in search criteria (or head if no such revision is specified) does not existGitException
- an unexpected error occurspublic GitRevisionInfo[] log(SearchCriteria searchCriteria, boolean fetchBranchInfo, ProgressMonitor monitor) throws GitException.MissingObjectException, GitException
searchCriteria
- criteria filtering the returned revisionsfetchBranchInfo
- if set to true
then the command will
also fetch information (GitRevisionInfo.getBranches()
) about what
branches contain the individual commits returned by the command. You can
use that information to filter returned commits by the branches they're
part of. Also note that the command will take more time to finish.monitor
- progress monitorGitException.MissingObjectException
- revision specified in search
criteria (or head if no such revision is specified) does not existGitException
- an unexpected error occurspublic GitMergeResult merge(String revision, ProgressMonitor monitor) throws GitException.CheckoutConflictException, GitException
revision
- id of a revision to merge.monitor
- progress monitorGitException.CheckoutConflictException
- there are local modifications in Working Tree, merge fails in such a caseGitException
- an unexpected error occurspublic GitMergeResult merge(String revision, GitRepository.FastForwardOption fastForward, ProgressMonitor monitor) throws GitException.CheckoutConflictException, GitException
revision
- id of a revision to merge.fastForward
- option telling merge to enforce or disable fast forward merges.monitor
- progress monitorGitException.CheckoutConflictException
- there are local modifications in Working Tree, merge fails in such a caseGitException
- an unexpected error occurspublic GitPullResult pull(String remote, List<String> fetchRefSpecifications, String branchToMerge, ProgressMonitor monitor) throws GitException.AuthorizationException, GitException.CheckoutConflictException, GitException.MissingObjectException, GitException
remote
- preferably a name of a remote, but can also be directly a URL of a remote repositoryfetchRefSpecifications
- list of reference specifications describing what objects to fetch from the remote repositorybranchToMerge
- a remote branch that will be merged into an active branchmonitor
- progress monitorGitException.AuthorizationException
- when the authentication or authorization failsGitException.CheckoutConflictException
- there are local changes in the working tree that would result in a merge conflictGitException.MissingObjectException
- given branch to merge does not existGitException
- an unexpected error occurspublic GitPushResult push(String remote, List<String> pushRefSpecifications, List<String> fetchRefSpecifications, ProgressMonitor monitor) throws GitException.AuthorizationException, GitException
remote
- preferably a name of a remote defined in the repository's config,
but can also be directly a URL of a remote repositorypushRefSpecifications
- list of reference specifications describing the list of references to pushfetchRefSpecifications
- list of fetch reference specifications describing the list of local references to update
to correctly track remote repository branches.monitor
- progress monitorGitException.AuthorizationException
- when the authentication or authorization failsGitException
- an unexpected error occurspublic GitRebaseResult rebase(GitClient.RebaseOperationType operation, String revision, ProgressMonitor monitor) throws GitException
operation
- kind of rebase operation you want to performrevision
- id of a destination commit. Considered only
when operation
is set
to RebaseOperationType.BEGIN
otherwise it's meaningless.monitor
- progress monitorGitException
- an unexpected error occurspublic void release()
public void remove(File[] roots, boolean cached, ProgressMonitor monitor) throws GitException
roots
- files/folders to remove, can not be emptycached
- if true
the working tree will not be affectedmonitor
- progress monitorGitException
- an unexpected error occurspublic void removeNotificationListener(NotificationListener listener)
listener
- listener to remove.public void removeRemote(String remote, ProgressMonitor monitor) throws GitException
remote
- name of the remotemonitor
- progress monitorGitException
- an unexpected error occurspublic void rename(File source, File target, boolean after, ProgressMonitor monitor) throws GitException
source
- file or folder to be renamedtarget
- target file or folder. Must not yet exist.after
- set to true if you don't only want to correct the indexmonitor
- progress monitorGitException
- an unexpected error occurspublic void reset(File[] roots, String revision, boolean recursively, ProgressMonitor monitor) throws GitException.MissingObjectException, GitException
revision
- revision to go back toroots
- files or folders to update in the indexrecursively
- if set to true
, all files under given roots will be affected, otherwise only roots and direct file children will be modified in the index.monitor
- progress monitorGitException.MissingObjectException
- if the given revision does not existGitException
- an unexpected error occurspublic void reset(String revision, GitClient.ResetType resetType, ProgressMonitor monitor) throws GitException.MissingObjectException, GitException
revision
- revision HEAD will reference toresetType
- type of reset, see git help resetmonitor
- progress monitorGitException.MissingObjectException
- if the given revision does not existGitException
- an unexpected error occurspublic GitRevertResult revert(String revision, String commitMessage, boolean commit, ProgressMonitor monitor) throws GitException.MissingObjectException, GitException.CheckoutConflictException, GitException
revision
- the id of a commit to revertcommitMessage
- used as the commit message for the revert commit. If set to null or an empty value, a default value will be used for the commit messagecommit
- if set to false
, the revert modifications will not be committed but will stay in indexmonitor
- progress monitorGitException.MissingObjectException
- if the given revision does not existGitException.CheckoutConflictException
- there are local modifications in Working Tree, merge fails in such a caseGitException
- an unexpected error occurspublic void setCallback(GitClientCallback callback)
callback
- callback implementation providing credentials for an authentication process.public void setRemote(GitRemoteConfig remoteConfig, ProgressMonitor monitor) throws GitException
remoteConfig
- new remote config to store as a remote section in the repository's config file.monitor
- progress monitorGitException
- an unexpected error occurspublic GitBranch setUpstreamBranch(String localBranchName, String remoteBranch, ProgressMonitor monitor) throws GitException
localBranchName
to
remoteBranch
.localBranchName
- local branch supposed to track another branchremoteBranch
- branch from remoteName
to be trackedmonitor
- progress monitorGitException
- error occurspublic void stashApply(int stashIndex, boolean dropStash, ProgressMonitor monitor) throws GitException
stashIndex
- index identifying the stashed commit to apply, zero
based (0 as the most recent stash).dropStash
- if true
the stashed commit will be dropped
from the stash after it has been successfully applied.monitor
- progress monitorGitException
- an error occurs.public void stashDropAll(ProgressMonitor monitor) throws GitException
monitor
- progress monitorGitException
- an error occurs.public void stashDrop(int stashIndex, ProgressMonitor monitor) throws GitException
stashIndex
- zero-based index to the stash list (0 as the most
recent stash).monitor
- progress monitorGitException
- an error occurs.public GitRevisionInfo[] stashList(ProgressMonitor monitor) throws GitException
monitor
- progress monitorGitException
- an error occurs.public GitRevisionInfo stashSave(String message, boolean includeUntracked, ProgressMonitor monitor) throws GitException
message
- description of the created stash commit.includeUntracked
- if true
also untracked files will be
stashed and then deleted.monitor
- progress monitorGitException
- an error occurs.public File[] unignore(File[] files, ProgressMonitor monitor) throws GitException
files
- files to mark unignored again and remove their respective record from gitignore files.monitor
- progress monitorGitException
- an unexpected error occurspublic GitRefUpdateResult updateReference(String referenceName, String newId, ProgressMonitor monitor) throws GitException
referenceName
- name of the ref to updatenewId
- the new reference idmonitor
- progress monitorGitException
- an unexpected error happenspublic Map<File,GitSubmoduleStatus> updateSubmodules(File[] roots, ProgressMonitor monitor) throws GitException
roots
- modules to updatemonitor
- progress monitorGitException
- an unexpected error occurs