@@ -195,7 +195,6 @@ public class CliGitAPIImpl extends LegacyCompatibleGitAPIImpl {
195
195
EnvVars environment ;
196
196
private Map <String , StandardCredentials > credentials = new HashMap <>();
197
197
private StandardCredentials defaultCredentials ;
198
- private StandardCredentials lfsCredentials ;
199
198
private final String encoding ;
200
199
201
200
/* If we fail some helper tool (e.g. SELinux chcon) do not make noise
@@ -672,10 +671,7 @@ public void fetch(String remoteName, RefSpec... refspec) throws GitException, In
672
671
}
673
672
}
674
673
675
- StandardCredentials cred = credentials .get (url );
676
- if (cred == null ) {
677
- cred = defaultCredentials ;
678
- }
674
+ StandardCredentials cred = getCredentials (url );
679
675
launchCommandWithCredentials (args , workspace , cred , url );
680
676
}
681
677
@@ -3171,23 +3167,49 @@ public void execute() throws GitException, InterruptedException {
3171
3167
args .add ("-f" );
3172
3168
}
3173
3169
args .add (ref );
3174
- launchCommandIn (args , workspace , checkoutEnv , timeout );
3170
+
3171
+ StandardCredentials cred = null ;
3172
+ String checkoutUrl = null ;
3173
+ if (isAtLeastVersion (2 , 27 , 0 , 0 )) {
3174
+ String result = firstLine (launchCommand (
3175
+ "config" , "--get" , "--default" , "''" , "remote.origin.partialclonefilter" ));
3176
+ if (result != null && !result .isBlank ()) {
3177
+ checkoutUrl = launchCommand ("config" , "--get" , "--default" , "''" , "remote.origin.url" )
3178
+ .trim (); // TODO: how to get the url correctly (and compatible with the
3179
+ // unit tests)?
3180
+ // checkoutUrl = getRemoteUrl("origin"); // fails with unit tests
3181
+ if (checkoutUrl .isBlank ()) {
3182
+ checkoutUrl = null ;
3183
+ } else {
3184
+ cred = getCredentials (checkoutUrl );
3185
+ }
3186
+ }
3187
+ }
3188
+
3189
+ if (checkoutUrl != null ) {
3190
+ try {
3191
+ // credentials are needed for instance for blobless clone and are simply not used in
3192
+ // "standard" cases
3193
+ launchCommandWithCredentials (args , workspace , cred , new URIish (checkoutUrl ), timeout );
3194
+ } catch (URISyntaxException e ) {
3195
+ throw new GitException ("Invalid URL " + checkoutUrl , e );
3196
+ }
3197
+ } else {
3198
+ launchCommandIn (args , workspace , checkoutEnv , timeout );
3199
+ }
3175
3200
3176
3201
if (lfsRemote != null ) {
3177
3202
final String url = getRemoteUrl (lfsRemote );
3178
- StandardCredentials cred = lfsCredentials ;
3179
- if (cred == null ) {
3180
- cred = credentials .get (url );
3181
- }
3182
- if (cred == null ) {
3183
- cred = defaultCredentials ;
3203
+ StandardCredentials lfsCred = lfsCredentials ;
3204
+ if (lfsCred == null ) {
3205
+ lfsCred = getCredentials (url );
3184
3206
}
3185
3207
ArgumentListBuilder lfsArgs = new ArgumentListBuilder ();
3186
3208
lfsArgs .add ("lfs" );
3187
3209
lfsArgs .add ("pull" );
3188
3210
lfsArgs .add (lfsRemote );
3189
3211
try {
3190
- launchCommandWithCredentials (lfsArgs , workspace , cred , new URIish (url ), timeout );
3212
+ launchCommandWithCredentials (lfsArgs , workspace , lfsCred , new URIish (url ), timeout );
3191
3213
} catch (URISyntaxException e ) {
3192
3214
throw new GitException ("Invalid URL " + url , e );
3193
3215
}
@@ -3731,10 +3753,7 @@ public Map<String, ObjectId> getHeadRev(String url) throws GitException, Interru
3731
3753
args .add ("-h" );
3732
3754
addCheckedRemoteUrl (args , url );
3733
3755
3734
- StandardCredentials cred = credentials .get (url );
3735
- if (cred == null ) {
3736
- cred = defaultCredentials ;
3737
- }
3756
+ StandardCredentials cred = getCredentials (url );
3738
3757
3739
3758
String result = launchCommandWithCredentials (args , null , cred , url );
3740
3759
@@ -3759,10 +3778,7 @@ public ObjectId getHeadRev(String url, String branchSpec) throws GitException, I
3759
3778
args .add ("-h" );
3760
3779
}
3761
3780
3762
- StandardCredentials cred = credentials .get (url );
3763
- if (cred == null ) {
3764
- cred = defaultCredentials ;
3765
- }
3781
+ StandardCredentials cred = getCredentials (url );
3766
3782
3767
3783
addCheckedRemoteUrl (args , url );
3768
3784
@@ -3791,10 +3807,7 @@ public Map<String, ObjectId> getRemoteReferences(String url, String pattern, boo
3791
3807
args .add (pattern );
3792
3808
}
3793
3809
3794
- StandardCredentials cred = credentials .get (url );
3795
- if (cred == null ) {
3796
- cred = defaultCredentials ;
3797
- }
3810
+ StandardCredentials cred = getCredentials (url );
3798
3811
3799
3812
String result = launchCommandWithCredentials (args , null , cred , url );
3800
3813
@@ -3834,10 +3847,7 @@ public Map<String, String> getRemoteSymbolicReferences(String url, String patter
3834
3847
args .add (pattern );
3835
3848
}
3836
3849
3837
- StandardCredentials cred = credentials .get (url );
3838
- if (cred == null ) {
3839
- cred = defaultCredentials ;
3840
- }
3850
+ StandardCredentials cred = getCredentials (url );
3841
3851
3842
3852
String result = launchCommandWithCredentials (args , null , cred , url );
3843
3853
@@ -3877,10 +3887,7 @@ public void push(RemoteConfig repository, String refspec) throws GitException, I
3877
3887
ArgumentListBuilder args = new ArgumentListBuilder ();
3878
3888
URIish uri = repository .getURIs ().get (0 );
3879
3889
String url = uri .toPrivateString ();
3880
- StandardCredentials cred = credentials .get (url );
3881
- if (cred == null ) {
3882
- cred = defaultCredentials ;
3883
- }
3890
+ StandardCredentials cred = getCredentials (url );
3884
3891
3885
3892
args .add ("push" );
3886
3893
addCheckedRemoteUrl (args , url );
@@ -3983,6 +3990,14 @@ private static boolean setsidExists() {
3983
3990
return false ;
3984
3991
}
3985
3992
3993
+ private StandardCredentials getCredentials (String url ) {
3994
+ StandardCredentials cred = credentials .get (url );
3995
+ if (cred == null ) {
3996
+ cred = defaultCredentials ;
3997
+ }
3998
+ return cred ;
3999
+ }
4000
+
3986
4001
/** {@inheritDoc} */
3987
4002
@ Override
3988
4003
public Set <GitObject > getTags () throws GitException , InterruptedException {
0 commit comments