[ 
https://issues.apache.org/jira/browse/SCM-992?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17571039#comment-17571039
 ] 

ASF GitHub Bot commented on SCM-992:
------------------------------------

michael-o commented on code in PR #159:
URL: https://github.com/apache/maven-scm/pull/159#discussion_r929168403


##########
maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/GitCommandLineUtils.java:
##########
@@ -196,4 +209,27 @@ public static int execute( Commandline cl, 
CommandLineUtils.StringStreamConsumer
         return exitCode;
     }
 
+    static Map<String, String> prepareEnvVariablesForRepository( 
GitScmProviderRepository repository,
+                                                                 Map<String, 
String> environmentVariables )
+    {
+        Map<String, String> effectiveEnvironmentVariables = new HashMap<>();
+        if ( environmentVariables != null )
+        {
+            effectiveEnvironmentVariables.putAll( environmentVariables );
+        }
+        if ( StringUtils.isNotBlank( repository.getPrivateKey() ) )
+        {
+            if ( effectiveEnvironmentVariables.putIfAbsent( 
VARIABLE_GIT_SSH_COMMAND, "ssh -IdentitiesOnly=yes -i "
+                            + FilenameUtils.separatorsToUnix( 
repository.getPrivateKey() ) ) != null )
+            {
+                LOGGER.warn( "Ignore GitScmProviderRepository.privateKey as 
environment variable {} is already set",
+                             VARIABLE_GIT_SSH_COMMAND );
+            }
+        }
+        if ( StringUtils.isNotBlank( repository.getPassphrase() ) )
+        {
+            LOGGER.warn( "GitScmProviderRepository.passphrase currently not 
supported by provider 'git'" );

Review Comment:
   gitexe is the term, no?



##########
maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/GitCommandLineUtils.java:
##########
@@ -90,28 +95,36 @@ public static void addTarget( Commandline cl, List<File> 
files )
     }
 
    /**
-    *
+    * Use this only for command not requiring environment variables (i.e. 
local commands).
     * @param workingDirectory
     * @param command
     * @return TODO
     */
    public static Commandline getBaseGitCommandLine( File workingDirectory, 
String command )
    {
-       return getBaseGitCommandLine( workingDirectory, command, 
Collections.emptyMap() );
+       return getBaseGitCommandLine( workingDirectory, command, null, null );
    }
 
     /**
-     *
+     * Use this for commands requiring environment variables (i.e. remote 
commands).
      * @param workingDirectory
      * @param command
      * @param environment
      * @return TODO
      */
     public static Commandline getBaseGitCommandLine( File workingDirectory, 
String command,
+                                                     GitScmProviderRepository 
repository,
                                                      Map<String, String> 
environment )
     {
         Commandline cl = getAnonymousBaseGitCommandLine( workingDirectory, 
command );
-        environment.forEach( cl::addEnvironment );
+        if ( repository != null ) 
+        {
+            prepareEnvVariablesForRepository( repository, environment 
).forEach( cl::addEnvironment );
+        }
+        else if ( environment != null )
+        {
+            environment.forEach( cl::addEnvironment );
+        }

Review Comment:
   I don't understand this double cascade. Everything from `environment` is 
ready in the map if repo is not null, thus the `forEach` is redundant, no?



##########
maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/GitCommandLineUtils.java:
##########
@@ -196,4 +209,27 @@ public static int execute( Commandline cl, 
CommandLineUtils.StringStreamConsumer
         return exitCode;
     }
 
+    static Map<String, String> prepareEnvVariablesForRepository( 
GitScmProviderRepository repository,
+                                                                 Map<String, 
String> environmentVariables )
+    {
+        Map<String, String> effectiveEnvironmentVariables = new HashMap<>();
+        if ( environmentVariables != null )
+        {
+            effectiveEnvironmentVariables.putAll( environmentVariables );
+        }
+        if ( StringUtils.isNotBlank( repository.getPrivateKey() ) )
+        {
+            if ( effectiveEnvironmentVariables.putIfAbsent( 
VARIABLE_GIT_SSH_COMMAND, "ssh -IdentitiesOnly=yes -i "

Review Comment:
   `-o Identities...`?





> Support explicitly configured SSH private key for gitexe
> --------------------------------------------------------
>
>                 Key: SCM-992
>                 URL: https://issues.apache.org/jira/browse/SCM-992
>             Project: Maven SCM
>          Issue Type: Improvement
>          Components: maven-scm-provider-gitexe
>            Reporter: Konrad Windszus
>            Assignee: Michael Osipov
>            Priority: Major
>             Fix For: 2.0.0-M2
>
>
> Currently the {{privateKey}} parameter set on 
> {{ScmProviderRepositoryWithHost}} is only evaluated in provider "jgit". It 
> should also be used for provider "git". Same for {{passphrase}} parameter.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to