org.eclipse.jgit.errors.NoWorkTreeException Java Examples

The following examples show how to use org.eclipse.jgit.errors.NoWorkTreeException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TagBasedVersionFactoryTest.java    From gradle-gitsemver with Apache License 2.0 6 votes vote down vote up
private void validateUnstable(String expectedVersion,
                              int commitCount,
                              RevCommit headCommit,
                              Dirty dirty,
                              String firstModifier)
        throws NoWorkTreeException, IOException, GitAPIException {
    String headCommitId = headCommit.getId().abbreviate(7).name();
    String dirtyText = (dirty == Dirty.YES) ? ".dirty" : "";
    String expected = expectedVersion + firstModifier + commitCount + "+g"
            + headCommitId + dirtyText;
    SemverVersion version = versionFactory.createVersion(repo, null);
    Assert.assertEquals(expected, version.toString());
    Integer buildNumber = 123;
    String expectedWithBuildNumber = expectedVersion + firstModifier
            + commitCount + "+g" + headCommitId + ".b" + buildNumber
            + dirtyText;
    Assert.assertEquals(
            expectedWithBuildNumber,
            versionFactory.createVersion(repo, buildNumber).toString());
}
 
Example #2
Source File: ResolveMerger.java    From onedev with MIT License 6 votes vote down vote up
private void checkout() throws NoWorkTreeException, IOException {
	// Iterate in reverse so that "folder/file" is deleted before
	// "folder". Otherwise this could result in a failing path because
	// of a non-empty directory, for which delete() would fail.
	for (int i = toBeDeleted.size() - 1; i >= 0; i--) {
		String fileName = toBeDeleted.get(i);
		File f = new File(nonNullRepo().getWorkTree(), fileName);
		if (!f.delete())
			if (!f.isDirectory())
				failingPaths.put(fileName,
						MergeFailureReason.COULD_NOT_DELETE);
		modifiedFiles.add(fileName);
	}
	for (Map.Entry<String, DirCacheEntry> entry : toBeCheckedOut
			.entrySet()) {
		DirCacheEntry cacheEntry = entry.getValue();
		if (cacheEntry.getFileMode() == FileMode.GITLINK) {
			new File(nonNullRepo().getWorkTree(), entry.getKey()).mkdirs();
		} else {
			DirCacheCheckout.checkoutEntry(db, cacheEntry, reader, false,
					checkoutMetadata.get(entry.getKey()));
			modifiedFiles.add(entry.getKey());
		}
	}
}
 
Example #3
Source File: ResolveMerger.java    From onedev with MIT License 6 votes vote down vote up
/**
 * Reverts the worktree after an unsuccessful merge. We know that for all
 * modified files the old content was in the old index and the index
 * contained only stage 0. In case if inCore operation just clear the
 * history of modified files.
 *
 * @throws java.io.IOException
 * @throws org.eclipse.jgit.errors.CorruptObjectException
 * @throws org.eclipse.jgit.errors.NoWorkTreeException
 * @since 3.4
 */
protected void cleanUp() throws NoWorkTreeException,
		CorruptObjectException,
		IOException {
	if (inCore) {
		modifiedFiles.clear();
		return;
	}

	DirCache dc = nonNullRepo().readDirCache();
	Iterator<String> mpathsIt=modifiedFiles.iterator();
	while(mpathsIt.hasNext()) {
		String mpath = mpathsIt.next();
		DirCacheEntry entry = dc.getEntry(mpath);
		if (entry != null) {
			DirCacheCheckout.checkoutEntry(db, entry, reader, false,
					checkoutMetadata.get(mpath));
		}
		mpathsIt.remove();
	}
}
 
Example #4
Source File: CleanCommand.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void deleteIfUnversioned(DirCache cache, String path, WorkingTreeIterator f, Repository repository, TreeWalk treeWalk) throws IOException, NoWorkTreeException {
    if (cache.getEntry(path) == null &&  // not in index 
        !f.isEntryIgnored() &&             // not ignored
        !Utils.isFromNested(f.getEntryFileMode().getBits()))
    {            
        File file = new File(repository.getWorkTree().getAbsolutePath() + File.separator + path);                        
        if(file.isDirectory()) {
            String[] s = file.list();
            if(s != null && s.length > 0) { // XXX is there no better way to find out if empty?
                // not empty
                return; 
            }
        }
        file.delete();
        listener.notifyFile(file, treeWalk.getPathString());
    }
}
 
