@@ -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
@@ -3162,23 +3158,49 @@ public void execute() throws GitException, InterruptedException {
3162
3158
args .add ("-f" );
3163
3159
}
3164
3160
args .add (ref );
3165
- launchCommandIn (args , workspace , checkoutEnv , timeout );
3161
+
3162
+ StandardCredentials cred = null ;
3163
+ String checkoutUrl = null ;
3164
+ if (isAtLeastVersion (2 , 27 , 0 , 0 )) {
3165
+ String result = firstLine (launchCommand (
3166
+ "config" , "--get" , "--default" , "''" , "remote.origin.partialclonefilter" ));
3167
+ if (result != null && !result .isBlank ()) {
3168
+ checkoutUrl = launchCommand ("config" , "--get" , "--default" , "''" , "remote.origin.url" )
3169
+ .trim (); // TODO: how to get the url correctly (and compatible with the
3170
+ // unit tests)?
3171
+ // checkoutUrl = getRemoteUrl("origin"); // fails with unit tests
3172
+ if (checkoutUrl .isBlank ()) {
3173
+ checkoutUrl = null ;
3174
+ } else {
3175
+ cred = getCredentials (checkoutUrl );
3176
+ }
3177
+ }
3178
+ }
3179
+
3180
+ if (checkoutUrl != null ) {
3181
+ try {
3182
+ // credentials are needed for instance for blobless clone and are simply not used in
3183
+ // "standard" cases
3184
+ launchCommandWithCredentials (args , workspace , cred , new URIish (checkoutUrl ), timeout );
3185
+ } catch (URISyntaxException e ) {
3186
+ throw new GitException ("Invalid URL " + checkoutUrl , e );
3187
+ }
3188
+ } else {
3189
+ launchCommandIn (args , workspace , checkoutEnv , timeout );
3190
+ }
3166
3191
3167
3192
if (lfsRemote != null ) {
3168
3193
final String url = getRemoteUrl (lfsRemote );
3169
- StandardCredentials cred = lfsCredentials ;
3170
- if (cred == null ) {
3171
- cred = credentials .get (url );
3172
- }
3173
- if (cred == null ) {
3174
- cred = defaultCredentials ;
3194
+ StandardCredentials lfsCred = lfsCredentials ;
3195
+ if (lfsCred == null ) {
3196
+ lfsCred = getCredentials (url );
3175
3197
}
3176
3198
ArgumentListBuilder lfsArgs = new ArgumentListBuilder ();
3177
3199
lfsArgs .add ("lfs" );
3178
3200
lfsArgs .add ("pull" );
3179
3201
lfsArgs .add (lfsRemote );
3180
3202
try {
3181
- launchCommandWithCredentials (lfsArgs , workspace , cred , new URIish (url ), timeout );
3203
+ launchCommandWithCredentials (lfsArgs , workspace , lfsCred , new URIish (url ), timeout );
3182
3204
} catch (URISyntaxException e ) {
3183
3205
throw new GitException ("Invalid URL " + url , e );
3184
3206
}
@@ -3722,10 +3744,7 @@ public Map<String, ObjectId> getHeadRev(String url) throws GitException, Interru
3722
3744
args .add ("-h" );
3723
3745
addCheckedRemoteUrl (args , url );
3724
3746
3725
- StandardCredentials cred = credentials .get (url );
3726
- if (cred == null ) {
3727
- cred = defaultCredentials ;
3728
- }
3747
+ StandardCredentials cred = getCredentials (url );
3729
3748
3730
3749
String result = launchCommandWithCredentials (args , null , cred , url );
3731
3750
@@ -3750,10 +3769,7 @@ public ObjectId getHeadRev(String url, String branchSpec) throws GitException, I
3750
3769
args .add ("-h" );
3751
3770
}
3752
3771
3753
- StandardCredentials cred = credentials .get (url );
3754
- if (cred == null ) {
3755
- cred = defaultCredentials ;
3756
- }
3772
+ StandardCredentials cred = getCredentials (url );
3757
3773
3758
3774
addCheckedRemoteUrl (args , url );
3759
3775
@@ -3782,10 +3798,7 @@ public Map<String, ObjectId> getRemoteReferences(String url, String pattern, boo
3782
3798
args .add (pattern );
3783
3799
}
3784
3800
3785
- StandardCredentials cred = credentials .get (url );
3786
- if (cred == null ) {
3787
- cred = defaultCredentials ;
3788
- }
3801
+ StandardCredentials cred = getCredentials (url );
3789
3802
3790
3803
String result = launchCommandWithCredentials (args , null , cred , url );
3791
3804
@@ -3825,10 +3838,7 @@ public Map<String, String> getRemoteSymbolicReferences(String url, String patter
3825
3838
args .add (pattern );
3826
3839
}
3827
3840
3828
- StandardCredentials cred = credentials .get (url );
3829
- if (cred == null ) {
3830
- cred = defaultCredentials ;
3831
- }
3841
+ StandardCredentials cred = getCredentials (url );
3832
3842
3833
3843
String result = launchCommandWithCredentials (args , null , cred , url );
3834
3844
@@ -3868,10 +3878,7 @@ public void push(RemoteConfig repository, String refspec) throws GitException, I
3868
3878
ArgumentListBuilder args = new ArgumentListBuilder ();
3869
3879
URIish uri = repository .getURIs ().get (0 );
3870
3880
String url = uri .toPrivateString ();
3871
- StandardCredentials cred = credentials .get (url );
3872
- if (cred == null ) {
3873
- cred = defaultCredentials ;
3874
- }
3881
+ StandardCredentials cred = getCredentials (url );
3875
3882
3876
3883
args .add ("push" );
3877
3884
addCheckedRemoteUrl (args , url );
@@ -3974,6 +3981,14 @@ private static boolean setsidExists() {
3974
3981
return false ;
3975
3982
}
3976
3983
3984
+ private StandardCredentials getCredentials (String url ) {
3985
+ StandardCredentials cred = credentials .get (url );
3986
+ if (cred == null ) {
3987
+ cred = defaultCredentials ;
3988
+ }
3989
+ return cred ;
3990
+ }
3991
+
3977
3992
/** {@inheritDoc} */
3978
3993
@ Override
3979
3994
public Set <GitObject > getTags () throws GitException , InterruptedException {
0 commit comments