@@ -684,6 +684,61 @@ static enum protocol parse_connect_url(const char *url_orig, char **ret_user,
684
684
return protocol ;
685
685
}
686
686
687
+ static int prepare_ssh_command (struct argv_array * cmd , const char * user ,
688
+ const char * host , const char * port , int flags )
689
+ {
690
+ const char * ssh ;
691
+ int putty = 0 , tortoiseplink = 0 , use_shell = 1 ;
692
+ transport_check_allowed ("ssh" );
693
+
694
+ ssh = getenv ("GIT_SSH_COMMAND" );
695
+ if (!ssh ) {
696
+ const char * base ;
697
+ char * ssh_dup ;
698
+
699
+ /*
700
+ * GIT_SSH is the no-shell version of
701
+ * GIT_SSH_COMMAND (and must remain so for
702
+ * historical compatibility).
703
+ */
704
+ use_shell = 0 ;
705
+
706
+ ssh = getenv ("GIT_SSH" );
707
+ if (!ssh )
708
+ ssh = "ssh" ;
709
+
710
+ ssh_dup = xstrdup (ssh );
711
+ base = basename (ssh_dup );
712
+
713
+ tortoiseplink = !strcasecmp (base , "tortoiseplink" ) ||
714
+ !strcasecmp (base , "tortoiseplink.exe" );
715
+ putty = tortoiseplink ||
716
+ !strcasecmp (base , "plink" ) ||
717
+ !strcasecmp (base , "plink.exe" );
718
+
719
+ free (ssh_dup );
720
+ }
721
+
722
+ argv_array_push (cmd , ssh );
723
+ if (flags & CONNECT_IPV4 )
724
+ argv_array_push (cmd , "-4" );
725
+ else if (flags & CONNECT_IPV6 )
726
+ argv_array_push (cmd , "-6" );
727
+ if (tortoiseplink )
728
+ argv_array_push (cmd , "-batch" );
729
+ if (port ) {
730
+ /* P is for PuTTY, p is for OpenSSH */
731
+ argv_array_push (cmd , putty ? "-P" : "-p" );
732
+ argv_array_push (cmd , port );
733
+ }
734
+ if (user )
735
+ argv_array_pushf (cmd , "%s@%s" , user , host );
736
+ else
737
+ argv_array_push (cmd , host );
738
+
739
+ return use_shell ;
740
+ }
741
+
687
742
static struct child_process no_fork = CHILD_PROCESS_INIT ;
688
743
689
744
/*
@@ -780,59 +835,12 @@ struct child_process *git_connect(int fd[2], const char *url,
780
835
781
836
/* remove repo-local variables from the environment */
782
837
conn -> env = local_repo_env ;
783
- conn -> use_shell = 1 ;
784
838
conn -> in = conn -> out = -1 ;
785
839
if (protocol == PROTO_SSH ) {
786
- const char * ssh ;
787
- int putty = 0 , tortoiseplink = 0 ;
788
- transport_check_allowed ("ssh" );
789
-
790
- ssh = getenv ("GIT_SSH_COMMAND" );
791
- if (!ssh ) {
792
- const char * base ;
793
- char * ssh_dup ;
794
-
795
- /*
796
- * GIT_SSH is the no-shell version of
797
- * GIT_SSH_COMMAND (and must remain so for
798
- * historical compatibility).
799
- */
800
- conn -> use_shell = 0 ;
801
-
802
- ssh = getenv ("GIT_SSH" );
803
- if (!ssh )
804
- ssh = "ssh" ;
805
-
806
- ssh_dup = xstrdup (ssh );
807
- base = basename (ssh_dup );
808
-
809
- tortoiseplink = !strcasecmp (base , "tortoiseplink" ) ||
810
- !strcasecmp (base , "tortoiseplink.exe" );
811
- putty = tortoiseplink ||
812
- !strcasecmp (base , "plink" ) ||
813
- !strcasecmp (base , "plink.exe" );
814
-
815
- free (ssh_dup );
816
- }
817
-
818
- argv_array_push (& conn -> args , ssh );
819
- if (flags & CONNECT_IPV4 )
820
- argv_array_push (& conn -> args , "-4" );
821
- else if (flags & CONNECT_IPV6 )
822
- argv_array_push (& conn -> args , "-6" );
823
- if (tortoiseplink )
824
- argv_array_push (& conn -> args , "-batch" );
825
- if (port ) {
826
- /* P is for PuTTY, p is for OpenSSH */
827
- argv_array_push (& conn -> args , putty ? "-P" : "-p" );
828
- argv_array_push (& conn -> args , port );
829
- }
830
- if (user )
831
- argv_array_pushf (& conn -> args , "%s@%s" ,
832
- user , host );
833
- else
834
- argv_array_push (& conn -> args , host );
840
+ conn -> use_shell = prepare_ssh_command (
841
+ & conn -> args , user , host , port , flags );
835
842
} else {
843
+ conn -> use_shell = 1 ;
836
844
transport_check_allowed ("file" );
837
845
}
838
846
argv_array_push (& conn -> args , cmd .buf );
0 commit comments