Search in sources :

Example 21 with PersonIdent

use of org.eclipse.jgit.lib.PersonIdent in project archi-modelrepository-plugin by archi-contribs.

the class ArchiRepository method getUserDetails.

@Override
public PersonIdent getUserDetails() throws IOException {
    try (Git git = Git.open(getLocalRepositoryFolder())) {
        StoredConfig config = git.getRepository().getConfig();
        String name = StringUtils.safeString(config.getString(ConfigConstants.CONFIG_USER_SECTION, null, ConfigConstants.CONFIG_KEY_NAME));
        String email = StringUtils.safeString(config.getString(ConfigConstants.CONFIG_USER_SECTION, null, ConfigConstants.CONFIG_KEY_EMAIL));
        return new PersonIdent(name, email);
    }
}
Also used : StoredConfig(org.eclipse.jgit.lib.StoredConfig) Git(org.eclipse.jgit.api.Git) PersonIdent(org.eclipse.jgit.lib.PersonIdent)

Example 22 with PersonIdent

use of org.eclipse.jgit.lib.PersonIdent in project archi-modelrepository-plugin by archi-contribs.

the class ModelRepositoryPreferencePage method performDefaults.

@Override
protected void performDefaults() {
    PersonIdent result = getUserDetails();
    fUserNameTextField.setText(result.getName());
    fUserEmailTextField.setText(result.getEmailAddress());
    fUserRepoFolderTextField.setText(getPreferenceStore().getDefaultString(PREFS_REPOSITORY_FOLDER));
    fStoreCredentialsButton.setSelection(getPreferenceStore().getDefaultBoolean(PREFS_STORE_REPO_CREDENTIALS));
    fUseProxyButton.setSelection(getPreferenceStore().getDefaultBoolean(PREFS_PROXY_USE));
    fProxyHostTextField.setText(getPreferenceStore().getDefaultString(PREFS_PROXY_HOST));
    fProxyPortTextField.setText(getPreferenceStore().getDefaultString(PREFS_PROXY_PORT));
    fRequiresProxyAuthenticationButton.setSelection(getPreferenceStore().getDefaultBoolean(PREFS_PROXY_REQUIRES_AUTHENTICATION));
    // $NON-NLS-1$
    fProxyUserNameTextField.setText("");
    // $NON-NLS-1$
    fProxyUserPasswordTextField.setText("");
    updateProxyControls();
}
Also used : PersonIdent(org.eclipse.jgit.lib.PersonIdent)

Example 23 with PersonIdent

use of org.eclipse.jgit.lib.PersonIdent in project archi-modelrepository-plugin by archi-contribs.

the class UserDetailsSection method handleSelection.

@Override
protected void handleSelection(IStructuredSelection selection) {
    if (selection.getFirstElement() instanceof IArchiRepository) {
        fRepository = (IArchiRepository) selection.getFirstElement();
        // $NON-NLS-1$ //$NON-NLS-2$
        String globalName = "", globalEmail = "";
        // $NON-NLS-1$ //$NON-NLS-2$
        String localName = "", localEmail = "";
        // Get global name, email
        try {
            PersonIdent global = GraficoUtils.getGitConfigUserDetails();
            globalName = global.getName();
            globalEmail = global.getEmailAddress();
        } catch (IOException | ConfigInvalidException ex) {
            ex.printStackTrace();
        }
        // Get local name, email
        try {
            PersonIdent local = fRepository.getUserDetails();
            localName = local.getName();
            localEmail = local.getEmailAddress();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        fTextName.setText(globalName, localName);
        fTextEmail.setText(globalEmail, localEmail);
    } else {
        // $NON-NLS-1$
        System.err.println(getClass() + " failed to get element for " + selection.getFirstElement());
    }
}
Also used : ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) PersonIdent(org.eclipse.jgit.lib.PersonIdent) IArchiRepository(org.archicontribs.modelrepository.grafico.IArchiRepository) IOException(java.io.IOException)

Example 24 with PersonIdent

use of org.eclipse.jgit.lib.PersonIdent in project MGit by maks.

the class Repo method updateLatestCommitInfo.

public void updateLatestCommitInfo() {
    RevCommit commit = getLatestCommit();
    ContentValues values = new ContentValues();
    String email = "";
    String uname = "";
    String commitDateStr = "";
    String msg = "";
    if (commit != null) {
        PersonIdent committer = commit.getCommitterIdent();
        if (committer != null) {
            email = committer.getEmailAddress() != null ? committer.getEmailAddress() : email;
            uname = committer.getName() != null ? committer.getName() : uname;
        }
        msg = commit.getShortMessage() != null ? commit.getShortMessage() : msg;
        long date = committer.getWhen().getTime();
        commitDateStr = Long.toString(date);
    }
    values.put(RepoContract.RepoEntry.COLUMN_NAME_LATEST_COMMIT_DATE, commitDateStr);
    values.put(RepoContract.RepoEntry.COLUMN_NAME_LATEST_COMMIT_MSG, msg);
    values.put(RepoContract.RepoEntry.COLUMN_NAME_LATEST_COMMITTER_EMAIL, email);
    values.put(RepoContract.RepoEntry.COLUMN_NAME_LATEST_COMMITTER_UNAME, uname);
    RepoDbManager.updateRepo(getID(), values);
}
Also used : ContentValues(android.content.ContentValues) PersonIdent(org.eclipse.jgit.lib.PersonIdent) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 25 with PersonIdent

use of org.eclipse.jgit.lib.PersonIdent in project MGit by maks.

the class CommitDiffActivity method formatCommitInfo.

private String formatCommitInfo() {
    PersonIdent committer, author;
    committer = mCommit.getCommitterIdent();
    author = mCommit.getAuthorIdent();
    return "commit " + mNewCommit + "\n" + "Author:     " + author.getName() + " <" + author.getEmailAddress() + ">\n" + "AuthorDate: " + author.getWhen() + "\n" + "Commit:     " + committer.getName() + " <" + committer.getEmailAddress() + ">\n" + "CommitDate: " + committer.getWhen() + "\n";
}
Also used : PersonIdent(org.eclipse.jgit.lib.PersonIdent)

Aggregations

PersonIdent (org.eclipse.jgit.lib.PersonIdent)221 RevCommit (org.eclipse.jgit.revwalk.RevCommit)78 ObjectId (org.eclipse.jgit.lib.ObjectId)55 Test (org.junit.Test)55 Repository (org.eclipse.jgit.lib.Repository)48 IOException (java.io.IOException)41 CommitBuilder (org.eclipse.jgit.lib.CommitBuilder)41 RevWalk (org.eclipse.jgit.revwalk.RevWalk)38 ObjectInserter (org.eclipse.jgit.lib.ObjectInserter)31 Change (com.google.gerrit.entities.Change)28 GerritPersonIdent (com.google.gerrit.server.GerritPersonIdent)26 Ref (org.eclipse.jgit.lib.Ref)26 Git (org.eclipse.jgit.api.Git)25 Account (com.google.gerrit.entities.Account)22 Instant (java.time.Instant)21 TestRepository (org.eclipse.jgit.junit.TestRepository)20 ArrayList (java.util.ArrayList)18 File (java.io.File)17 Date (java.util.Date)17 RefUpdate (org.eclipse.jgit.lib.RefUpdate)17