Git
Overview
Module
- package:
org.eclipse.dirigible.sdk.git - source: git/Git.java
JGit-backed operations against repositories the IDE knows about under a user's workspace. Covers the everyday flow — clone, pull, push, checkout, status, log, file content at a given revision — plus branch and remote management.
Repositories are addressed by (workspaceName, repositoryName); the URI and credentials only appear on the clone and pull / push operations. Every method that touches the repository propagates the underlying JGit / connector checked exceptions verbatim — handle them at the controller / job boundary the way you would with GitFacade directly.
For ad-hoc Git work that does not need to live in a workspace (CI scripts, throwaway tooling), the bare JGit API (org.eclipse.jgit.api.Git) is a more appropriate fit.
Key Features:
- Workspace-resident — repositories are addressed by name, not by filesystem path.
- Full JGit surface — clone, pull, push, checkout, rebase, hard-reset, status, history.
- Native return types —
GitBranch,GitChangedFile,GitCommitInfo,Statusetc.
Example Usage:
import org.eclipse.dirigible.sdk.git.Git;
import org.eclipse.dirigible.components.ide.git.domain.GitCommitInfo;
import java.util.List;
Git.cloneRepository("myws", "https://github.com/acme/svc.git", "user", "token", "main");
Git.commit("alice", "alice@acme.com", "myws", "svc", "tighten validation", true);
Git.push("myws", "svc", "user", "token");
List<GitCommitInfo> history = Git.getHistory("svc", "myws", "src/Main.java");Methods
initRepository()
Initializes a new repository under the given workspace and creates an initial commit.
javapublic static void initRepository(String username, String email, String workspaceName, String projectName, String repositoryName, String commitMessage) throws IOException, GitAPIException, GitConnectorException;
Parameter Type Description usernameStringAuthor user name. StringAuthor email. workspaceNameStringOwning workspace. projectNameStringProject to seed the repository from. repositoryNameStringNew repository name. commitMessageStringInitial commit message.
commit()
Creates a commit on the workspace's current branch.
javapublic static void commit(String username, String email, String workspaceName, String repositoryName, String commitMessage, Boolean add) throws GitAPIException, IOException, GitConnectorException;
Parameter Type Description usernameStringAuthor user name. StringAuthor email. workspaceNameStringThe workspace. repositoryNameStringThe repository. commitMessageStringCommit message. addBooleanIf true, stage all changes before committing.
getRepositories()
Lists all Git repositories under a workspace.
javapublic static List<ProjectDescriptor> getRepositories(String workspaceName);
Parameter Type Description workspaceNameStringThe workspace. Returns
- Type:
List<ProjectDescriptor>- Description: Descriptors for every Git repository in the workspace.
getHistory()
Returns the commit history of a path within a repository.
javapublic static List<GitCommitInfo> getHistory(String repositoryName, String workspaceName, String path) throws GitConnectorException;
Parameter Type Description repositoryNameStringThe repository. workspaceNameStringThe workspace. pathStringPath within the repository (or empty for the root). Returns
- Type:
List<GitCommitInfo>- Description: Commits in reverse chronological order.
deleteRepository()
Removes a repository from the workspace.
javapublic static void deleteRepository(String workspaceName, String repositoryName) throws GitConnectorException;
Parameter Type Description workspaceNameStringThe workspace. repositoryNameStringThe repository.
cloneRepository()
Clones a remote repository into the workspace.
javapublic static IGitConnector cloneRepository(String workspaceName, String repositoryUri, String username, String password, String branch) throws IOException, GitAPIException;
Parameter Type Description workspaceNameStringThe destination workspace. repositoryUriStringRemote URL. usernameStringCredentials user. passwordStringCredentials secret (token, app password). branchStringBranch to check out after clone. Returns
- Type:
IGitConnector- Description: Live connector to the cloned repository.
pull()
Pulls from the configured remote.
javapublic static void pull(String workspaceName, String repositoryName, String username, String password) throws GitAPIException, IOException, GitConnectorException;
push()
Pushes the current branch to the configured remote.
javapublic static void push(String workspaceName, String repositoryName, String username, String password) throws GitAPIException, IOException, GitConnectorException;
checkout()
Switches to the named branch.
javapublic static void checkout(String workspaceName, String repositoryName, String branchName) throws GitAPIException, IOException, GitConnectorException;
hardReset()
Discards working-tree and index changes, resetting HEAD hard.
javapublic static void hardReset(String workspaceName, String repositoryName) throws GitAPIException, IOException, GitConnectorException;
rebase()
Rebases the current branch onto the named branch.
javapublic static void rebase(String workspaceName, String repositoryName, String branchName) throws GitAPIException, IOException, GitConnectorException;
status()
Returns JGit's Status for the repository.
javapublic static Status status(String workspaceName, String repositoryName) throws GitAPIException, IOException, GitConnectorException;Returns
- Type:
org.eclipse.jgit.api.Status- Description: JGit status object —
added(),modified(),removed(), etc.
getBranch()
Returns the current branch name.
javapublic static String getBranch(String workspaceName, String repositoryName) throws GitAPIException, IOException, GitConnectorException;
getLocalBranches() / getRemoteBranches()
List local or remote branches.
javapublic static List<GitBranch> getLocalBranches(String workspaceName, String repositoryName); public static List<GitBranch> getRemoteBranches(String workspaceName, String repositoryName);
getUnstagedChanges() / getStagedChanges()
Inspect the working-tree / index state.
javapublic static List<GitChangedFile> getUnstagedChanges(String workspaceName, String repositoryName); public static List<GitChangedFile> getStagedChanges(String workspaceName, String repositoryName);
getFileContent()
Reads file content at a specific revision.
javapublic static String getFileContent(String workspaceName, String repositoryName, String filePath, String revStr) throws GitAPIException, IOException, GitConnectorException;
Parameter Type Description workspaceNameStringThe workspace. repositoryNameStringThe repository. filePathStringPath within the repository. revStrStringRevision (commit hash, branch, tag, or HEAD).Returns
- Type:
String- Description: File contents at the given revision.