@@ -200,7 +200,6 @@ public class CliGitAPIImpl extends LegacyCompatibleGitAPIImpl {
200
200
EnvVars environment ;
201
201
private Map <String , StandardCredentials > credentials = new HashMap <>();
202
202
private StandardCredentials defaultCredentials ;
203
- private StandardCredentials lfsCredentials ;
204
203
private final String encoding ;
205
204
206
205
/* If we fail some helper tool (e.g. SELinux chcon) do not make noise
@@ -680,10 +679,7 @@ public void fetch(String remoteName, RefSpec... refspec) throws GitException, In
680
679
}
681
680
}
682
681
683
- StandardCredentials cred = credentials .get (url );
684
- if (cred == null ) {
685
- cred = defaultCredentials ;
686
- }
682
+ StandardCredentials cred = getCredentials (url );
687
683
launchCommandWithCredentials (args , workspace , cred , url );
688
684
}
689
685
@@ -3177,23 +3173,49 @@ public void execute() throws GitException, InterruptedException {
3177
3173
args .add ("-f" );
3178
3174
}
3179
3175
args .add (ref );
3180
- launchCommandIn (args , workspace , checkoutEnv , timeout );
3176
+
3177
+ StandardCredentials cred = null ;
3178
+ String checkoutUrl = null ;
3179
+ if (isAtLeastVersion (2 , 27 , 0 , 0 )) {
3180
+ String result = firstLine (launchCommand (
3181
+ "config" , "--get" , "--default" , "''" , "remote.origin.partialclonefilter" ));
3182
+ if (result != null && !result .isBlank ()) {
3183
+ checkoutUrl = launchCommand ("config" , "--get" , "--default" , "''" , "remote.origin.url" )
3184
+ .trim (); // TODO: how to get the url correctly (and compatible with the
3185
+ // unit tests)?
3186
+ // checkoutUrl = getRemoteUrl("origin"); // fails with unit tests
3187
+ if (checkoutUrl .isBlank ()) {
3188
+ checkoutUrl = null ;
3189
+ } else {
3190
+ cred = getCredentials (checkoutUrl );
3191
+ }
3192
+ }
3193
+ }
3194
+
3195
+ if (cred != null ) {
3196
+ try {
3197
+ // credentials are needed for instance for blobless clone and are simply not used in
3198
+ // "standard" cases
3199
+ launchCommandWithCredentials (args , workspace , cred , new URIish (checkoutUrl ), timeout );
3200
+ } catch (URISyntaxException e ) {
3201
+ throw new GitException ("Invalid URL " + checkoutUrl , e );
3202
+ }
3203
+ } else {
3204
+ launchCommandIn (args , workspace , checkoutEnv , timeout );
3205
+ }
3181
3206
3182
3207
if (lfsRemote != null ) {
3183
3208
final String url = getRemoteUrl (lfsRemote );
3184
- StandardCredentials cred = lfsCredentials ;
3185
- if (cred == null ) {
3186
- cred = credentials .get (url );
3187
- }
3188
- if (cred == null ) {
3189
- cred = defaultCredentials ;
3209
+ StandardCredentials lfsCred = lfsCredentials ;
3210
+ if (lfsCred == null ) {
3211
+ lfsCred = getCredentials (url );
3190
3212
}
3191
3213
ArgumentListBuilder lfsArgs = new ArgumentListBuilder ();
3192
3214
lfsArgs .add ("lfs" );
3193
3215
lfsArgs .add ("pull" );
3194
3216
lfsArgs .add (lfsRemote );
3195
3217
try {
3196
- launchCommandWithCredentials (lfsArgs , workspace , cred , new URIish (url ), timeout );
3218
+ launchCommandWithCredentials (lfsArgs , workspace , lfsCred , new URIish (url ), timeout );
3197
3219
} catch (URISyntaxException e ) {
3198
3220
throw new GitException ("Invalid URL " + url , e );
3199
3221
}
@@ -3740,10 +3762,7 @@ public Map<String, ObjectId> getHeadRev(String url) throws GitException, Interru
3740
3762
args .add ("-h" );
3741
3763
addCheckedRemoteUrl (args , url );
3742
3764
3743
- StandardCredentials cred = credentials .get (url );
3744
- if (cred == null ) {
3745
- cred = defaultCredentials ;
3746
- }
3765
+ StandardCredentials cred = getCredentials (url );
3747
3766
3748
3767
String result = launchCommandWithCredentials (args , null , cred , url );
3749
3768
@@ -3768,10 +3787,7 @@ public ObjectId getHeadRev(String url, String branchSpec) throws GitException, I
3768
3787
args .add ("-h" );
3769
3788
}
3770
3789
3771
- StandardCredentials cred = credentials .get (url );
3772
- if (cred == null ) {
3773
- cred = defaultCredentials ;
3774
- }
3790
+ StandardCredentials cred = getCredentials (url );
3775
3791
3776
3792
addCheckedRemoteUrl (args , url );
3777
3793
@@ -3800,10 +3816,7 @@ public Map<String, ObjectId> getRemoteReferences(String url, String pattern, boo
3800
3816
args .add (pattern );
3801
3817
}
3802
3818
3803
- StandardCredentials cred = credentials .get (url );
3804
- if (cred == null ) {
3805
- cred = defaultCredentials ;
3806
- }
3819
+ StandardCredentials cred = getCredentials (url );
3807
3820
3808
3821
String result = launchCommandWithCredentials (args , null , cred , url );
3809
3822
@@ -3843,10 +3856,7 @@ public Map<String, String> getRemoteSymbolicReferences(String url, String patter
3843
3856
args .add (pattern );
3844
3857
}
3845
3858
3846
- StandardCredentials cred = credentials .get (url );
3847
- if (cred == null ) {
3848
- cred = defaultCredentials ;
3849
- }
3859
+ StandardCredentials cred = getCredentials (url );
3850
3860
3851
3861
String result = launchCommandWithCredentials (args , null , cred , url );
3852
3862
@@ -3886,10 +3896,7 @@ public void push(RemoteConfig repository, String refspec) throws GitException, I
3886
3896
ArgumentListBuilder args = new ArgumentListBuilder ();
3887
3897
URIish uri = repository .getURIs ().get (0 );
3888
3898
String url = uri .toPrivateString ();
3889
- StandardCredentials cred = credentials .get (url );
3890
- if (cred == null ) {
3891
- cred = defaultCredentials ;
3892
- }
3899
+ StandardCredentials cred = getCredentials (url );
3893
3900
3894
3901
args .add ("push" );
3895
3902
addCheckedRemoteUrl (args , url );
@@ -3992,6 +3999,14 @@ private static boolean setsidExists() {
3992
3999
return false ;
3993
4000
}
3994
4001
4002
+ private StandardCredentials getCredentials (String url ) {
4003
+ StandardCredentials cred = credentials .get (url );
4004
+ if (cred == null ) {
4005
+ cred = defaultCredentials ;
4006
+ }
4007
+ return cred ;
4008
+ }
4009
+
3995
4010
/** {@inheritDoc} */
3996
4011
@ Override
3997
4012
public Set <GitObject > getTags () throws GitException , InterruptedException {
0 commit comments