List of usage examples for org.eclipse.jgit.lib Repository stripWorkDir
@NonNull public static String stripWorkDir(File workDir, File file)
From source file:ch.sourcepond.maven.release.providers.DefaultRootProject.java
License:Apache License
@Override public String calculateModulePath(final MavenProject project) throws ReactorException { // Getting canonical files because on Windows, it's possible one returns // "C:\..." and the other "c:\..." which is rather amazing File projectRoot;/*from ww w . j av a 2 s . c o m*/ File moduleRoot; try { projectRoot = getProject().getBasedir().getCanonicalFile(); moduleRoot = project.getBasedir().getCanonicalFile(); } catch (final IOException e) { throw new ReactorException(e, "Could not find directory paths for maven project"); } String relativePathToModule = Repository.stripWorkDir(projectRoot, moduleRoot); if (relativePathToModule.length() == 0) { relativePathToModule = "."; } return relativePathToModule; }
From source file:ch.sourcepond.maven.release.scm.git.GitRepository.java
License:Apache License
@Override public void revertChanges(final Collection<File> changedFiles) throws SCMException { try {// w w w .jav a 2 s.c o m final File workTree = getGit().getRepository().getWorkTree().getCanonicalFile(); final SCMException exception = new SCMException("Reverting changed POMs failed!"); for (final File changedFile : changedFiles) { try { final String pathRelativeToWorkingTree = Repository.stripWorkDir(workTree, changedFile); getGit().checkout().addPath(pathRelativeToWorkingTree).call(); } catch (final Exception e) { exception.add( " * Unable to revert changes to %s - you may need to manually revert this file. Error was: %s", changedFile, e.getMessage()); } } if (!exception.getMessages().isEmpty()) { throw exception; } } catch (NoWorkTreeException | IOException e) { throw new SCMException(e, "Working directory could not be determined!"); } }
From source file:ch.sourcepond.maven.release.scm.git.GitRepository.java
License:Apache License
@Override public void pushChanges(final Collection<File> changedFiles) throws SCMException { try {/*from www . j a va 2 s. com*/ final File workTree = getGit().getRepository().getWorkTree().getCanonicalFile(); for (final File changedFile : changedFiles) { final String pathRelativeToWorkingTree = Repository.stripWorkDir(workTree, changedFile); getGit().add().setUpdate(true).addFilepattern(pathRelativeToWorkingTree).call(); } getGit().commit().setMessage(SNAPSHOT_COMMIT_MESSAGE).call(); if (config.getRemoteUrlOrNull() != null) { getGit().push().setRemote(config.getRemoteUrlOrNull()).call(); } } catch (final GitAPIException | IOException e) { throw new SCMException(e, "Changed POM files could not be committed and pushed!"); } }
From source file:org.debian.dependency.sources.TestJGitSource.java
License:Apache License
/** * If we've initialized a work branch (removed bad files), and they are there again on second init, we assume the user knows * what they are doing./*w w w . j a v a 2 s . co m*/ */ @Test public void testBadFilesAfterInit() throws Exception { File clazz1 = File.createTempFile("SomeClass", ".class", directory); File jar1 = File.createTempFile("some-jar", ".jar", directory); File subdir = new File(directory, "subdir"); subdir.mkdirs(); File clazz2 = File.createTempFile("AnotherClass", ".class", subdir); File jar2 = File.createTempFile("another-jar", ".jar", subdir); git.add().addFilepattern(".").call(); git.commit().setMessage("Add bad files for test").call(); git.checkout().setCreateBranch(true).setName(WORK_BRANCH).call(); // perform test source.initialize(directory, ORIGIN); DirCache dirCache = git.getRepository().readDirCache(); assertTrue("Class file put there after setup is vaild", dirCache.findEntry(Repository.stripWorkDir(directory, clazz1)) >= 0); assertTrue("Class file put there after setup is vaild", dirCache.findEntry(Repository.stripWorkDir(directory, clazz2)) >= 0); assertTrue("Jar file put there after setup is vaild", dirCache.findEntry(Repository.stripWorkDir(directory, jar1)) >= 0); assertTrue("Jar file put there after setup is vaild", dirCache.findEntry(Repository.stripWorkDir(directory, jar2)) >= 0); }
From source file:org.eclipse.egit.core.synchronize.GitResourceVariantComparatorTest.java
License:Open Source License
/** * Comparing two folders that have different path should return false. * * @throws Exception//from ww w.j a v a 2 s.com */ @Test @SuppressWarnings("boxing") public void shouldReturnFalseWhenComparingContainerAndContainer() throws Exception { // when GitResourceVariantComparator grvc = new GitResourceVariantComparator(null); // given IPath localPath = createMock(IPath.class); replay(localPath); IContainer local = createMock(IContainer.class); expect(local.exists()).andReturn(true).times(2); expect(local.getFullPath()).andReturn(localPath); replay(local); File file = testRepo.createFile(iProject, "test" + File.separator + "keep"); RevCommit commit = testRepo.addAndCommit(iProject, file, "initial commit"); String path = Repository.stripWorkDir(repo.getWorkTree(), file); GitFolderResourceVariant remote = new GitFolderResourceVariant(repo, null, commit.getTree(), path); // then assertFalse(grvc.compare(local, remote)); verify(local, localPath); }
From source file:org.eclipse.egit.core.synchronize.GitResourceVariantComparatorTest.java
License:Open Source License
/** * When comparing two folders that have same path, compare() method should * return true.// w w w .j a va 2 s . c o m * * @throws Exception */ @Test @SuppressWarnings("boxing") public void shouldReturnTrueWhenComparingContainerAndContainer() throws Exception { // when GitResourceVariantComparator grvc = new GitResourceVariantComparator(null); // given File file = testRepo.createFile(iProject, "test" + File.separator + "keep"); RevCommit commit = testRepo.addAndCommit(iProject, file, "initial commit"); String path = Repository.stripWorkDir(repo.getWorkTree(), file); IPath iPath = new Path(File.separator + path); IContainer local = createMock(IContainer.class); expect(local.exists()).andReturn(true).times(2); expect(local.getFullPath()).andReturn(iPath).anyTimes(); replay(local); GitFolderResourceVariant remote = new GitFolderResourceVariant(repo, null, commit.getTree(), path); // then assertTrue(grvc.compare(local, remote)); verify(local); }
From source file:org.eclipse.egit.core.synchronize.GitResourceVariantComparatorTest.java
License:Open Source License
/** * When comparing file that don't exist in base, but exists in remote * compare method should return false./*w w w . ja va 2 s. c o m*/ * * @throws Exception */ @Test public void shouldReturnFalseWhenBaseDoesntExist() throws Exception { // when GitResourceVariantComparator grvc = new GitResourceVariantComparator(null); // given RevCommit baseCommit = testRepo.createInitialCommit("initial commit"); testRepo.createAndCheckoutBranch(Constants.HEAD, Constants.R_HEADS + "test"); File file = testRepo.createFile(iProject, "test-file"); RevCommit remoteCommit = testRepo.addAndCommit(iProject, file, "second commit"); String path = Repository.stripWorkDir(repo.getWorkTree(), file); GitBlobResourceVariant base = new GitBlobResourceVariant(repo, null, baseCommit.getTree(), path); GitBlobResourceVariant remote = new GitBlobResourceVariant(repo, null, remoteCommit.getTree(), path); // then assertFalse(grvc.compare(base, remote)); }
From source file:org.eclipse.egit.core.synchronize.GitResourceVariantComparatorTest.java
License:Open Source License
/** * Compare() should return false when remote file does not exists, but * equivalent local file exist.// ww w. ja v a2 s .c o m * * @throws Exception */ @Test public void shouldReturnFalseWhenRemoteVariantDoesntExist() throws Exception { // when GitResourceVariantComparator grvc = new GitResourceVariantComparator(null); // given RevCommit remoteCommit = testRepo.createInitialCommit("initial commit"); testRepo.createAndCheckoutBranch(Constants.HEAD, Constants.R_HEADS + "test"); File file = testRepo.createFile(iProject, "test-file"); RevCommit baseCommit = testRepo.addAndCommit(iProject, file, "second commit"); String path = Repository.stripWorkDir(repo.getWorkTree(), file); GitBlobResourceVariant base = new GitBlobResourceVariant(repo, null, baseCommit.getTree(), path); GitBlobResourceVariant remote = new GitBlobResourceVariant(repo, null, remoteCommit.getTree(), path); // then assertFalse(grvc.compare(base, remote)); }
From source file:org.eclipse.egit.core.synchronize.GitResourceVariantComparatorTest.java
License:Open Source License
/** * Return false when comparing incompatible types (file against folder) that * also maps onto different resources//from w ww. j av a2s.c o m * * @throws Exception */ @Test public void shouldReturnFalseWhenComparingRemoteVariantFileWithContainer() throws Exception { // when GitResourceVariantComparator grvc = new GitResourceVariantComparator(null); // given File file = testRepo.createFile(iProject, "test" + File.separator + "keep"); RevCommit commit = testRepo.addAndCommit(iProject, file, "initial commit"); String filePath = Repository.stripWorkDir(repo.getWorkTree(), file); String folderPath = Repository.stripWorkDir(repo.getWorkTree(), new File(file.getParent())); GitBlobResourceVariant base = new GitBlobResourceVariant(repo, null, commit.getTree(), filePath); GitFolderResourceVariant remote = new GitFolderResourceVariant(repo, null, commit.getTree(), folderPath); // then assertFalse(grvc.compare(base, remote)); }
From source file:org.eclipse.egit.core.synchronize.GitResourceVariantComparatorTest.java
License:Open Source License
/** * Return false when comparing incompatible types (folder against file) that * also map onto different resources/*w ww .ja va 2 s .co m*/ * * @throws Exception */ @Test public void shouldReturnFalseWhenComparingRemoteVariantContainerWithFile() throws Exception { // when GitResourceVariantComparator grvc = new GitResourceVariantComparator(null); // given File file = testRepo.createFile(iProject, "test" + File.separator + "keep"); RevCommit commit = testRepo.addAndCommit(iProject, file, "initial commit"); String filePath = Repository.stripWorkDir(repo.getWorkTree(), file); String folderPath = Repository.stripWorkDir(repo.getWorkTree(), new File(file.getParent())); GitFolderResourceVariant base = new GitFolderResourceVariant(repo, null, commit.getTree(), folderPath); GitBlobResourceVariant remote = new GitBlobResourceVariant(repo, null, commit.getTree(), filePath); // then assertFalse(grvc.compare(base, remote)); }