Example usage for org.eclipse.jgit.lib PersonIdent PersonIdent

List of usage examples for org.eclipse.jgit.lib PersonIdent PersonIdent

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib PersonIdent PersonIdent.

Prototype

private PersonIdent(UserConfig config) 

Source Link

Usage

From source file:com.google.appraise.eclipse.core.client.git.AppraiseGitReviewClient.java

License:Open Source License

/**
 * Creates a new client for the given git repository.
 *///from w w w  . j a v  a 2s  .  co  m
public AppraiseGitReviewClient(Repository repo) {
    this.repo = repo;
    this.author = new PersonIdent(repo);
}

From source file:com.mangosolutions.rcloud.rawgist.repository.git.BareCommitCommand.java

/**
 * Sets default values for not explicitly specified options. Then validates
 * that all required data has been provided.
 *
 * @param state//from   w ww .j  a  v  a 2  s.  c  o m
 *            the state of the repository we are working on
 * @param rw
 *            the RevWalk to use
 *
 * @throws NoMessageException
 *             if the commit message has not been specified
 */
private void processOptions(RepositoryState state, RevWalk rw) throws NoMessageException {
    if (committer == null) {
        committer = new PersonIdent(repo);
    }
    if (author == null && !amend) {
        author = committer;
    }
    if (allowEmpty == null) {
        // JGit allows empty commits by default. Only when pathes are
        // specified the commit should not be empty. This behaviour differs
        // from native git but can only be adapted in the next release.
        // TODO(ch) align the defaults with native git
        allowEmpty = (only.isEmpty()) ? Boolean.TRUE : Boolean.FALSE;
    }
    // when doing a merge commit parse MERGE_HEAD and MERGE_MSG files
    if (state == RepositoryState.MERGING_RESOLVED || isMergeDuringRebase(state)) {
        try {
            parents = repo.readMergeHeads();
            if (parents != null) {
                for (int i = 0; i < parents.size(); i++) {
                    RevObject ro = rw.parseAny(parents.get(i));
                    if (ro instanceof RevTag)
                        parents.set(i, rw.peel(ro));
                }
            }
        } catch (IOException e) {
            throw new JGitInternalException(MessageFormat.format(
                    JGitText.get().exceptionOccurredDuringReadingOfGIT_DIR, Constants.MERGE_HEAD, e), e);
        }
        if (message == null) {
            try {
                message = repo.readMergeCommitMsg();
            } catch (IOException e) {
                throw new JGitInternalException(MessageFormat.format(
                        JGitText.get().exceptionOccurredDuringReadingOfGIT_DIR, Constants.MERGE_MSG, e), e);
            }
        }
    } else if (state == RepositoryState.SAFE && message == null) {
        try {
            message = repo.readSquashCommitMsg();
            if (message != null) {
                repo.writeSquashCommitMsg(null /* delete */);
            }
        } catch (IOException e) {
            throw new JGitInternalException(MessageFormat
                    .format(JGitText.get().exceptionOccurredDuringReadingOfGIT_DIR, Constants.MERGE_MSG, e), e);
        }

    }
    if (message == null) {
        // as long as we don't support -C option we have to have
        // an explicit message
        throw new NoMessageException(JGitText.get().commitMessageNotSpecified);
    }
}

From source file:io.fabric8.git.internal.GitDataStore.java

License:Apache License

