List of usage examples for org.eclipse.jgit.lib ConfigConstants CONFIG_KEY_EMAIL
String CONFIG_KEY_EMAIL
To view the source code for org.eclipse.jgit.lib ConfigConstants CONFIG_KEY_EMAIL.
Click Source Link
From source file:org.eclipse.che.git.impl.jgit.JGitConnection.java
License:Open Source License
public void clone(CloneRequest request) throws GitException, UnauthorizedException { String remoteUri;//from w w w . ja va 2 s. c om boolean removeIfFailed = false; try { if (request.getRemoteName() == null) { request.setRemoteName(Constants.DEFAULT_REMOTE_NAME); } if (request.getWorkingDir() == null) { request.setWorkingDir(repository.getWorkTree().getCanonicalPath()); } // If clone fails and the .git folder didn't exist we want to remove it. // We have to do this here because the clone command doesn't revert its own changes in case of failure. removeIfFailed = !repository.getDirectory().exists(); remoteUri = request.getRemoteUri(); CloneCommand cloneCommand = Git.cloneRepository().setDirectory(new File(request.getWorkingDir())) .setRemote(request.getRemoteName()).setURI(remoteUri); if (request.getBranchesToFetch().isEmpty()) { cloneCommand.setCloneAllBranches(true); } else { cloneCommand.setBranchesToClone(request.getBranchesToFetch()); } executeRemoteCommand(remoteUri, cloneCommand); StoredConfig repositoryConfig = getRepository().getConfig(); GitUser gitUser = getUser(); if (gitUser != null) { repositoryConfig.setString(ConfigConstants.CONFIG_USER_SECTION, null, ConfigConstants.CONFIG_KEY_NAME, gitUser.getName()); repositoryConfig.setString(ConfigConstants.CONFIG_USER_SECTION, null, ConfigConstants.CONFIG_KEY_EMAIL, gitUser.getEmail()); } repositoryConfig.save(); } catch (IOException | GitAPIException exception) { // Delete .git directory in case it was created if (removeIfFailed) { deleteRepositoryFolder(); } throw new GitException(exception.getMessage(), exception); } }
From source file:org.eclipse.egit.ui.internal.dialogs.BasicConfigurationDialog.java
License:Open Source License
@Override protected void buttonPressed(int buttonId) { if (buttonId == Window.OK) { if (needsUpdate) { userScopedConfig.setString(ConfigConstants.CONFIG_USER_SECTION, null, ConfigConstants.CONFIG_KEY_NAME, userName.getText()); userScopedConfig.setString(ConfigConstants.CONFIG_USER_SECTION, null, ConfigConstants.CONFIG_KEY_EMAIL, email.getText()); try { userScopedConfig.save(); } catch (IOException e) { Activator.handleError(e.getMessage(), e, true); }// w w w . j a v a 2 s . c om } if (dontShowAgain.getSelection()) Activator.getDefault().getPreferenceStore().setValue(UIPreferences.SHOW_INITIAL_CONFIG_DIALOG, false); } super.buttonPressed(buttonId); }
From source file:org.eclipse.egit.ui.test.TestUtil.java
License:Open Source License
public static void configureTestCommitterAsUser(Repository repository) { StoredConfig config = repository.getConfig(); config.setString(ConfigConstants.CONFIG_USER_SECTION, null, ConfigConstants.CONFIG_KEY_NAME, TestUtil.TESTCOMMITTER_NAME); config.setString(ConfigConstants.CONFIG_USER_SECTION, null, ConfigConstants.CONFIG_KEY_EMAIL, TestUtil.TESTCOMMITTER_EMAIL); }
From source file:org.eclipse.orion.server.git.servlets.GitCloneHandlerV1.java
License:Open Source License
static void doConfigureClone(Git git, String user) throws IOException, CoreException { StoredConfig config = git.getRepository().getConfig(); IOrionUserProfileNode userNode = UserServiceHelper.getDefault().getUserProfileService() .getUserProfileNode(user, true).getUserProfileNode(IOrionUserProfileConstants.GENERAL_PROFILE_PART); if (userNode.get(GitConstants.KEY_NAME, null) != null) config.setString(ConfigConstants.CONFIG_USER_SECTION, null, ConfigConstants.CONFIG_KEY_NAME, userNode.get(GitConstants.KEY_NAME, null)); if (userNode.get(GitConstants.KEY_MAIL, null) != null) config.setString(ConfigConstants.CONFIG_USER_SECTION, null, ConfigConstants.CONFIG_KEY_EMAIL, userNode.get(GitConstants.KEY_MAIL, null)); config.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_FILEMODE, false); config.save();/* w w w . ja v a 2s . com*/ }
From source file:org.eclipse.orion.server.tests.servlets.git.GitConfigTest.java
License:Open Source License
@Test public void testClonedRepoConfigUsingUserProfile() throws Exception { // set Git name and mail in the user profile WebRequest request = getPutUserRequest(); WebResponse response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); // clone a repo URI workspaceLocation = createWorkspace(getMethodName()); JSONObject project = createProjectOrLink(workspaceLocation, getMethodName(), null); IPath clonePath = new Path("file").append(project.getString(ProtocolConstants.KEY_ID)).makeAbsolute(); String contentLocation = clone(clonePath).getString(ProtocolConstants.KEY_CONTENT_LOCATION); // check the repository configuration using JGit API Git git = new Git(getRepositoryForContentLocation(contentLocation)); StoredConfig config = git.getRepository().getConfig(); assertEquals(GIT_NAME,/*from ww w . j a v a 2s . com*/ config.getString(ConfigConstants.CONFIG_USER_SECTION, null, ConfigConstants.CONFIG_KEY_NAME)); assertEquals(GIT_MAIL, config.getString(ConfigConstants.CONFIG_USER_SECTION, null, ConfigConstants.CONFIG_KEY_EMAIL)); // now check if commits have the right committer set request = getGetFilesRequest(project.getString(ProtocolConstants.KEY_CONTENT_LOCATION)); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); project = new JSONObject(response.getText()); String childrenLocation = project.getString(ProtocolConstants.KEY_CHILDREN_LOCATION); assertNotNull(childrenLocation); // check if Git locations are in place JSONObject gitSection = project.optJSONObject(GitConstants.KEY_GIT); assertNotNull(gitSection); String gitIndexUri = gitSection.getString(GitConstants.KEY_INDEX); String gitHeadUri = gitSection.getString(GitConstants.KEY_HEAD); // modify String projectLocation = project.getString(ProtocolConstants.KEY_LOCATION); request = getPutFileRequest(projectLocation + "/test.txt", "change to commit"); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); // add request = GitAddTest.getPutGitIndexRequest(gitIndexUri + "test.txt"); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); // commit all request = GitCommitTest.getPostGitCommitRequest(gitHeadUri /* all */, GIT_COMMIT_MESSAGE, false); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); // log // TODO: replace with RESTful API for git log when available Iterable<RevCommit> commits = git.log().call(); PersonIdent testIdent = new PersonIdent(GIT_NAME, GIT_MAIL); PersonIdent[] expectedIdents = new PersonIdent[] { testIdent }; int c = 0; for (RevCommit commit : commits) { if (commit.getFullMessage().equals(GIT_COMMIT_MESSAGE)) { assertEquals(expectedIdents[expectedIdents.length - 1 - c].getName(), commit.getCommitterIdent().getName()); assertEquals(expectedIdents[expectedIdents.length - 1 - c].getEmailAddress(), commit.getCommitterIdent().getEmailAddress()); } c++; } assertEquals(2, c); }
From source file:org.eclipse.orion.server.tests.servlets.git.GitConfigTest.java
License:Open Source License
@Test public void testInitializedRepoConfigUsingUserProfile() throws Exception { // set Git name and mail in the user profile WebRequest request = getPutUserRequest(); WebResponse response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); // init a repo URI workspaceLocation = createWorkspace(getMethodName()); JSONObject project = createProjectOrLink(workspaceLocation, getMethodName(), null); IPath initPath = new Path("file").append(project.getString(ProtocolConstants.KEY_ID)).makeAbsolute(); String contentLocation = init(null, initPath, null).getString(ProtocolConstants.KEY_CONTENT_LOCATION); // check the repository configuration using JGit API Git git = new Git(getRepositoryForContentLocation(contentLocation)); StoredConfig config = git.getRepository().getConfig(); assertEquals(GIT_NAME,//from w w w .ja v a 2 s. c o m config.getString(ConfigConstants.CONFIG_USER_SECTION, null, ConfigConstants.CONFIG_KEY_NAME)); assertEquals(GIT_MAIL, config.getString(ConfigConstants.CONFIG_USER_SECTION, null, ConfigConstants.CONFIG_KEY_EMAIL)); // now check if commits have the right committer set request = getGetFilesRequest(project.getString(ProtocolConstants.KEY_CONTENT_LOCATION)); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); project = new JSONObject(response.getText()); String childrenLocation = project.getString(ProtocolConstants.KEY_CHILDREN_LOCATION); assertNotNull(childrenLocation); // check if Git locations are in place JSONObject gitSection = project.optJSONObject(GitConstants.KEY_GIT); assertNotNull(gitSection); String gitIndexUri = gitSection.getString(GitConstants.KEY_INDEX); String gitHeadUri = gitSection.getString(GitConstants.KEY_HEAD); // modify String projectLocation = project.getString(ProtocolConstants.KEY_LOCATION); request = getPutFileRequest(projectLocation + "/test.txt", "change to commit"); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); // add request = GitAddTest.getPutGitIndexRequest(gitIndexUri + "test.txt"); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); // commit all request = GitCommitTest.getPostGitCommitRequest(gitHeadUri /* all */, GIT_COMMIT_MESSAGE, false); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); // log // TODO: replace with RESTful API for git log when available Iterable<RevCommit> commits = git.log().call(); PersonIdent testIdent = new PersonIdent(GIT_NAME, GIT_MAIL); PersonIdent[] expectedIdents = new PersonIdent[] { testIdent }; int c = 0; for (RevCommit commit : commits) { if (commit.getFullMessage().equals(GIT_COMMIT_MESSAGE)) { assertEquals(expectedIdents[expectedIdents.length - 1 - c].getName(), commit.getCommitterIdent().getName()); assertEquals(expectedIdents[expectedIdents.length - 1 - c].getEmailAddress(), commit.getCommitterIdent().getEmailAddress()); } c++; } assertEquals(2, c); }
From source file:org.flowerplatform.web.git.GitUtils.java
License:Open Source License
/** * This method must be used to set user configuration before running * some GIT commands that uses it.//from ww w .ja v a 2 s . c om * * <p> * A lock/unlock on repository is done before/after the command is executed * because the configuration modifies the same file and this will not be * thread safe any more. */ public Object runGitCommandInUserRepoConfig(Repository repo, GitCommand<?> command) throws Exception { namedLockPool.lock(repo.getDirectory().getPath()); try { StoredConfig c = repo.getConfig(); c.load(); User user = (User) CommunicationPlugin.tlCurrentPrincipal.get().getUser(); c.setString(ConfigConstants.CONFIG_USER_SECTION, null, ConfigConstants.CONFIG_KEY_NAME, user.getName()); c.setString(ConfigConstants.CONFIG_USER_SECTION, null, ConfigConstants.CONFIG_KEY_EMAIL, user.getEmail()); c.save(); return command.call(); } catch (Exception e) { throw e; } finally { namedLockPool.unlock(repo.getDirectory().getPath()); } }
From source file:org.jboss.tools.openshift.egit.internal.test.util.TestRepository.java
License:Open Source License
public void setUserAndEmail(String user, String email) { StoredConfig config = repository.getConfig(); config.setString(ConfigConstants.CONFIG_USER_SECTION, null, ConfigConstants.CONFIG_KEY_NAME, user); config.setString(ConfigConstants.CONFIG_USER_SECTION, null, ConfigConstants.CONFIG_KEY_EMAIL, email); }