Example #5
Source File: RenamingDatasetExtractor.java    From naturalize with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static void main(final String[] args) throws NoWorkTreeException,
		NoHeadException, IOException, GitAPIException {
	if (args.length != 4) {
		System.err
				.println("Usage <datafile> <prefix> <repositoryDir> <outputFilePrefix>");
		System.exit(-1);
	}
	final SvnToGitMapper mapper = new SvnToGitMapper(args[2]);
	final RepentDataParser rdp = new RepentDataParser(new File(args[0]),
			mapper.mapSvnToGit(), args[1], new Predicate<Integer>() {

				@Override
				public boolean test(final Integer t) {
					return t > 250;
				}
			});
	final List<Renaming> renamings = rdp.parse();
	final Multimap<String, Renaming> renamingsPerSha = mapRenamingsToTargetSha(renamings);
	final BindingExtractor be = new BindingExtractor(args[2],
			renamingsPerSha);
	be.doWalk();

	writeJson(args[3], "_variables.json", be.renamedVariablesDatapoints);
	writeJson(args[3], "_methoddeclarations.json",
			be.renamedMethodDeclarationsDatapoints);
}
 
Example #6
Source File: RepentDataParser.java    From naturalize with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * @param args
 * @throws IOException
 * @throws GitAPIException
 * @throws NoHeadException
 * @throws NoWorkTreeException
 */
public static void main(final String[] args) throws IOException,
		NoWorkTreeException, NoHeadException, GitAPIException {
	if (args.length != 3) {
		System.err.println("Usage <datafile> <prefix> <repositoryDir>");
		System.exit(-1);
	}
	final SvnToGitMapper mapper = new SvnToGitMapper(args[2]);
	final RepentDataParser rdp = new RepentDataParser(new File(args[0]),
			mapper.mapSvnToGit(), args[1], new Predicate<Integer>() {

				@Override
				public boolean test(final Integer t) {
					return t < 250;
				}
			});
	final List<Renaming> renamings = rdp.parse();
	for (final Renaming renaming : renamings) {
		System.out.println(renaming);
	}
	System.out.println("Num Renamings: " + renamings.size());
}
 
Example #7
Source File: TagBasedVersionFactory.java    From gradle-gitsemver with Apache License 2.0 6 votes vote down vote up
public SemverVersion createVersion(Repository repo, Integer buildNumber, boolean topo)
    throws MissingObjectException, IncorrectObjectTypeException, IOException,
                      NoWorkTreeException, GitAPIException {
        if (repo == null) {
            throw new SemverGitflowPlugin.VersionApplicationException(
                    "Project is not in a Git repository. Cannot use semver versioning in a non repository.");
        }
        TagVersionAndCount latestTagAndCount;
        if (topo) {
            latestTagAndCount = Tags.getTopoTagVersionAndCount(repo, prefix);
        } else {
            latestTagAndCount = Tags.getLatestTagVersionAndCount(repo, prefix);
        }
        String headCommitAbbreviation = GitRepos.getHeadCommitIdAbbreviation(repo);
        boolean isDirty = GitRepos.isDirty(repo);
        return generateVersion(latestTagAndCount, headCommitAbbreviation, buildNumber, isDirty);
}
 
Example #8
Source File: SvnToGitMapper.java    From naturalize with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public BiMap<Integer, String> mapSvnToGit() throws IOException,
		NoWorkTreeException, NoHeadException, GitAPIException {
	final BiMap<Integer, String> mappings = HashBiMap.create();
	final Git repository = GitCommitUtils
			.getGitRepository(repositoryDirectory);

	for (final RevCommit commit : GitCommitUtils
			.getAllCommitsTopological(repository)) {
		final String message = commit.getFullMessage();
		if (!message.contains("git-svn-id")) {
			continue;
		}
		final Matcher matcher = svnIdMatcher.matcher(message);
		matcher.find();
		mappings.put(Integer.parseInt(matcher.group(1)), commit.name());
	}

	return mappings;
}
 
Example #9
Source File: GitProctorCore.java    From proctor with Apache License 2.0 6 votes vote down vote up
@Nullable
private Set<String> parseStagedTestNames() {
    try {
        final Status status = git.status().call();
        return Stream.of(
                status.getAdded(),
                status.getChanged(),
                status.getRemoved())
                .flatMap(Set::stream)
                .distinct()
                .map(s -> parseTestName(testDefinitionsDirectory, s))
                .filter(Objects::nonNull)
                .collect(Collectors.toSet());
    } catch (final GitAPIException | NoWorkTreeException e) {
        LOGGER.warn("Failed to call git status", e);
        return null;
    }
}
 
Example #10
Source File: RepoSemanticVersions.java    From gradle-gitsemver with Apache License 2.0 5 votes vote down vote up
public static SemverVersion getRepoVersion(String repoLocation, Integer buildNumber, String prefix)
    throws NoWorkTreeException, IOException, GitAPIException {
    Repository repo = getRepo(repoLocation);

    TagBasedVersionFactory versionFactory;
    if (prefix == null)
        versionFactory = new TagBasedVersionFactory();
    else
        versionFactory = new TagBasedVersionFactory(prefix);
    return versionFactory.createVersion(repo, buildNumber);
}
 
