11package org .jenkinsci .plugins .gitclient ;
22
3- import com .cloudbees .jenkins .plugins .sshcredentials .SSHUserPrivateKey ;
4- import com .cloudbees .plugins .credentials .common .StandardCredentials ;
5- import com .cloudbees .plugins .credentials .common .StandardUsernamePasswordCredentials ;
6- import edu .umd .cs .findbugs .annotations .CheckForNull ;
7- import edu .umd .cs .findbugs .annotations .NonNull ;
8- import edu .umd .cs .findbugs .annotations .SuppressFBWarnings ;
9- import hudson .EnvVars ;
10- import hudson .FilePath ;
11- import hudson .Launcher ;
12- import hudson .Launcher .LocalLauncher ;
13- import hudson .Proc ;
14- import hudson .Util ;
15- import hudson .console .HyperlinkNote ;
16- import hudson .model .TaskListener ;
17- import hudson .plugins .git .Branch ;
18- import hudson .plugins .git .GitException ;
19- import hudson .plugins .git .GitLockFailedException ;
20- import hudson .plugins .git .GitObject ;
21- import hudson .plugins .git .IGitAPI ;
22- import hudson .plugins .git .IndexEntry ;
23- import hudson .plugins .git .Revision ;
24- import hudson .util .ArgumentListBuilder ;
25- import hudson .util .Secret ;
263import java .io .BufferedReader ;
274import java .io .BufferedWriter ;
285import java .io .ByteArrayOutputStream ;
6845import java .util .regex .Matcher ;
6946import java .util .regex .Pattern ;
7047import java .util .stream .Collectors ;
48+
49+ import com .cloudbees .jenkins .plugins .sshcredentials .SSHUserPrivateKey ;
50+ import com .cloudbees .plugins .credentials .common .StandardCredentials ;
51+ import com .cloudbees .plugins .credentials .common .StandardUsernamePasswordCredentials ;
52+ import edu .umd .cs .findbugs .annotations .CheckForNull ;
53+ import edu .umd .cs .findbugs .annotations .NonNull ;
54+ import edu .umd .cs .findbugs .annotations .SuppressFBWarnings ;
55+ import hudson .EnvVars ;
56+ import hudson .FilePath ;
57+ import hudson .Launcher ;
58+ import hudson .Launcher .LocalLauncher ;
59+ import hudson .Proc ;
60+ import hudson .Util ;
61+ import hudson .console .HyperlinkNote ;
62+ import hudson .model .TaskListener ;
63+ import hudson .plugins .git .Branch ;
64+ import hudson .plugins .git .GitException ;
65+ import hudson .plugins .git .GitLockFailedException ;
66+ import hudson .plugins .git .GitObject ;
67+ import hudson .plugins .git .IGitAPI ;
68+ import hudson .plugins .git .IndexEntry ;
69+ import hudson .plugins .git .Revision ;
70+ import hudson .util .ArgumentListBuilder ;
71+ import hudson .util .Secret ;
7172import org .apache .commons .io .FileUtils ;
7273import org .apache .commons .io .IOUtils ;
7374import org .apache .commons .lang .StringUtils ;
@@ -798,7 +799,11 @@ public CloneCommand depth(Integer depth) {
798799
799800 @ Override
800801 public CloneCommand refspecs (List <RefSpec > refspecs ) {
801- this .refspecs = new ArrayList <>(refspecs );
802+ List <RefSpec > refSpecsList = new ArrayList <RefSpec >();
803+ for (RefSpec ref : refspecs ) {
804+ refSpecsList .add (new RefSpec (ref .toString ().trim ()));
805+ }
806+ this .refspecs = refSpecsList ;
802807 return this ;
803808 }
804809
@@ -870,8 +875,7 @@ public void execute() throws GitException, InterruptedException {
870875 }
871876
872877 if (refspecs == null ) {
873- refspecs = Collections .singletonList (
874- new RefSpec ("+refs/heads/*:refs/remotes/" + origin .trim () + "/*" ));
878+ refspecs = Collections .singletonList (new RefSpec ("+refs/heads/*:refs/remotes/" + origin + "/*" .trim ()));
875879 }
876880 fetch_ ().from (urIish , refspecs )
877881 .shallow (shallow )
@@ -881,7 +885,7 @@ public void execute() throws GitException, InterruptedException {
881885 .execute ();
882886 setRemoteUrl (origin , url );
883887 for (RefSpec refSpec : refspecs ) {
884- launchCommand ("config" , "--add" , "remote." + origin + ".fetch" , refSpec .toString ());
888+ launchCommand ("config" , "--add" , "remote." + origin + ".fetch" , refSpec .toString (). trim () );
885889 }
886890 }
887891 };
0 commit comments