org.eclipse.jgit.api.errors.NoHeadException Java Examples

The following examples show how to use org.eclipse.jgit.api.errors.NoHeadException. 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: GitWorkspaceSync.java    From milkman with MIT License 6 votes vote down vote up
private Git refreshRepository(GitSyncDetails syncDetails, File syncDir)
		throws GitAPIException, InvalidRemoteException, TransportException, IOException,
		WrongRepositoryStateException, InvalidConfigurationException, CanceledException, RefNotFoundException,
		RefNotAdvertisedException, NoHeadException {
	Git repo;
	if (!syncDir.exists()) {
		syncDir.mkdirs();
		repo = initWith(Git.cloneRepository(), syncDetails)
			.setURI(syncDetails.getGitUrl())
			.setDirectory(syncDir)
			.setCloneAllBranches(true)
			.setBranch("master")
			.call();
		
		
	} else {
		repo = Git.open(syncDir);
		initWith(repo.pull(), syncDetails)
			.call();
	}
	return repo;
}
 
Example #2
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 #3
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 #4
Source File: DevicesGit.java    From Flashtool with GNU General Public License v3.0 6 votes vote down vote up
public static void pullRepository() {
	try {
 	logger.info("Scanning devices folder for changes.");
 	git.add().addFilepattern(".").call();
 	Status status = git.status().call();
 	if (status.getChanged().size()>0 || status.getAdded().size()>0 || status.getModified().size()>0) {
 		logger.info("Changes have been found. Doing a hard reset (removing user modifications).");
 		ResetCommand reset = git.reset();
 		reset.setMode(ResetType.HARD);
 		reset.setRef(Constants.HEAD);
 		reset.call();
 	}
 	logger.info("Pulling changes from github.");
 	git.pull().call();
	} catch (NoHeadException e) {
		logger.info("Pull failed. Trying to clone repository instead");
		closeRepository();
		cloneRepository();
	}
	catch (Exception e1) {
		closeRepository();
	}
}
 
Example #5
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 #6
Source File: JGitUtil.java    From mcg-helper with Apache License 2.0 5 votes vote down vote up
public static boolean pull(String projectPath, String branch, String user, String pwd) throws IOException, WrongRepositoryStateException, InvalidConfigurationException, InvalidRemoteException, CanceledException, RefNotFoundException, RefNotAdvertisedException, NoHeadException, TransportException, GitAPIException {

		try (Git git = Git.open(new File(projectPath)) ) {
			UsernamePasswordCredentialsProvider provider = new UsernamePasswordCredentialsProvider(user, pwd);
			git.pull().setRemoteBranchName(branch)
					.setCredentialsProvider(provider)
					.setProgressMonitor(new PullProgressMonitor())
					.call();
		}
		
		return true;
	}
 
Example #7
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 #8
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 #9
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 #10
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 #11
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 #12
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 #13
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 #14
Source File: TagBasedVersionFactoryTest.java    From gradle-gitsemver with Apache License 2.0 5 votes vote down vote up
@Before
public void createVersionFactory() throws IOException, NoHeadException,
        NoMessageException, UnmergedPathsException,
        ConcurrentRefUpdateException, WrongRepositoryStateException,
        GitAPIException {
    repo = createRepository();
    git = initializeGitFlow(repo);
    versionFactory = new TagBasedVersionFactory();
}
 
Example #15
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 #16
Source File: ChurnRateCalculator.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
public void setRemoreCommits() throws IOException, RevisionSyntaxException, NoHeadException, GitAPIException {
	System.out.println(localPath + "/.git");

	/////////////////////// this should be move to an instance variable

	// stores into appropriate instance variables (HashMap localCommits) the commits
	// of each branch
	for (int i = 0; i < remoteBranches.size(); i++) {

		// for each branch create a list of lists with the total commits
		// the next for loop stores the list of all commits of each branch
		// to allCommitsSpecificBranchRemote list and then add that list to allCommits
		// list
		List<String> allCommitsSpecificBranchRemote = new ArrayList<>();

		// loop for each commit of all the commits of each branch
		for (RevCommit commit : repo.log().add(myrepo.resolve(remoteBranches.get(i))).call()) {

			allCommitsSpecificBranchRemote.add(commit.getName());

		}

		// after each loop it adds allCommitsSpecificBranchRemote List to allCommits
		// list of lists
		// allCommits.add(allCommitsSpecificBranchRemote);

		// stores all commits lists with key value of a specific branch to hashmap
		// remoteCommits
		remoteCommits.put(remoteBranches.get(i), allCommitsSpecificBranchRemote);
		// remoteCommits.put(remoteBranches.get(i), allCommits.get(i));

	}

	this.getCommits(remoteCommits);

	// myrepo.close();

}
 
