org.eclipse.jgit.api.TagCommand Java Examples

The following examples show how to use org.eclipse.jgit.api.TagCommand. 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: CreateTagCommand.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
protected void run () throws GitException {
    Repository repository = getRepository();
    try {
        RevObject obj = Utils.findObject(repository, taggedObject);
        TagCommand cmd = new Git(repository).tag();
        cmd.setName(tagName);
        cmd.setForceUpdate(forceUpdate);
        cmd.setObjectId(obj);
        cmd.setAnnotated(message != null && !message.isEmpty() || signed);
        if (cmd.isAnnotated()) {
            cmd.setMessage(message);
            cmd.setSigned(signed);
        }
        cmd.call();
        ListTagCommand tagCmd = new ListTagCommand(repository, getClassFactory(), false, new DelegatingGitProgressMonitor(monitor));
        tagCmd.run();
        Map<String, GitTag> tags = tagCmd.getTags();
        tag = tags.get(tagName);
    } catch (JGitInternalException | GitAPIException ex) {
        throw new GitException(ex);
    }
}
 
Example #2
Source File: Scenarios.java    From jgitver with Apache License 2.0 6 votes vote down vote up
private ScenarioBuilder tag(String tagName, boolean light, String id) {
    try {
        TagCommand tagCommand = git.tag().setName(tagName).setAnnotated(!light);

        if (id != null) {   // we do not tag on HEAD
            String commitId = scenario.getCommits().get(id).name();
            ObjectId objectId = repository.resolve(commitId);
            RevCommit commit = repository.parseCommit(objectId);
            tagCommand.setObjectId(commit);
        }

        tagCommand.call();
    } catch (Exception ex) {
        throw new IllegalStateException(String.format("cannot add tag: %s, lightweight[%s]", tagName, light), ex);
    }

    return this;
}
 
Example #3
Source File: Project.java    From onedev with MIT License 5 votes vote down vote up
public void createTag(String tagName, String tagRevision, PersonIdent taggerIdent, @Nullable String tagMessage) {
try {
	TagCommand tag = git().tag();
	tag.setName(tagName);
	if (tagMessage != null)
		tag.setMessage(tagMessage);
	tag.setTagger(taggerIdent);
	tag.setObjectId(getRevCommit(tagRevision, true));
	tag.call();
	
	String refName = GitUtils.tag2ref(tagName);
	cacheObjectId(refName, tag.getObjectId());
	
   	ObjectId commitId = tag.getObjectId().copy();
   	OneDev.getInstance(TransactionManager.class).runAfterCommit(new Runnable() {

		@Override
		public void run() {
	    	OneDev.getInstance(SessionManager.class).runAsync(new Runnable() {

				@Override
				public void run() {
					Project project = OneDev.getInstance(ProjectManager.class).load(getId());
					OneDev.getInstance(ListenerRegistry.class).post(
							new RefUpdated(project, refName, ObjectId.zeroId(), commitId));
				}
	    		
	    	});
		}
   		
   	});			
} catch (GitAPIException e) {
	throw new RuntimeException(e);
}
  }
 
Example #4
Source File: GitContentRepository.java    From studio with GNU General Public License v3.0 5 votes vote down vote up
@Override
public String createVersion(String site, String path, String comment, boolean majorVersion) {
    // SJ: Will ignore minor revisions since git handles that via write/commit
    // SJ: Major revisions become git tags
    // TODO: SJ: Redesign/refactor the whole approach in 3.1+
    String toReturn = EMPTY;

    synchronized (helper.getRepository(site, StringUtils.isEmpty(site) ? GLOBAL : PUBLISHED)) {
        if (majorVersion) {
            Repository repo = helper.getRepository(site, StringUtils.isEmpty(site) ? GLOBAL : PUBLISHED);
            // Tag the repository with a date-time based version label
            String gitPath = helper.getGitPath(path);

            try (Git git = new Git(repo)) {
                PersonIdent currentUserIdent = helper.getCurrentUserIdent();
                DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HHmmssX");
                Calendar cal = Calendar.getInstance();
                String versionLabel = dateFormat.format(cal.getTime());

                TagCommand tagCommand = git.tag()
                        .setName(versionLabel)
                        .setMessage(comment)
                        .setTagger(currentUserIdent);

                tagCommand.call();

                toReturn = versionLabel;

            } catch (GitAPIException | ServiceLayerException | UserNotFoundException err) {
                logger.error("error creating new version for site:  " + site + " path: " + path, err);
            }
        } else {
            logger.info("request to create minor revision ignored for site: " + site + " path: " + path);
        }
    }

    return toReturn;
}