|
org.netbeans.libs.git/1 1.1 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.netbeans.libs.git.GitClient
public final class GitClient
This class provides access to all supported git commands, methods that
allow you to get information about a git repository or affect the behavior
of invoked commands.
An instance of this class is always bound to a local git repository.
The repository (identified by a git repository root file) may not exist on disk however
because obviously when cloning or initializing a repository it may not yet physically exist.
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 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 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.
| Nested Class Summary | |
|---|---|
static class |
GitClient.DiffMode
Used as a parameter in commands comparing two trees in the repository. |
static class |
GitClient.ResetType
Used as a parameter of reset(java.lang.String, org.netbeans.libs.git.GitClient.ResetType, org.netbeans.libs.git.progress.ProgressMonitor)
to set the behavior of the command. |
| Method Summary | |
|---|---|
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. |
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,
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 |
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 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)
Returns an array of statuses for files under given roots |
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. |
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,
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,
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. |
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. |
File[] |
unignore(File[] files,
ProgressMonitor monitor)
Unignores given files |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public void add(File[] roots,
ProgressMonitor monitor)
throws GitException
roots - files or folders to add recursively to the indexmonitor - progress monitor
GitException - an unexpected error occurspublic void addNotificationListener(NotificationListener listener)
listener - a listener to add
public 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 monitor
GitException.MissingObjectException - when the revision revision cannot be resolved.
GitException - an unexpected error occurs
public boolean catFile(File file,
String revision,
OutputStream out,
ProgressMonitor monitor)
throws GitException.MissingObjectException,
GitException
file - file to catrevision - git revision, never nullout - output stream to print the content to.
true if the file was found in the specified revision and printed to out, otherwise false
GitException.MissingObjectException - if the given revision does not exist
GitException - an unexpected error occurs
public 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 stream
true if the file was found in the index and printed to out, otherwise false
GitException - an unexpected error occurs
public 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.
GitException - an unexpected error occurs
GitException.MissingObjectException
public 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 branch
GitException - an unexpected error occurs
GitException.MissingObjectException
public 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 monitor
GitException - an unexpected error occurs
public 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 monitor
GitException - an unexpected error occurs
public 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 monitor
GitException - an unexpected error occurs
public 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 monitor
GitException - an unexpected error occurs
public 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 monitor
GitException - an unexpected error occurs
public 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 monitor
GitException.NotMergedException - branch has not been fully merged yet and forceDeleteUnmerged is set to false
GitException - an unexpected error occurs
public void deleteTag(String tagName,
ProgressMonitor monitor)
throws GitException
tagName - name of a tag to deletemonitor - progress monitor
GitException - an unexpected error occurs
public 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 monitor
GitException - an unexpected error occurs
public 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 monitor
GitException - an unexpected error occurs
public 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 monitor
GitException.AuthorizationException - when the authentication or authorization fails
GitException - an unexpected error occurs
public 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 monitor
GitException.AuthorizationException - when the authentication or authorization fails
GitException - an unexpected error occurs
public Map<String,GitBranch> getBranches(boolean all,
ProgressMonitor monitor)
throws GitException
all - if false then only local (and no remote) branches will be returned
GitException - an unexpected error occurs
public 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 returned
GitException - an unexpected error occurs
public GitRevisionInfo getCommonAncestor(String[] revisions,
ProgressMonitor monitor)
throws GitException
null if none found.
revisions - revisions whose common ancestor to searchmonitor - progress monitor
null if none found.
GitException - an unexpected error occurs
public 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 monitor
null if none found.
GitException - an unexpected error occurs
public Map<File,GitStatus> getConflicts(File[] roots,
ProgressMonitor monitor)
throws GitException
getStatus(java.io.File[], org.netbeans.libs.git.progress.ProgressMonitor), but returns only conflicts.
roots - files to search the conflicts undermonitor - progress monitor
GitException - an unexpected error occurs
public Map<File,GitStatus> getStatus(File[] roots,
ProgressMonitor monitor)
throws GitException
roots - root folders or files to search under
GitException - an unexpected error occurs
public GitRemoteConfig getRemote(String remoteName,
ProgressMonitor monitor)
throws GitException
remoteName - name under which the remote is stored in repository's config filemonitor - progress monitor
null if no remote with such name was found
GitException - an unexpected error occurs
public Map<String,GitRemoteConfig> getRemotes(ProgressMonitor monitor)
throws GitException
monitor - progress monitor
GitException - an unexpected error occurs
public GitRepositoryState getRepositoryState(ProgressMonitor monitor)
throws GitException
monitor - progress monitor
GitException - an unexpected error occurs
public GitUser getUser()
throws GitException
GitException - an unexpected error occurs
public File[] ignore(File[] files,
ProgressMonitor monitor)
throws GitException
files - files to ignoremonitor - progress monitor
GitException - an unexpected error occurs
public void init(ProgressMonitor monitor)
throws GitException
monitor - progress monitor
GitException - if the repository could not be created either because it already exists inside workDir or cannot be created for other reasons.
public File[] listModifiedIndexEntries(File[] roots,
ProgressMonitor monitor)
throws GitException
roots - files or folders to search for modified files.monitor - progress monitor
GitException - an unexpected error occurs
public Map<String,GitBranch> listRemoteBranches(String remoteRepositoryUrl,
ProgressMonitor monitor)
throws GitException.AuthorizationException,
GitException
remoteRepositoryUrl - url of the remote repositorymonitor - progress monitor
GitException.AuthorizationException - when the authentication or authorization fails
GitException - an unexpected error occurs
public Map<String,String> listRemoteTags(String remoteRepositoryUrl,
ProgressMonitor monitor)
throws GitException.AuthorizationException,
GitException
remoteRepositoryUrl - url of the remote repositorymonitor - progress monitor
GitException.AuthorizationException - when the authentication or authorization fails
GitException - an unexpected error occurs
public GitRevisionInfo log(String revision,
ProgressMonitor monitor)
throws GitException.MissingObjectException,
GitException
revision - revision to search in the historymonitor - progress monitor
GitException.MissingObjectException - no such revision exists
GitException - an unexpected error occurs
public GitRevisionInfo[] log(SearchCriteria searchCriteria,
ProgressMonitor monitor)
throws GitException.MissingObjectException,
GitException
searchCriteria - criteria filtering the returned revisionsmonitor - progress monitor
GitException.MissingObjectException - revision specified in search criteria (or head if no such revision is specified) does not exist
GitException - an unexpected error occurs
public GitMergeResult merge(String revision,
ProgressMonitor monitor)
throws GitException.CheckoutConflictException,
GitException
revision - id of a revision to merge.monitor - progress monitor
GitException.CheckoutConflictException - there are local modifications in Working Tree, merge fails in such a case
GitException - an unexpected error occurs
public 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 monitor
GitException.AuthorizationException - when the authentication or authorization fails
GitException.CheckoutConflictException - there are local changes in the working tree that would result in a merge conflict
GitException.MissingObjectException - given branch to merge does not exist
GitException - an unexpected error occurs
public 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 monitor
GitException.AuthorizationException - when the authentication or authorization fails
GitException - an unexpected error occurs
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 monitor
GitException - 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 monitor
GitException - an unexpected error occurs
public 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 monitor
GitException - an unexpected error occurs
public 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 monitor
GitException.MissingObjectException - if the given revision does not exist
GitException - an unexpected error occurs
public 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 monitor
GitException.MissingObjectException - if the given revision does not exist
GitException - an unexpected error occurs
public 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 monitor
GitException.MissingObjectException - if the given revision does not exist
GitException.CheckoutConflictException - there are local modifications in Working Tree, merge fails in such a case
GitException - 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 monitor
GitException
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 monitor
GitException - an unexpected error occurs
|
org.netbeans.libs.git/1 1.1 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||