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