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 Project: onedev   Author: theonedev   File: ResolveMerger.java    License: 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 #2
Source Project: onedev   Author: theonedev   File: ResolveMerger.java    License: 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 #3
Source Project: netbeans   Author: apache   File: CleanCommand.java    License: 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 #4
Source Project: naturalize   Author: mast-group   File: RenamingDatasetExtractor.java    License: 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 #5
Source Project: naturalize   Author: mast-group   File: RepentDataParser.java    License: 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 #6
Source Project: naturalize   Author: mast-group   File: SvnToGitMapper.java    License: 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 #7
Source Project: proctor   Author: indeedeng   File: GitProctorCore.java    License: 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 #8
Source Project: gradle-gitsemver   Author: palantir   File: TagBasedVersionFactory.java    License: 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 #9
Source Project: gradle-gitsemver   Author: palantir   File: TagBasedVersionFactoryTest.java    License: 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 #10
Source Project: MergeProcessor   Author: aposin   File: GitMergeUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Resolve the conflicts.
 * 
 * @param conflicts the collection of current existing conflicts in the
 *                  repository
 */
private void resolveConflicts(final Collection<String> conflicts) {
	final List<String> conflicts2 = new ArrayList<>();
	conflicts2.addAll(conflicts);
	boolean isFixedOrCanceled = false;
	while (!isFixedOrCanceled) {
		switch (resolveConflictsByUser(conflicts2)) {
		case OPEN_REPOSITORY:
			MergeProcessorUtil.openFile(repo.getRepository().getWorkTree().toString());
			break;
		case RETRY:
			try {
				final Status call = repo.status().call();
				if (call.getConflicting().isEmpty()) {
					isFixedOrCanceled = true;
				} else {
					conflicts2.clear();
					conflicts2.addAll(call.getConflicting());
				}
			} catch (NoWorkTreeException | GitAPIException e) {
				exception = new MergeUnitException(
						String.format("Could not check the status of the local repository '%s'.", repo), e); //$NON-NLS-1$
				return;
			}
			break;
		case CANCEL:
		default:
			monitor.setCanceled(true);
			isFixedOrCanceled = true;
			break;
		}
	}
}
 
Example #11
Source Project: hop   Author: project-hop   File: UIGit.java    License: 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 #12
Source Project: ParallelGit   Author: beijunyi   File: AbstractParallelGitTest.java    License: 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 #13
Source Project: naturalize   Author: mast-group   File: SvnToGitMapper.java    License: 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 #14
Source Project: ParallelGit   Author: beijunyi   File: AbstractParallelGitTest.java    License: 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 #15
Source Project: XACML   Author: att   File: GitPushWindow.java    License: MIT License 5 votes vote down vote up
protected void	refreshStatus() {
	try {
		//
		// Grab our working repository
		//
		Path repoPath = ((XacmlAdminUI)getUI()).getUserGitPath();
		final Git git = Git.open(repoPath.toFile());
		//
		// Get our status
		//
		final String base;
		Status status;
		if (target == null) {
			base = ".";
		} else {
			Path relativePath = repoPath.relativize(Paths.get(target.getPath()));
			base = relativePath.toString();
		}
		if (logger.isDebugEnabled()) {
			logger.debug("Status on base: " + base);
		}
		status = git.status().addPath(base).call();
		//
		// Pass it to our container
		//
		this.container.refreshStatus(status);
		this.tableChanges.refreshRowCache();
	} catch (NoWorkTreeException | IOException | GitAPIException e) {
		String error = "Failed to refresh status: " + e.getLocalizedMessage();
		logger.error(error);
	}
}
 
Example #16
Source Project: gradle-gitsemver   Author: palantir   File: SemverGitflowPlugin.java    License: 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 #17
Source Project: gradle-gitsemver   Author: palantir   File: SemverGitflowPlugin.java    License: Apache License 2.0 5 votes vote down vote up
public static SemverVersion getRepoVersion(Project project, String prefix)
        throws NoWorkTreeException, IOException, GitAPIException {
    String repoLocation = project.getProjectDir().getAbsolutePath()
            + "/.git";
    Integer buildNumber = getBuildNumber();
    return RepoSemanticVersions.getRepoVersion(repoLocation, buildNumber, prefix);
}
 
Example #18
Source Project: gradle-gitsemver   Author: palantir   File: SemverGitflowPlugin.java    License: Apache License 2.0 5 votes vote down vote up
public static SemverVersion getRepoVersion(Project project)
        throws NoWorkTreeException, IOException, GitAPIException {
    String repoLocation = project.getProjectDir().getAbsolutePath()
            + "/.git";
    Integer buildNumber = getBuildNumber();
    return RepoSemanticVersions.getRepoVersion(repoLocation, buildNumber);
}
 
Example #19
Source Project: gradle-gitsemver   Author: palantir   File: SemverGitflowPlugin.java    License: Apache License 2.0 5 votes vote down vote up
public static SemverVersion getRepoTopoVersion(Project project)
        throws NoWorkTreeException, IOException, GitAPIException {
    String repoLocation = project.getProjectDir().getAbsolutePath()
            + "/.git";
    Integer buildNumber = getBuildNumber();
    return RepoSemanticVersions.getRepoTopoVersion(repoLocation, buildNumber);
}
 
Example #20
Source Project: gradle-gitsemver   Author: palantir   File: SemverGitflowPlugin.java    License: Apache License 2.0 5 votes vote down vote up
public static SemverVersion getRepoTopoVersion(Project project, String prefix)
        throws NoWorkTreeException, IOException, GitAPIException {
    String repoLocation = project.getProjectDir().getAbsolutePath()
            + "/.git";
    Integer buildNumber = getBuildNumber();
    return RepoSemanticVersions.getRepoTopoVersion(repoLocation, buildNumber, prefix);
}
 
Example #21
Source Project: gradle-gitsemver   Author: palantir   File: RepoSemanticVersions.java    License: 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 #22
Source Project: gradle-gitsemver   Author: palantir   File: RepoSemanticVersions.java    License: 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 #23
Source Project: gradle-gitsemver   Author: palantir   File: RepoSemanticVersions.java    License: 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 #24
Source Project: gradle-gitsemver   Author: palantir   File: PrintGitStatusTask.java    License: 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 #25
Source Project: gradle-gitsemver   Author: palantir   File: TagBasedVersionFactoryTest.java    License: 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 #26
Source Project: gradle-gitsemver   Author: palantir   File: TagBasedVersionFactoryTest.java    License: 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 #27
Source Project: gradle-gitsemver   Author: palantir   File: TagBasedVersionFactoryTest.java    License: 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 #28
Source Project: gradle-gitsemver   Author: palantir   File: TagBasedVersionFactoryTest.java    License: 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 #29
Source Project: gradle-gitsemver   Author: palantir   File: TagBasedVersionFactoryTest.java    License: 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 #30
Source Project: gradle-gitsemver   Author: palantir   File: TagBasedVersionFactoryTest.java    License: 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);
}