Package com.mooltiverse.oss.nyx.git
Interface Repository
public interface Repository
This interface models coarse grained, implementation independent methods used by Nyx to access a Git repository.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(Collection<String> paths) Adds the given paths to the staging area.Commits changes to the repository.Commits changes to the repository.commit(Collection<String> paths, String message) Adds the given files to the staging area and commits changes to the repository.Adds the given files to the staging area and commits changes to the repository.getCommitTags(String commit) Returns a set of objects representing all the tags for the given commit.Returns the name of the current branch or a commit SHA-1 if the repository is in the detached head state.Returns the SHA-1 identifier of the last commit in the current branch.Returns the names of configured remote repositories.Returns the SHA-1 identifier of the first commit in the repository (the only commit with no parents).getTags()Returns a set of objects representing all the tags for the repository.booleanisClean()Returnstrueif the repository is clean, which is when no differences exist between the working tree, the index, and the currentHEAD.Pushes local changes in the current branch to the default remoteorigin.Pushes local changes in the current branch to the default remoteorigin.Pushes local changes in the current branch to the given remote using no authentication.Pushes local changes in the current branch to the given remote using no authentication.Pushes local changes in the current branch to the given remote.Pushes local changes in the current branch to the given remote.push(Collection<String> remotes, String privateKey, byte[] passphrase) Pushes local changes in the current branch to the given remotes.push(Collection<String> remotes, String user, String password) Pushes local changes in the current branch to the given remotes.Tags the latest commit in the current branch with a tag with the given name.Tags the latest commit in the current branch with a tag with the given name and optional message.Tags the latest commit in the current branch with a tag with the given name and optional message.Tags the latest commit in the current branch with a tag with the given name and optional message using the optional tagger identity.Tags the object represented by the given SHA-1 with a tag with the given name and optional message using the optional tagger identity.Tags the object represented by the given SHA-1 with a tag with the given name and optional message using the optional tagger identity.voidwalkHistory(String start, String end, CommitVisitor visitor) Browse the repository commit history using the givenvisitorto inspect each commit.
-
Field Details
-
DEFAULT_REMOTE_NAME
The default remote name. Value: "origin".- See Also:
-
-
Method Details
-
add
Adds the given paths to the staging area.- Parameters:
paths- the file patterns of the contents to add to stage. Cannot benullor empty. The path "." represents all files in the working area so with that you can add all locally changed files.- Throws:
GitException- in case some problem is encountered with the underlying Git repository, preventing to add paths.- See Also:
-
commit
Commits changes to the repository. Files to commit must be staged separately usingadd(Collection).- Parameters:
message- the commit message. Cannot benull.- Returns:
- the object modelling the new commit that was created. Never
null. - Throws:
GitException- in case some problem is encountered with the underlying Git repository, preventing to commit.- See Also:
-
commit
Commits changes to the repository. Files to commit must be staged separately usingadd(Collection).- Parameters:
message- the commit message. Cannot benull.author- the object modelling the commit author informations. It may benull, in which case the default for the repository will be usedcommitter- the object modelling the committer informations. It may benull, in which case the default for the repository will be used- Returns:
- the object modelling the new commit that was created. Never
null. - Throws:
GitException- in case some problem is encountered with the underlying Git repository, preventing to commit.- See Also:
-
commit
Adds the given files to the staging area and commits changes to the repository. This method is a shorthand foradd(Collection)andcommit(String).- Parameters:
paths- the file patterns of the contents to add to stage. Cannot benullor empty. The path "." represents all files in the working area so with that you can add all locally changed files.message- the commit message. Cannot benull.- Returns:
- the object modelling the new commit that was created. Never
null. - Throws:
GitException- in case some problem is encountered with the underlying Git repository, preventing to commit.
-
commit
Commit commit(Collection<String> paths, String message, Identity author, Identity committer) throws GitException Adds the given files to the staging area and commits changes to the repository. This method is a shorthand foradd(Collection)andcommit(String, Identity, Identity).- Parameters:
paths- the file patterns of the contents to add to stage. Cannot benullor empty. The path "." represents all files in the working area so with that you can add all locally changed files.message- the commit message. Cannot benull.author- the object modelling the commit author informations. It may benull, in which case the default for the repository will be usedcommitter- the object modelling the committer informations. It may benull, in which case the default for the repository will be used- Returns:
- the object modelling the new commit that was created. Never
null. - Throws:
GitException- in case some problem is encountered with the underlying Git repository, preventing to commit.
-
getCommitTags
Returns a set of objects representing all the tags for the given commit.- Parameters:
commit- the SHA-1 identifier of the commit to get the tags for. It can be a full or abbreviated SHA-1.- Returns:
- the set of objects representing all the tags for the given commit.
- Throws:
GitException- in case some problem is encountered with the underlying Git repository.
-
getCurrentBranch
Returns the name of the current branch or a commit SHA-1 if the repository is in the detached head state.- Returns:
- the name of the current branch or a commit SHA-1 if the repository is in the detached head state.
- Throws:
GitException- in case some problem is encountered with the underlying Git repository, including when the repository has no commits yet or is in the 'detached HEAD' state.
-
getLatestCommit
Returns the SHA-1 identifier of the last commit in the current branch.- Returns:
- the SHA-1 identifier of the last commit in the current branch.
- Throws:
GitException- in case some problem is encountered with the underlying Git repository, including when the repository has no commits yet or is in the 'detached HEAD' state.
-
getRemoteNames
Returns the names of configured remote repositories.- Returns:
- the names of configured remote repositories.
- Throws:
GitException- in case some problem is encountered with the underlying Git repository, including when the repository has no commits yet or is in the 'detached HEAD' state.
-
getRootCommit
Returns the SHA-1 identifier of the first commit in the repository (the only commit with no parents).- Returns:
- the SHA-1 identifier of the first commit in the repository.
- Throws:
GitException- in case some problem is encountered with the underlying Git repository, including when the repository has no commits yet or is in the 'detached HEAD' state.
-
getTags
Returns a set of objects representing all the tags for the repository.- Returns:
- the set of objects representing all the tags for the repository.
- Throws:
GitException- in case some problem is encountered with the underlying Git repository.
-
isClean
Returnstrueif the repository is clean, which is when no differences exist between the working tree, the index, and the currentHEAD.- Returns:
trueif the repository is clean,falseotherwise.- Throws:
GitException- in case some problem is encountered with the underlying Git repository, including when the repository has no commits yet or is in the 'detached HEAD' state.
-
push
Pushes local changes in the current branch to the default remoteorigin. This method allows using user name and password authentication (also used for tokens).- Parameters:
user- the user name to create when credentials are required. If this andpasswordare bothnullthen no credentials is used. When using single token authentication (i.e. OAuth or Personal Access Tokens) this value may be the token or something other than a token, depending on the remote provider.password- the password to create when credentials are required. If this anduserare bothnullthen no credentials is used. When using single token authentication (i.e. OAuth or Personal Access Tokens) this value may be the token or something other than a token, depending on the remote provider.- Returns:
- the local name of the remotes that has been pushed
- Throws:
GitException- in case some problem is encountered with the underlying Git repository, preventing to push.- See Also:
-
push
Pushes local changes in the current branch to the default remoteorigin. This method allows using SSH authentication.- Parameters:
privateKey- the SSH private key. Ifnullthe private key will be searched in its default location (i.e. in the users'$HOME/.sshdirectory).passphrase- the optional password to use to open the private key, in case it's protected by a passphrase. This is required when the private key is password protected as this implementation does not support prompting the user interactively for entering the password.- Returns:
- the local name of the remotes that has been pushed
- Throws:
GitException- in case some problem is encountered with the underlying Git repository, preventing to push.- See Also:
-
push
Pushes local changes in the current branch to the given remote. This method allows using user name and password authentication (also used for tokens).- Parameters:
remote- the name of the remote to push to. Ifnullor empty the default remote name (origin) is used.user- the user name to create when credentials are required. If this andpasswordare bothnullthen no credentials is used. When using single token authentication (i.e. OAuth or Personal Access Tokens) this value may be the token or something other than a token, depending on the remote provider.password- the password to create when credentials are required. If this anduserare bothnullthen no credentials is used. When using single token authentication (i.e. OAuth or Personal Access Tokens) this value may be the token or something other than a token, depending on the remote provider.- Returns:
- the local name of the remotes that has been pushed
- Throws:
GitException- in case some problem is encountered with the underlying Git repository, preventing to push.- See Also:
-
push
Pushes local changes in the current branch to the given remote. This method allows using user name and password authentication (also used for tokens).- Parameters:
remote- the name of the remote to push to. Ifnullor empty the default remote name (origin) is used.user- the user name to create when credentials are required. If this andpasswordare bothnullthen no credentials is used. When using single token authentication (i.e. OAuth or Personal Access Tokens) this value may be the token or something other than a token, depending on the remote provider.password- the password to create when credentials are required. If this anduserare bothnullthen no credentials is used. When using single token authentication (i.e. OAuth or Personal Access Tokens) this value may be the token or something other than a token, depending on the remote provider.force- set it totrueif you want the push to be executed using the force option- Returns:
- the local name of the remotes that has been pushed
- Throws:
GitException- in case some problem is encountered with the underlying Git repository, preventing to push.- See Also:
-
push
Pushes local changes in the current branch to the given remote using no authentication. This method allows using SSH authentication.- Parameters:
remote- the name of the remote to push to. Ifnullor empty the default remote name (origin) is used.privateKey- the SSH private key. Ifnullthe private key will be searched in its default location (i.e. in the users'$HOME/.sshdirectory).passphrase- the optional password to use to open the private key, in case it's protected by a passphrase. This is required when the private key is password protected as this implementation does not support prompting the user interactively for entering the password.- Returns:
- the local name of the remotes that has been pushed
- Throws:
GitException- in case some problem is encountered with the underlying Git repository, preventing to push.- See Also:
-
push
Pushes local changes in the current branch to the given remote using no authentication. This method allows using SSH authentication.- Parameters:
remote- the name of the remote to push to. Ifnullor empty the default remote name (origin) is used.privateKey- the SSH private key. Ifnullthe private key will be searched in its default location (i.e. in the users'$HOME/.sshdirectory).passphrase- the optional password to use to open the private key, in case it's protected by a passphrase. This is required when the private key is password protected as this implementation does not support prompting the user interactively for entering the password.force- set it totrueif you want the push to be executed using the force option- Returns:
- the local name of the remotes that has been pushed
- Throws:
GitException- in case some problem is encountered with the underlying Git repository, preventing to push.- See Also:
-
push
Pushes local changes in the current branch to the given remotes. This method allows using user name and password authentication (also used for tokens).- Parameters:
remotes- the names of remotes to push to. Ifnullor empty the default remote name (origin) is used.user- the user name to create when credentials are required. If this andpasswordare bothnullthen no credentials is used. When using single token authentication (i.e. OAuth or Personal Access Tokens) this value may be the token or something other than a token, depending on the remote provider.password- the password to create when credentials are required. If this anduserare bothnullthen no credentials is used. When using single token authentication (i.e. OAuth or Personal Access Tokens) this value may be the token or something other than a token, depending on the remote provider.- Returns:
- a collection with the local names of remotes that have been pushed
- Throws:
GitException- in case some problem is encountered with the underlying Git repository, preventing to push.
-
push
Set<String> push(Collection<String> remotes, String privateKey, byte[] passphrase) throws GitException Pushes local changes in the current branch to the given remotes. This method allows using SSH authentication.- Parameters:
remotes- the names of remotes to push to. Ifnullor empty the default remote name (origin) is used.privateKey- the SSH private key. Ifnullthe private key will be searched in its default location (i.e. in the users'$HOME/.sshdirectory).passphrase- the optional password to use to open the private key, in case it's protected by a passphrase. This is required when the private key is password protected as this implementation does not support prompting the user interactively for entering the password.- Returns:
- a collection with the local names of remotes that have been pushed
- Throws:
GitException- in case some problem is encountered with the underlying Git repository, preventing to push.
-
tag
Tags the latest commit in the current branch with a tag with the given name. The resulting tag is lightweight. If the tag already exists it's updated.- Parameters:
name- the name of the tag. Cannot benull- Returns:
- the object modelling the new tag that was created. Never
null. - Throws:
GitException- in case some problem is encountered with the underlying Git repository, preventing to tag (i.e. when the tag name isnull).
-
tag
Tags the latest commit in the current branch with a tag with the given name and optional message. If the tag already exists it's updated.- Parameters:
name- the name of the tag. Cannot benullmessage- the optional tag message. Ifnullthe new tag will be lightweight, otherwise it will be an annotated tag- Returns:
- the object modelling the new tag that was created. Never
null. - Throws:
GitException- in case some problem is encountered with the underlying Git repository, preventing to tag (i.e. when the tag name isnull).
-
tag
Tags the latest commit in the current branch with a tag with the given name and optional message. If the tag already exists it's updated.- Parameters:
name- the name of the tag. Cannot benullmessage- the optional tag message. Ifnullthe new tag will be lightweight, otherwise it will be an annotated tagforce- set it totrueif you want the tag to be applied using the force option- Returns:
- the object modelling the new tag that was created. Never
null. - Throws:
GitException- in case some problem is encountered with the underlying Git repository, preventing to tag (i.e. when the tag name isnull).
-
tag
Tags the latest commit in the current branch with a tag with the given name and optional message using the optional tagger identity. If the tag already exists it's updated.- Parameters:
name- the name of the tag. Cannot benullmessage- the optional tag message. Ifnullthe new tag will be lightweight, otherwise it will be an annotated tagtagger- the optional identity of the tagger. IfnullGit defaults are used. Ifmessageisnullthis is ignored.- Returns:
- the object modelling the new tag that was created. Never
null. - Throws:
GitException- in case some problem is encountered with the underlying Git repository, preventing to tag (i.e. when the tag name isnull).
-
tag
Tags the object represented by the given SHA-1 with a tag with the given name and optional message using the optional tagger identity. If the tag already exists it's updated.- Parameters:
target- the SHA-1 identifier of the object to tag. Ifnullthe latest commit in the current branch is tagged.name- the name of the tag. Cannot benullmessage- the optional tag message. Ifnullthe new tag will be lightweight, otherwise it will be an annotated tagtagger- the optional identity of the tagger. IfnullGit defaults are used. Ifmessageisnullthis is ignored.- Returns:
- the object modelling the new tag that was created. Never
null. - Throws:
GitException- in case some problem is encountered with the underlying Git repository, preventing to tag (i.e. when the tag name isnull).
-
tag
Tag tag(String target, String name, String message, Identity tagger, boolean force) throws GitException Tags the object represented by the given SHA-1 with a tag with the given name and optional message using the optional tagger identity. If the tag already exists it's updated.- Parameters:
target- the SHA-1 identifier of the object to tag. Ifnullthe latest commit in the current branch is tagged.name- the name of the tag. Cannot benullmessage- the optional tag message. Ifnullthe new tag will be lightweight, otherwise it will be an annotated tagtagger- the optional identity of the tagger. IfnullGit defaults are used. Ifmessageisnullthis is ignored.force- set it totrueif you want the tag to be applied using the force option- Returns:
- the object modelling the new tag that was created. Never
null. - Throws:
GitException- in case some problem is encountered with the underlying Git repository, preventing to tag (i.e. when the tag name isnull).
-
walkHistory
Browse the repository commit history using the givenvisitorto inspect each commit. Commits are evaluated in Git's natural order, from the most recent to oldest.- Parameters:
start- the optional SHA-1 id of the commit to start from. Ifnullthe latest commit in the current branch (HEAD) is used. This can be a long or abbreviated SHA-1. If this commit cannot be resolved within the repository aGitExceptionis thrown.end- the optional SHA-1 id of the commit to end with, included. Ifnullthe repository root commit is used (until the givenvisitorreturnsfalse). If this commit is not reachable from the start it will be ignored. This can be a long or abbreviated SHA-1. If this commit cannot be resolved within the repository aGitExceptionis thrown.visitor- the visitor function that will receive commit data to evaluate. Ifnullthis method takes no action.- Throws:
GitException- in case some problem is encountered with the underlying Git repository, including when the repository has no commits yet or a given commit identifier cannot be resolved.
-