List of usage examples for org.eclipse.jgit.lib Constants DOT_GIT_EXT
String DOT_GIT_EXT
To view the source code for org.eclipse.jgit.lib Constants DOT_GIT_EXT.
Click Source Link
From source file:com.google.gerrit.sshd.commands.CreateProject.java
License:Apache License
private void validateParameters() throws Failure { if (projectName.endsWith(Constants.DOT_GIT_EXT)) { projectName = projectName.substring(0, // projectName.length() - Constants.DOT_GIT_EXT.length()); }//from ww w. j a va2s. c om if (!CollectionsUtil.isAnyIncludedIn(currentUser.getEffectiveGroups(), projectCreatorGroups)) { throw new Failure(1, "fatal: Not permitted to create " + projectName); } if (ownerIds != null && !ownerIds.isEmpty()) { ownerIds = new ArrayList<AccountGroup.UUID>(new HashSet<AccountGroup.UUID>(ownerIds)); } else { ownerIds = new ArrayList<AccountGroup.UUID>(projectOwnerGroups); } while (branch.startsWith("/")) { branch = branch.substring(1); } if (!branch.startsWith(Constants.R_HEADS)) { branch = Constants.R_HEADS + branch; } if (!Repository.isValidRefName(branch)) { throw new Failure(1, "--branch \"" + branch + "\" is not a valid name"); } }
From source file:net.community.chest.gitcloud.facade.backend.git.BackendRepositoryResolverTest.java
License:Apache License
@Test public void testOpenExistingRepository() throws Exception { final String REPO_NAME = "testOpenExistingRepository"; File expected = new File(reposDir, REPO_NAME + Constants.DOT_GIT_EXT); if (!expected.exists()) { Repository repo = new FileRepository(expected); try {/*ww w.ja v a 2 s .c om*/ repo.create(true); } finally { repo.close(); } } else { assertTrue("Test repo not a folder: " + expected, expected.isDirectory()); } for (String ext : TEST_EXTS) { Repository repo = resolver.open(null, REPO_NAME + ext); assertNotNull("No resolution result for ext=" + ext, repo); try { File actual = repo.getDirectory(); assertEquals("Mismatched resolved location for ext=" + ext, expected, actual); } finally { repo.close(); } } }
From source file:net.community.chest.gitcloud.facade.backend.git.BackendRepositoryResolverTest.java
License:Apache License
@Test public void testOpenNonExistingRepository() throws Exception { final String REPO_NAME = "testOpenNonExistingRepository"; File gitDir = new File(reposDir, REPO_NAME + Constants.DOT_GIT_EXT); FileUtils.deleteDirectory(gitDir);//from www. j a va2 s .c o m assertFalse("Failed to delete " + gitDir, gitDir.exists()); for (String ext : TEST_EXTS) { try { Repository repo = resolver.open(null, REPO_NAME + ext); try { fail("Unexpected success for ext=" + ext + ": " + repo.getDirectory()); } finally { repo.close(); } } catch (RepositoryNotFoundException e) { // expected - ignored } } }
From source file:net.community.chest.gitcloud.facade.backend.git.BackendRepositoryResolverTest.java
License:Apache License
@Test public void testDeepDownRepositoryResolution() throws Exception { final String REPO_NAME = "testDeepDownRepositoryResolution", GIT_NAME = REPO_NAME + Constants.DOT_GIT_EXT; final int MAX_DEPTH = Byte.SIZE; StringBuilder sb = new StringBuilder(MAX_DEPTH + Long.SIZE); File parentDir = reposDir;/*from www .jav a2 s.c om*/ for (int depth = 0; depth < MAX_DEPTH; depth++) { String subName = String.valueOf(depth); parentDir = new File(parentDir, subName); sb.append(subName).append('/'); File gitDir = new File(parentDir, GIT_NAME); if (!gitDir.exists()) { Repository repo = new FileRepository(gitDir); try { repo.create(true); } finally { repo.close(); } } else { assertTrue("Child repo not a folder: " + gitDir, gitDir.isDirectory()); } int curLen = sb.length(); try { sb.append(REPO_NAME); int baseLen = sb.length(); for (String ext : TEST_EXTS) { try { Repository repo = resolver.open(null, sb.append(ext).toString()); assertNotNull("No resolution result for ext=" + ext, repo); try { File actual = repo.getDirectory(); assertEquals("Mismatched resolved location for ext=" + ext, gitDir, actual); } finally { repo.close(); } } finally { sb.setLength(baseLen); } } } finally { sb.setLength(curLen); } } }
From source file:net.community.chest.gitcloud.facade.frontend.git.GitController.java
License:Apache License
public static final String extractRepositoryName(String uriPath) { if (StringUtils.isEmpty(uriPath)) { return null; }/*from w w w . j a va 2 s. c o m*/ int gitPos = uriPath.indexOf(Constants.DOT_GIT_EXT); if (gitPos <= 0) { return null; } int startPos = gitPos; for (; startPos >= 0; startPos--) { if (uriPath.charAt(startPos) == '/') { startPos++; break; } } if (startPos < 0) { startPos = 0; // in case did not start with '/' } int endPos = gitPos; for (; endPos < uriPath.length(); endPos++) { if (uriPath.charAt(endPos) == '/') { break; } } String pureName = uriPath.substring(startPos, endPos); if (Constants.DOT_GIT_EXT.equals(pureName)) { return null; } else { return pureName; } }
From source file:net.community.chest.gitcloud.facade.frontend.git.GitControllerTest.java
License:Apache License
@Test public void testExtractRepositoryNameFromValidPaths() { final String expected = "testExtractRepositoryName" + Constants.DOT_GIT_EXT; List<String> prefixes = Collections.unmodifiableList(Arrays.asList("", "/", "/l/y/o/r/")); List<String> suffixes = Collections.unmodifiableList(Arrays.asList("", "/", "/r/o/y/l")); for (String prfx : prefixes) { for (String sfx : suffixes) { String uriPath = prfx + expected + sfx; String actual = GitController.extractRepositoryName(uriPath); assertEquals("Mismatched name for path=" + uriPath, expected, actual); }// w ww . j a va2s . c o m } }
From source file:net.community.chest.gitcloud.facade.frontend.git.GitControllerTest.java
License:Apache License
@Test public void testExtractRepositoryNameFromInvalidPaths() { for (String uriPath : new String[] { null, "", Constants.DOT_GIT_EXT, "/" + Constants.DOT_GIT_EXT, "/no/dot/git" }) { assertNull("Unexpected name for " + uriPath, GitController.extractRepositoryName(uriPath)); }//from w w w .j ava2s. c om }
From source file:org.eclipse.egit.core.internal.ProjectReferenceImporter.java
License:Open Source License
private static File cloneIfNecessary(final URIish gitUrl, final String branch, final IPath workDir, final Set<ProjectReference> projects, IProgressMonitor monitor) throws TeamException, InterruptedException { final File repositoryPath = workDir.append(Constants.DOT_GIT_EXT).toFile(); if (workDir.toFile().exists()) { if (repositoryAlreadyExistsForUrl(repositoryPath, gitUrl)) return repositoryPath; else {//w w w . jav a 2 s . co m final Collection<String> projectNames = new LinkedList<String>(); for (final ProjectReference projectReference : projects) projectNames.add(projectReference.getProjectDir()); throw new TeamException(NLS.bind(CoreText.GitProjectSetCapability_CloneToExistingDirectory, new Object[] { workDir, projectNames, gitUrl })); } } else { try { int timeout = 60; String refName = Constants.R_HEADS + branch; final CloneOperation cloneOperation = new CloneOperation(gitUrl, true, null, workDir.toFile(), refName, Constants.DEFAULT_REMOTE_NAME, timeout); cloneOperation.run(monitor); return repositoryPath; } catch (final InvocationTargetException e) { throw getTeamException(e); } } }