public <T> T gitOperation(PersonIdent personIdent, GitOperation<T> operation, boolean pullFirst,
        GitContext context) {//  ww w . ja  v  a2  s.  c  om
    synchronized (gitOperationMonitor) {
        assertValid();

        // must set the TCCL to the classloader that loaded GitDataStore as we need the classloader
        // that could load this class, as jgit will load resources from classpath using the TCCL
        // and that requires the TCCL to the classloader that could load GitDataStore as the resources
        // jgit requires are in the same bundle as GitDataSource (eg embedded inside fabric-git)
        // see FABRIC-887
        ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
        ClassLoader cl = GitDataStore.class.getClassLoader();
        Thread.currentThread().setContextClassLoader(cl);
        LOG.trace("Setting ThreadContextClassLoader to {} instead of {}", cl, oldCl);
        try {
            Git git = getGit();
            Repository repository = git.getRepository();
            // lets default the identity if none specified
            if (personIdent == null) {
                personIdent = new PersonIdent(repository);
            }

            if (GitHelpers.hasGitHead(git)) {
                // lets stash any local changes just in case..
                git.stashCreate().setPerson(personIdent).setWorkingDirectoryMessage("Stash before a write")
                        .call();
            }

            if (pullFirst) {
                doPull(git, getCredentialsProvider(), false);
            }

            T answer = operation.call(git, context);
            boolean requirePush = context.isRequirePush();
            if (context.isRequireCommit()) {
                requirePush = true;
                String message = context.getCommitMessage().toString();
                if (message.length() == 0) {
                    LOG.warn("No commit message from " + operation + ". Please add one! :)");
                }
                git.commit().setMessage(message).call();
                if (--commitsWithoutGC < 0) {
                    commitsWithoutGC = MAX_COMMITS_WITHOUT_GC;
                    LOG.debug("Performing \"git gc\" after {} commits", MAX_COMMITS_WITHOUT_GC);
                    git.gc().call();
                }
            }

            if (requirePush) {
                doPush(git, context, getCredentialsProvider());
            }

            if (context.isRequireCommit()) {
                clearCaches();
                fireChangeNotifications();
            }
            return answer;
        } catch (Exception e) {
            throw FabricException.launderThrowable(e);
        } finally {
            LOG.trace("Restoring ThreadContextClassLoader to {}", oldCl);
            Thread.currentThread().setContextClassLoader(oldCl);
        }
    }
}

From source file:io.fabric8.git.internal.GitDataStoreImpl.java

License:Apache License

private <T> T executeInternal(GitContext context, PersonIdent personIdent, GitOperation<T> operation) {

    if (context.isRequirePull() || context.isRequireCommit()) {
        assertWriteLock();/*from ww w.  j a va2 s .  c  o m*/
    } else {
        assertReadLock();
    }

    // [FABRIC-887] Must set the TCCL to the classloader that loaded GitDataStore as we need the classloader
    // that could load this class, as jgit will load resources from classpath using the TCCL
    // and that requires the TCCL to the classloader that could load GitDataStore as the resources
    // jgit requires are in the same bundle as GitDataSource (eg embedded inside fabric-git)
    ClassLoader tccl = Thread.currentThread().getContextClassLoader();
    try {
        ClassLoader gitcl = GitDataStoreImpl.class.getClassLoader();
        Thread.currentThread().setContextClassLoader(gitcl);
        LOGGER.trace("Setting ThreadContextClassLoader to {} instead of {}", gitcl, tccl);

        Git git = getGit();
        Repository repository = git.getRepository();

        if (personIdent == null) {
            personIdent = new PersonIdent(repository);
        }

        if (context.isRequirePull()) {
            doPullInternal(context, getCredentialsProvider(), false);
        }

        T result = operation.call(git, context);

        if (context.isRequireCommit()) {
            doCommit(git, context);
            versionCache.invalidateAll();
            notificationRequired = true;
        }

        if (context.isRequirePush()) {
            PushPolicyResult pushResult = doPushInternal(context, getCredentialsProvider());
            if (!pushResult.getRejectedUpdates().isEmpty()) {
                Exception gitex = pushResult.getLastException();
                throw new IllegalStateException("Push rejected: " + pushResult.getRejectedUpdates(), gitex);
            }
        }

        return result;
    } catch (Exception e) {
        throw FabricException.launderThrowable(e);
    } finally {
        LOGGER.trace("Restoring ThreadContextClassLoader to {}", tccl);
        Thread.currentThread().setContextClassLoader(tccl);
    }
}

From source file:jetbrains.buildServer.buildTriggers.vcs.git.GitVcsRoot.java

License:Apache License

@NotNull
public PersonIdent getTagger(@NotNull Repository r) {
    if (myUsernameForTags == null)
        return new PersonIdent(r);
    return parseIdent();
}

From source file:org.ajoberstar.gradle.git.tasks.GitCommit.java

License:Apache License

/**
 * Configures the committer for this commit.
 * A {@code PersonIdent} is passed to the closure.
 *
 * @param config the configuration closure
 *///from  w ww .  j  a  v a 2 s.  co  m
@SuppressWarnings("rawtypes")
public void committer(Closure config) {
    if (committer == null) {
        this.committer = new PersonIdent(getGit().getRepository());
    }
    ConfigureUtil.configure(config, committer);
}

From source file:org.ajoberstar.gradle.git.tasks.GitCommit.java

License:Apache License