Example #11
Source File: RepoSemanticVersions.java    From gradle-gitsemver with Apache License 2.0 5 votes vote down vote up
public static Repository getRepo(String repoLocation)
       throws NoWorkTreeException, IOException, GitAPIException {
    Repository repo;
    try {
        repo = new FileRepositoryBuilder().readEnvironment()
                .findGitDir(new File(repoLocation)).build();
    } catch (IllegalArgumentException iae) {
        throw new SemverGitflowPlugin.VersionApplicationException(
                "Project is not in a Git repository. Cannot use semver versioning in a non repository.",
                iae);
    }
    return repo;
}
 
Example #12
Source File: RepoSemanticVersions.java    From gradle-gitsemver with Apache License 2.0 5 votes vote down vote up
public static SemverVersion getRepoTopoVersion(String repoLocation, Integer buildNumber, String prefix)
        throws NoWorkTreeException, IOException, GitAPIException {
    Repository repo = getRepo(repoLocation);

    TagBasedVersionFactory versionFactory;
    if (prefix == null) {
        versionFactory = new TagBasedVersionFactory();
    } else {
        versionFactory = new TagBasedVersionFactory(prefix);
    }
    return versionFactory.createTopoVersion(repo, buildNumber);
}
 
Example #13
Source File: PrintGitStatusTask.java    From gradle-gitsemver with Apache License 2.0 5 votes vote down vote up
@TaskAction
public void printStatus() throws NoWorkTreeException, IOException,
        GitAPIException {
    String repoLocation = project.getProjectDir().getAbsolutePath() + "/.git";
    Repository repo = RepoSemanticVersions.getRepo(repoLocation);
    GitRepos.printJgitStatus(repo);
}
 
Example #14
Source File: TagBasedVersionFactoryTest.java    From gradle-gitsemver with Apache License 2.0 5 votes vote down vote up
@Test
public void testHeadPointsAtStable() throws ConcurrentRefUpdateException,
        InvalidTagNameException, NoHeadException, GitAPIException,
        NoWorkTreeException, MissingObjectException,
        IncorrectObjectTypeException, IOException {
    tag("v1.0.0");
    validateStableTag("1.0.0");
}
 
Example #15
Source File: TagBasedVersionFactoryTest.java    From gradle-gitsemver with Apache License 2.0 5 votes vote down vote up
@Test
public void testHeadPointsAtStableWhenUsingPrefix() throws ConcurrentRefUpdateException,
        InvalidTagNameException, NoHeadException, GitAPIException,
        NoWorkTreeException, MissingObjectException,
        IncorrectObjectTypeException, IOException {
    versionFactory = new TagBasedVersionFactory("myPrefix");
    tag("myPrefix-v1.0.0");
    validateStableTag("1.0.0");
}
 
Example #16
Source File: TagBasedVersionFactoryTest.java    From gradle-gitsemver with Apache License 2.0 5 votes vote down vote up
@Test
public void testHeadPointsOneAboveStable()
        throws ConcurrentRefUpdateException, InvalidTagNameException,
        NoHeadException, GitAPIException, NoWorkTreeException,
        MissingObjectException, IncorrectObjectTypeException, IOException {
    tag("v1.0.0");
    RevCommit head = makeCommit();
    validateUnstable("1.0.0", 1, head, Dirty.NO, DOT);
}
 
Example #17
Source File: TagBasedVersionFactoryTest.java    From gradle-gitsemver with Apache License 2.0 5 votes vote down vote up
@Test
public void testHeadPointsAtUnstableTag() throws NoWorkTreeException,
        IOException, GitAPIException {
    RevCommit head = makeCommit();
    tag("v0.1.0-dev");
    validateUnstable("0.1.0-dev", 0, head, Dirty.NO, DOT);
}
 
Example #18
Source File: TagBasedVersionFactoryTest.java    From gradle-gitsemver with Apache License 2.0 5 votes vote down vote up
@Test
public void testHeadPointsAtCommitAboveStable() throws NoWorkTreeException,
        IOException, GitAPIException {
    tag("1.0.0");
    makeCommit();
    RevCommit commit = makeCommit();
    validateUnstable("1.0.0", 2, commit, Dirty.NO, DASH);
}
 
Example #19
Source File: TagBasedVersionFactoryTest.java    From gradle-gitsemver with Apache License 2.0 5 votes vote down vote up
@Test
public void testCommitCount() throws NoHeadException, NoMessageException,
        UnmergedPathsException, ConcurrentRefUpdateException,
        WrongRepositoryStateException, GitAPIException,
        NoWorkTreeException, IOException {
    tag("v0.1.1-rc");
    makeCommit();
    makeCommit();
    RevCommit head = makeCommit();
    validateUnstable("0.1.1-rc", 3, head, Dirty.NO, DOT);
}
 
