package hudson.plugins.git.extensions.impl;

import hudson.Extension;
import hudson.plugins.git.GitSCM;
import hudson.plugins.git.extensions.GitSCMExtension;
import hudson.plugins.git.extensions.GitSCMExtensionDescriptor;
import org.kohsuke.stapler.DataBoundConstructor;

import java.util.Map;

import static hudson.Util.*;

/**
 * {@link GitSCMExtension} that sets a different name and/or e-mail address for commits.
 *
 * @author Andrew Bayer
 * @author Kohsuke Kawaguchi
 */
public class UserIdentity extends GitSCMExtension {
    private String name;
    private String email;

    @DataBoundConstructor
    public UserIdentity(String name, String email) {
        this.name = fixEmptyAndTrim(name);
        this.email = fixEmptyAndTrim(email);
    }

    public String getName() {
        return name;
    }

    public String getEmail() {
        return email;
    }

    @Override
    public void populateEnvironmentVariables(GitSCM scm, Map<String, String> env) {
        if (name!=null) {
            env.put("GIT_COMMITTER_NAME", name);
            env.put("GIT_AUTHOR_NAME", name);
        }
        if (email!=null) {
            env.put("GIT_COMMITTER_EMAIL", email);
            env.put("GIT_AUTHOR_EMAIL", email);
        }
    }

    @Extension
    public static class DescriptorImpl extends GitSCMExtensionDescriptor {
        @Override
        public String getDisplayName() {
            return "Custom user name/e-mail address";
        }
    }
}


@@ -55,32 +55,72 @@
 dson.Extension;%0A
+import hudson.plugins.git.GitException;%0A
 import hudson.pl
@@ -137,16 +137,16 @@
 GitSCM;%0A
-
 import h
@@ -255,16 +255,66 @@
 riptor;%0A
+import org.jenkinsci.plugins.gitclient.GitClient;%0A
 import o
@@ -355,16 +355,44 @@
 uctor;%0A%0A
+import java.io.IOException;%0A
 import j
@@ -1079,24 +1079,114 @@
 ing%3E env) %7B%0A
+        // for backward compatibility, in case the user's shell script invokes Git inside%0A
         if (
@@ -1422,32 +1422,32 @@
 EMAIL%22, email);%0A
-
         %7D%0A    %7D%0A
@@ -1443,24 +1443,456 @@
    %7D%0A    %7D%0A%0A
+    @Override%0A    public GitClient decorate(GitSCM scm, GitClient git) throws IOException, InterruptedException, GitException %7B%0A        GitSCM.DescriptorImpl d = scm.getDescriptor();%0A%0A        String n = d.getGlobalConfigName();%0A        if (name!=null) n = name;%0A%0A        String e = d.getGlobalConfigEmail();%0A        if (email!=null) e = email;%0A%0A        git.setAuthor(n,e);%0A        git.setCommitter(n,e);%0A%0A        return git;%0A    %7D%0A%0A
     @Extensi

Configure author/committer more reliably