Example #17
Source File: GitUtils.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
private static void pull(final Git git, ProgressMonitor monitor)
		throws GitAPIException, WrongRepositoryStateException,
		InvalidConfigurationException, InvalidRemoteException, CanceledException, RefNotFoundException,
		RefNotAdvertisedException, NoHeadException, TransportException {

	git.pull().setTransportConfigCallback(TRANSPORT_CALLBACK).setProgressMonitor(monitor).call();
}
 
Example #18
Source File: GitUtils.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
private static void pull(final Git git, IProgressMonitor monitor)
		throws GitAPIException, WrongRepositoryStateException,
		InvalidConfigurationException, InvalidRemoteException, CanceledException, RefNotFoundException,
		RefNotAdvertisedException, NoHeadException, TransportException {

	@SuppressWarnings("restriction")
	ProgressMonitor gitMonitor = (null == monitor) ? createMonitor()
			: new org.eclipse.egit.core.EclipseGitProgressTransformer(monitor);
	pull(git, gitMonitor);
}
 
Example #19
Source File: GitControl.java    From juneau with Apache License 2.0 4 votes vote down vote up
public void pullFromRepo()
		throws IOException, WrongRepositoryStateException, InvalidConfigurationException, DetachedHeadException,
		InvalidRemoteException, CanceledException, RefNotFoundException, NoHeadException, GitAPIException {
	git.pull().call();
}
 
Example #20
Source File: GitControl.java    From juneau with Apache License 2.0 4 votes vote down vote up
public void commitToRepo(String message) throws IOException, NoHeadException, NoMessageException,
		ConcurrentRefUpdateException, JGitInternalException, WrongRepositoryStateException, GitAPIException {
	git.commit().setMessage(message).call();
}
 
Example #21
Source File: GitFlowMetaData.java    From nifi-registry with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public void loadGitRepository(File gitProjectRootDir) throws IOException, GitAPIException {
    gitRepo = openRepository(gitProjectRootDir);

    try (final Git git = new Git(gitRepo)) {

        // Check if remote exists.
        if (!isEmpty(remoteToPush)) {
            final List<RemoteConfig> remotes = git.remoteList().call();
            final boolean isRemoteExist = remotes.stream().anyMatch(remote -> remote.getName().equals(remoteToPush));
            if (!isRemoteExist) {
                final List<String> remoteNames = remotes.stream().map(RemoteConfig::getName).collect(Collectors.toList());
                throw new IllegalArgumentException(
                        format("The configured remote '%s' to push does not exist. Available remotes are %s", remoteToPush, remoteNames));
            }
        }

        boolean isLatestCommit = true;
        try {
            for (RevCommit commit : git.log().call()) {
                final String shortCommitId = commit.getId().abbreviate(7).name();
                logger.debug("Processing a commit: {}", shortCommitId);
                final RevTree tree = commit.getTree();

                try (final TreeWalk treeWalk = new TreeWalk(gitRepo)) {
                    treeWalk.addTree(tree);

                    // Path -> ObjectId
                    final Map<String, ObjectId> bucketObjectIds = new HashMap<>();
                    final Map<String, ObjectId> flowSnapshotObjectIds = new HashMap<>();
                    while (treeWalk.next()) {
                        if (treeWalk.isSubtree()) {
                            treeWalk.enterSubtree();
                        } else {
                            final String pathString = treeWalk.getPathString();
                            // TODO: what is this nth?? When does it get grater than 0? Tree count seems to be always 1..
                            if (pathString.endsWith("/" + BUCKET_FILENAME)) {
                                bucketObjectIds.put(pathString, treeWalk.getObjectId(0));
                            } else if (pathString.endsWith(GitFlowPersistenceProvider.SNAPSHOT_EXTENSION)) {
                                flowSnapshotObjectIds.put(pathString, treeWalk.getObjectId(0));
                            }
                        }
                    }

                    if (bucketObjectIds.isEmpty()) {
                        // No bucket.yml means at this point, all flows are deleted. No need to scan older commits because those are already deleted.
                        logger.debug("Tree at commit {} does not contain any " + BUCKET_FILENAME + ". Stop loading commits here.", shortCommitId);
                        return;
                    }

                    loadBuckets(gitRepo, commit, isLatestCommit, bucketObjectIds, flowSnapshotObjectIds);
                    isLatestCommit = false;
                }
            }
        } catch (NoHeadException e) {
            logger.debug("'{}' does not have any commit yet. Starting with empty buckets.", gitProjectRootDir);
        }

    }
}
 