Example #20
Source File: TagBasedVersionFactoryTest.java    From gradle-gitsemver with Apache License 2.0 5 votes vote down vote up
@Test
public void testVUnnecessary() throws ConcurrentRefUpdateException,
        InvalidTagNameException, NoHeadException, GitAPIException,
        NoWorkTreeException, IOException {
    makeCommit();
    tag("0.1.0");
    validateStableTag("0.1.0");
}
 
Example #21
Source File: TagBasedVersionFactoryTest.java    From gradle-gitsemver with Apache License 2.0 5 votes vote down vote up
@Test
public void testNonVersionedTagIsSkipped() throws NoWorkTreeException,
        IOException, GitAPIException {
    makeCommit();
    tag("v0.1.0");
    makeCommit();
    RevCommit head = makeCommit();
    tag("hello");
    validateUnstable("0.1.0", 2, head, Dirty.NO, DASH);
}
 
Example #22
Source File: TagBasedVersionFactoryTest.java    From gradle-gitsemver with Apache License 2.0 5 votes vote down vote up
@Test
public void testUnstableIsDirty() throws ConcurrentRefUpdateException,
        InvalidTagNameException, NoHeadException, GitAPIException,
        NoWorkTreeException, MissingObjectException,
        IncorrectObjectTypeException, IOException {
    RevCommit commit = makeCommit();
    tag("0.1.0-dev");
    dirtyRepo();
    validateUnstable("0.1.0-dev", 0, commit, Dirty.YES, DOT);
}
 
Example #23
Source File: TagBasedVersionFactoryTest.java    From gradle-gitsemver with Apache License 2.0 5 votes vote down vote up
@Test
public void testOrdering() throws ConcurrentRefUpdateException,
        InvalidTagNameException, NoHeadException, GitAPIException,
        NoWorkTreeException, MissingObjectException,
        IncorrectObjectTypeException, IOException {
    tag("3.0.0");
    makeCommit();
    RevCommit head = makeCommit();
    tag("1.0.0");
    validateUnstable("3.0.0", 2, head, Dirty.NO, DASH);
}
 
Example #24
Source File: TagBasedVersionFactoryTest.java    From gradle-gitsemver with Apache License 2.0 5 votes vote down vote up
@Test
public void testTwoTagsSameCommit() throws NoWorkTreeException,
        MissingObjectException, IncorrectObjectTypeException, IOException,
        GitAPIException {
    tag("1.0.0-rc");
    tag("1.0.0");
    validateStableTag("1.0.0");
}
 
Example #25
Source File: TagBasedVersionFactoryTest.java    From gradle-gitsemver with Apache License 2.0 5 votes vote down vote up
private void validateStableTag(String expectedVersion)
        throws NoWorkTreeException, MissingObjectException,
        IncorrectObjectTypeException, IOException, GitAPIException {
    SemverVersion version = versionFactory.createVersion(repo, null);
    Assert.assertEquals(expectedVersion, version.toString());
    SemverVersion versionBuild = versionFactory.createVersion(repo, 123);
    Assert.assertEquals(expectedVersion, versionBuild.toString());
}
 
Example #26
Source File: SemverGitflowPlugin.java    From gradle-gitsemver with Apache License 2.0 5 votes vote down vote up
@Override
public void apply(Project project) {
    try {
        SemverConvention convention = new SemverConvention(project);
        project.getConvention().getPlugins().put("semver", convention);
    } catch (NoWorkTreeException e) {
        throw new VersionApplicationException(e);
    }
}
 
Example #27
Source File: UIGit.java    From hop with Apache License 2.0 5 votes vote down vote up
private boolean hasUncommittedChanges() {
  try {
    return git.status().call().hasUncommittedChanges();
  } catch ( NoWorkTreeException | GitAPIException e ) {
    e.printStackTrace();
    return false;
  }
}
 
Example #28
Source File: AbstractParallelGitTest.java    From ParallelGit with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public File getWorkTree() throws NoWorkTreeException {
  if(workTree == null)
    throw new NoWorkTreeException();
  return workTree;
}
 
Example #29
Source File: SvnToGitMapper.java    From naturalize with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * @param args
 * @throws GitAPIException
 * @throws IOException
 * @throws NoHeadException
 * @throws NoWorkTreeException
 */
public static void main(final String[] args) throws NoWorkTreeException,
		NoHeadException, IOException, GitAPIException {
	if (args.length != 1) {
		System.err.println("Usage <repository>");
		System.exit(-1);
	}
	final SvnToGitMapper mapper = new SvnToGitMapper(args[0]);
	System.out.println(mapper.mapSvnToGit());
}
 
Example #30
Source File: AbstractParallelGitTest.java    From ParallelGit with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public File getWorkTree() throws NoWorkTreeException {
  if(workTree == null)
    throw new NoWorkTreeException();
  return workTree;
}