/** {@inheritDoc} */ public void setAuthor(String name, String email) throws GitException { proxy.setAuthor(name, email); }
/** {@inheritDoc} */ public void setAuthor(PersonIdent p) throws GitException { proxy.setAuthor(p); }
/** * {@inheritDoc} */ @Override public GitClient decorate(GitSCM scm, GitClient git) throws IOException, InterruptedException, GitException { GitSCM.DescriptorImpl d = scm.getDescriptor(); String n = d.getGlobalConfigName(); if (name!=null) n = name; String e = d.getGlobalConfigEmail(); if (email!=null) e = email; git.setAuthor(n,e); git.setCommitter(n,e); return git; }
@Override public Boolean invoke(File localWorkspace, VirtualChannel channel) throws IOException, InterruptedException { File gitClonePath = localWorkspace; if (gitPrefix != null) { gitClonePath = new File(localWorkspace, gitPrefix); } GitClient git = Git.with(listener, environment) .in(gitClonePath).using(gitExe) .getClient(); if (git.hasGitRepo()) { PersonIdent person = new PersonIdent(accountName, accountEmail); for (String module: modules) { git.add(new File(module, "debian/changelog").getCanonicalPath()); } git.setAuthor(person); git.setCommitter(person); git.commit(commitMessage); return true; } else { return false; } }
try { git.setAuthor("Jenkins", "nobody@nowhere"); git.setCommitter("Jenkins", "nobody@nowhere"); MergeCommand cmd = git.merge().setRevisionToMerge(baseObjectId);
@Override public Revision decorateRevisionToBuild(GitSCM scm, Run<?, ?> build, GitClient git, TaskListener listener, Revision marked, Revision rev) throws IOException, InterruptedException, GitException { listener.getLogger().println("Merging " + targetBranch.getName() + " commit " + targetBranch.getRevision().getHash() + " into merge-request head commit " + rev.getSha1String()); checkout(scm, build, git, listener, rev); try { git.setAuthor("Jenkins", /* could parse out of JenkinsLocationConfiguration.get().getAdminAddress() but seems overkill */"nobody@nowhere"); git.setCommitter("Jenkins", "nobody@nowhere"); MergeCommand cmd = git.merge().setRevisionToMerge(ObjectId.fromString(targetBranch.getRevision().getHash())); for (GitSCMExtension ext : scm.getExtensions()) { // By default we do a regular merge, allowing it to fast-forward. ext.decorateMergeCommand(scm, build, git, listener, cmd); } cmd.execute(); } catch (GitException e) { // Try to revert merge conflict markers. checkout(scm, build, git, listener, rev); throw e; } build.addAction(new MergeRecord(targetBranch.getRefSpec().destinationRef(targetBranch.getName()), targetBranch.getRevision().getHash())); // does not seem to be used, but just in case ObjectId mergeRev = git.revParse(Constants.HEAD); listener.getLogger().println("Merge succeeded, producing " + mergeRev.name()); return new Revision(mergeRev, rev.getBranches()); // note that this ensures Build.revision != Build.marked }
private GitClient getGitClient(ReleaseRepository releaseRepository) throws IOException, InterruptedException { FilePath directory = getWorkingDirectory(getJenkinsScm(), build.getWorkspace()); EnvVars env = build.getEnvironment(buildListener); Git git = new Git(buildListener, env); git.in(directory); /* * When init the git exe, the user dons`t have to add SSH credentials in the git plugin. * This solution automatically takes the user default SSH ($HOME/.ssh) * */ git.using(getJenkinsScm().getGitExe(build.getBuiltOn(), buildListener)); // git.exe GitClient client = git.getClient(); client.setCommitter(StringUtils.defaultIfEmpty(env.get("GIT_COMMITTER_NAME"), ""), StringUtils.defaultIfEmpty(env.get("GIT_COMMITTER_EMAIL"), "")); client.setAuthor(StringUtils.defaultIfEmpty(env.get("GIT_AUTHOR_NAME"), ""), StringUtils.defaultIfEmpty(env.get("GIT_AUTHOR_EMAIL"), "")); if (releaseRepository != null && releaseRepository.isTargetRepoUri()) { client.setRemoteUrl(releaseRepository.getRepositoryName(), releaseRepository.getTargetRepoPrivateUri()); } else { addRemoteRepoToConfig(client); } addCredentialsToGitClient(client); return client; }