/**
 * Configures the author for this commit.
 * A {@code PersonIdent} is passed to the closure.
 *
 * @param config the configuration closure
 *///from   w ww .  ja  va  2 s.c  om
@SuppressWarnings("rawtypes")
public void author(Closure config) {
    if (author == null) {
        this.author = new PersonIdent(getGit().getRepository());
    }
    ConfigureUtil.configure(config, author);
}

From source file:org.ajoberstar.gradle.git.tasks.GitTag.java

License:Apache License

/**
 * Configures the tagger./*from  ww w . ja v  a 2  s.c om*/
 * A {@code PersonIdent} is passed to the closure.
 * @param config the configuration closure
 */
@SuppressWarnings("rawtypes")
public void tagger(Closure config) {
    if (tagger == null) {
        this.tagger = new PersonIdent(getGit().getRepository());
    }
    ConfigureUtil.configure(config, tagger);
}

From source file:org.commonjava.gitwrap.BareGitRepository.java

License:Open Source License

public BareGitRepository createTag(final String tagSource, final String tagName, final String message,
        final boolean force) throws GitWrapException {
    try {/*from  ww w. j a  v  a 2 s  .  c om*/
        final ObjectId src = repository.resolve(tagSource);
        if (src == null) {
            throw new GitWrapException("Cannot resolve tag-source: %s", tagSource);
        }

        if (!force && repository.resolve(tagName) != null) {
            throw new GitWrapException("Tag: %s already exists!", tagName);
        }

        String dest = tagName;
        if (!dest.startsWith(Constants.R_TAGS)) {
            dest = Constants.R_TAGS + tagName;
        }

        final String tagShort = dest.substring(Constants.R_TAGS.length());

        final ObjectLoader sourceLoader = repository.open(src);
        final ObjectInserter inserter = repository.newObjectInserter();

        final TagBuilder tag = new TagBuilder();
        tag.setTag(tagShort);
        tag.setTagger(new PersonIdent(repository));
        tag.setObjectId(src, sourceLoader.getType());
        tag.setMessage(message);

        final ObjectId tagId = inserter.insert(tag);
        tag.setTagId(tagId);

        final String refName = Constants.R_TAGS + tag.getTag();

        final RefUpdate tagRef = repository.updateRef(refName);
        tagRef.setNewObjectId(tag.getTagId());
        tagRef.setForceUpdate(force);
        tagRef.setRefLogMessage("Tagging source: " + src.name() + " as " + tagName, false);

        final Result updateResult = tagRef.update();

        switch (updateResult) {
        case NEW:
        case FAST_FORWARD:
        case FORCED: {
            break;
        }
        case REJECTED: {
            throw new GitWrapException("Tag already exists: %s", tagName);
        }
        default: {
            throw new GitWrapException("Cannot lock tag: %s", tagName);
        }
        }
    } catch (final IOException e) {
        throw new GitWrapException("Failed to add tag: %s", e, e.getMessage());
    }

    return this;
}

From source file:org.commonjava.gitwrap.GitRepository.java

License:Open Source License

public GitRepository commitChanges(final String message, final String... filePatterns) throws GitWrapException {
    final AddCommand add = getGit().add();
    add.setWorkingTreeIterator(new FileTreeIterator(getRepository()));
    for (final String pattern : filePatterns) {
        add.addFilepattern(pattern);//w  ww . j ava  2  s  .  c om
    }

    try {
        add.call();
    } catch (final NoFilepatternException e) {
        throw new GitWrapException("Failed to add file patterns: %s", e, e.getMessage());
    }

    try {
        getGit().commit().setMessage(message).setAuthor(new PersonIdent(getRepository())).call();
    } catch (final NoHeadException e) {
        throw new GitWrapException("Commit failed: no repository HEAD. Nested error: %s", e, e.getMessage());
    } catch (final NoMessageException e) {
        throw new GitWrapException("Commit failed: no message provided. Nested error: %s", e, e.getMessage());
    } catch (final UnmergedPathException e) {
        throw new GitWrapException("Commit failed: you have unmerged paths. Nested error: %s", e,
                e.getMessage());
    } catch (final ConcurrentRefUpdateException e) {
        throw new GitWrapException("Commit failed: %s", e, e.getMessage());
    } catch (final JGitInternalException e) {
        throw new GitWrapException("Commit failed: %s", e, e.getMessage());
    } catch (final WrongRepositoryStateException e) {
        throw new GitWrapException("Commit failed: %s", e, e.getMessage());
    }

    return this;
}