@@ -107,14 +107,15 @@ class GitCredentialHelper(CredentialHelper):
107
107
>>> password = credentials.password
108
108
"""
109
109
110
- def __init__ (self , command : str ):
110
+ def __init__ (self , command : str , use_http_path : bool = False ):
111
111
super ().__init__ ()
112
112
self ._command = command
113
113
self ._run_kwargs : Dict [str , Any ] = {}
114
114
if self ._command [0 ] == "!" :
115
115
# On Windows this will only work in git-bash and/or WSL2
116
116
self ._run_kwargs ["shell" ] = True
117
117
self ._encoding = locale .getpreferredencoding ()
118
+ self .use_http_path = use_http_path
118
119
119
120
def _prepare_command (self , action : Optional [str ] = None ) -> Union [str , List [str ]]:
120
121
if self ._command [0 ] == "!" :
@@ -150,7 +151,12 @@ def get(self, credential: "Credential", **kwargs) -> "Credential":
150
151
if not (credential .protocol or credential .host ):
151
152
raise ValueError ("One of protocol, hostname must be provided" )
152
153
cmd = self ._prepare_command ("get" )
153
- helper_input = [f"{ key } ={ value } " for key , value in credential .items ()]
154
+ use_path = credential .protocol in ("http" , "https" ) and self .use_http_path
155
+ helper_input = [
156
+ f"{ key } ={ value } "
157
+ for key , value in credential .items ()
158
+ if key != "path" or use_path
159
+ ]
154
160
helper_input .append ("" )
155
161
156
162
try :
@@ -186,7 +192,12 @@ def get(self, credential: "Credential", **kwargs) -> "Credential":
186
192
def store (self , credential : "Credential" , ** kwargs ):
187
193
"""Store the credential, if applicable to the helper"""
188
194
cmd = self ._prepare_command ("store" )
189
- helper_input = [f"{ key } ={ value } " for key , value in credential .items ()]
195
+ use_path = credential .protocol in ("http" , "https" ) and self .use_http_path
196
+ helper_input = [
197
+ f"{ key } ={ value } "
198
+ for key , value in credential .items ()
199
+ if key != "path" or use_path
200
+ ]
190
201
helper_input .append ("" )
191
202
192
203
try :
@@ -205,7 +216,12 @@ def store(self, credential: "Credential", **kwargs):
205
216
def erase (self , credential : "Credential" , ** kwargs ):
206
217
"""Remove a matching credential, if any, from the helper’s storage"""
207
218
cmd = self ._prepare_command ("erase" )
208
- helper_input = [f"{ key } ={ value } " for key , value in credential .items ()]
219
+ use_path = credential .protocol in ("http" , "https" ) and self .use_http_path
220
+ helper_input = [
221
+ f"{ key } ={ value } "
222
+ for key , value in credential .items ()
223
+ if key != "path" or use_path
224
+ ]
209
225
helper_input .append ("" )
210
226
211
227
try :
@@ -224,7 +240,7 @@ def erase(self, credential: "Credential", **kwargs):
224
240
@staticmethod
225
241
def get_matching_commands (
226
242
base_url : str , config : Optional [Union ["ConfigDict" , "StackedConfig" ]] = None
227
- ):
243
+ ) -> Iterator [ Tuple [ str , bool ]] :
228
244
config = config or StackedConfig .default ()
229
245
if isinstance (config , StackedConfig ):
230
246
backends : Iterable ["ConfigDict" ] = config .backends
@@ -240,7 +256,11 @@ def get_matching_commands(
240
256
except KeyError :
241
257
# no helper configured
242
258
continue
243
- yield command .decode (conf .encoding or sys .getdefaultencoding ())
259
+ use_http_path = conf .get_boolean (section , "usehttppath" , False )
260
+ yield (
261
+ command .decode (conf .encoding or sys .getdefaultencoding ()),
262
+ use_http_path ,
263
+ )
244
264
245
265
246
266
class _CredentialKey (NamedTuple ):
@@ -542,8 +562,8 @@ def describe(self, use_path: bool = False, sanitize: bool = True) -> str:
542
562
def helpers (self ) -> List ["CredentialHelper" ]:
543
563
url = self .url
544
564
return [
545
- GitCredentialHelper (command )
546
- for command in GitCredentialHelper .get_matching_commands (url )
565
+ GitCredentialHelper (command , use_http_path = use_http_path )
566
+ for command , use_http_path in GitCredentialHelper .get_matching_commands (url )
547
567
]
548
568
549
569
def fill (self , interactive : bool = True ) -> "Credential" :
0 commit comments