Example #22
Source File: LogCommand.java    From orion.server with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Executes the {@code Log} command with all the options and parameters collected by the setter methods (e.g. {@link #add(AnyObjectId)},
 * {@link #not(AnyObjectId)}, ..) of this class. Each instance of this class should only be used for one invocation of the command. Don't call this method
 * twice on an instance.
 *
 * @return an iteration over RevCommits
 * @throws NoHeadException
 *             of the references ref cannot be resolved
 */
@Override
public Iterable<RevCommit> call() throws GitAPIException, NoHeadException {
	checkCallable();
	ArrayList<RevFilter> filters = new ArrayList<RevFilter>();

	if (pathFilters.size() > 0)
		walk.setTreeFilter(AndTreeFilter.create(PathFilterGroup.create(pathFilters), TreeFilter.ANY_DIFF));

	if (msgFilter != null)
		filters.add(msgFilter);
	if (authorFilter != null)
		filters.add(authorFilter);
	if (committerFilter != null)
		filters.add(committerFilter);
	if (sha1Filter != null)
		filters.add(sha1Filter);
	if (dateFilter != null)
		filters.add(dateFilter);
	if (skip > -1)
		filters.add(SkipRevFilter.create(skip));
	if (maxCount > -1)
		filters.add(MaxCountRevFilter.create(maxCount));
	RevFilter filter = null;
	if (filters.size() > 1) {
		filter = AndRevFilter.create(filters);
	} else if (filters.size() == 1) {
		filter = filters.get(0);
	}

	if (filter != null)
		walk.setRevFilter(filter);

	if (!startSpecified) {
		try {
			ObjectId headId = repo.resolve(Constants.HEAD);
			if (headId == null)
				throw new NoHeadException(JGitText.get().noHEADExistsAndNoExplicitStartingRevisionWasSpecified);
			add(headId);
		} catch (IOException e) {
			// all exceptions thrown by add() shouldn't occur and represent
			// severe low-level exception which are therefore wrapped
			throw new JGitInternalException(JGitText.get().anExceptionOccurredWhileTryingToAddTheIdOfHEAD, e);
		}
	}
	setCallable(false);
	return walk;
}
 
Example #23
Source File: GitUtils.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
private static void pull(final Git git) throws GitAPIException, WrongRepositoryStateException,
		InvalidConfigurationException, InvalidRemoteException, CanceledException, RefNotFoundException,
		RefNotAdvertisedException, NoHeadException, TransportException {

	pull(git, (ProgressMonitor) null);
}
 
Example #24
Source File: TagBasedVersionFactoryTest.java    From gradle-gitsemver with Apache License 2.0 4 votes vote down vote up
private Ref tag(String tagName) throws ConcurrentRefUpdateException,
        InvalidTagNameException, NoHeadException, GitAPIException {
    return git.tag().setMessage("blah").setName(tagName).call();
}
 
Example #25
Source File: TagBasedVersionFactoryTest.java    From gradle-gitsemver with Apache License 2.0 4 votes vote down vote up
private RevCommit makeCommit() throws NoHeadException, NoMessageException,
        UnmergedPathsException, ConcurrentRefUpdateException,
        WrongRepositoryStateException, GitAPIException {
    return git.commit().setCommitter(COMMITTER).setMessage("some commit").call();
}