@@ -26,86 +26,74 @@ class InvalidRepoCredentialsError(DstackError):
2626 pass
2727
2828
29- def get_repo_creds_and_default_branch (
29+ def get_repo_creds (
3030 repo_url : str ,
3131 identity_file : Optional [PathLike ] = None ,
3232 private_key : Optional [str ] = None ,
3333 oauth_token : Optional [str ] = None ,
34- ) -> tuple [ RemoteRepoCreds , Optional [ str ]] :
34+ ) -> RemoteRepoCreds :
3535 url = GitRepoURL .parse (repo_url , get_ssh_config = get_host_config )
3636
3737 # no auth
3838 with suppress (InvalidRepoCredentialsError ):
39- creds , default_branch = _get_repo_creds_and_default_branch_https (url )
40- logger .debug (
41- "Git repo %s is public. Using no auth. Default branch: %s" , repo_url , default_branch
42- )
43- return creds , default_branch
39+ creds = _get_repo_creds_https (url )
40+ logger .debug ("Git repo %s is public. Using no auth." , repo_url )
41+ return creds
4442
4543 # ssh key provided by the user or pulled from the server
4644 if identity_file is not None or private_key is not None :
4745 if identity_file is not None :
4846 private_key = _read_private_key (identity_file )
49- creds , default_branch = _get_repo_creds_and_default_branch_ssh (
50- url , identity_file , private_key
51- )
47+ creds = _get_repo_creds_ssh (url , identity_file , private_key )
5248 logger .debug (
53- "Git repo %s is private. Using identity file: %s. Default branch: %s " ,
49+ "Git repo %s is private. Using identity file: %s." ,
5450 repo_url ,
5551 identity_file ,
56- default_branch ,
5752 )
58- return creds , default_branch
53+ return creds
5954 elif private_key is not None :
6055 with NamedTemporaryFile ("w+" , 0o600 ) as f :
6156 f .write (private_key )
6257 f .flush ()
63- creds , default_branch = _get_repo_creds_and_default_branch_ssh (
64- url , f .name , private_key
65- )
58+ creds = _get_repo_creds_ssh (url , f .name , private_key )
6659 masked_key = "***" + private_key [- 10 :] if len (private_key ) > 10 else "***MASKED***"
6760 logger .debug (
6861 "Git repo %s is private. Using private key: %s. Default branch: %s" ,
6962 repo_url ,
7063 masked_key ,
71- default_branch ,
7264 )
73- return creds , default_branch
65+ return creds
7466 else :
7567 assert False , "should not reach here"
7668
7769 # oauth token provided by the user or pulled from the server
7870 if oauth_token is not None :
79- creds , default_branch = _get_repo_creds_and_default_branch_https (url , oauth_token )
71+ creds = _get_repo_creds_https (url , oauth_token )
8072 masked_token = (
8173 len (oauth_token [:- 4 ]) * "*" + oauth_token [- 4 :]
8274 if len (oauth_token ) > 4
8375 else "***MASKED***"
8476 )
8577 logger .debug (
86- "Git repo %s is private. Using provided OAuth token: %s. Default branch: %s " ,
78+ "Git repo %s is private. Using provided OAuth token: %s." ,
8779 repo_url ,
8880 masked_token ,
89- default_branch ,
9081 )
91- return creds , default_branch
82+ return creds
9283
9384 # key from ssh config
9485 identities = get_host_config (url .original_host ).get ("identityfile" )
9586 if identities :
9687 _identity_file = identities [0 ]
9788 with suppress (InvalidRepoCredentialsError ):
9889 _private_key = _read_private_key (_identity_file )
99- creds , default_branch = _get_repo_creds_and_default_branch_ssh (
100- url , _identity_file , _private_key
101- )
90+ creds = _get_repo_creds_ssh (url , _identity_file , _private_key )
10291 logger .debug (
103- "Git repo %s is private. Using SSH config identity file: %s. Default branch: %s " ,
92+ "Git repo %s is private. Using SSH config identity file: %s." ,
10493 repo_url ,
10594 _identity_file ,
106- default_branch ,
10795 )
108- return creds , default_branch
96+ return creds
10997
11098 # token from gh config
11199 if os .path .exists (gh_config_path ):
@@ -114,48 +102,44 @@ def get_repo_creds_and_default_branch(
114102 _oauth_token = gh_hosts .get (url .host , {}).get ("oauth_token" )
115103 if _oauth_token is not None :
116104 with suppress (InvalidRepoCredentialsError ):
117- creds , default_branch = _get_repo_creds_and_default_branch_https (url , _oauth_token )
105+ creds = _get_repo_creds_https (url , _oauth_token )
118106 masked_token = (
119107 len (_oauth_token [:- 4 ]) * "*" + _oauth_token [- 4 :]
120108 if len (_oauth_token ) > 4
121109 else "***MASKED***"
122110 )
123111 logger .debug (
124- "Git repo %s is private. Using GitHub config token: %s from %s. Default branch: %s " ,
112+ "Git repo %s is private. Using GitHub config token: %s from %s." ,
125113 repo_url ,
126114 masked_token ,
127115 gh_config_path ,
128- default_branch ,
129116 )
130- return creds , default_branch
117+ return creds
131118
132119 # default user key
133120 if os .path .exists (default_ssh_key ):
134121 with suppress (InvalidRepoCredentialsError ):
135122 _private_key = _read_private_key (default_ssh_key )
136- creds , default_branch = _get_repo_creds_and_default_branch_ssh (
137- url , default_ssh_key , _private_key
138- )
123+ creds = _get_repo_creds_ssh (url , default_ssh_key , _private_key )
139124 logger .debug (
140- "Git repo %s is private. Using default identity file: %s. Default branch: %s " ,
125+ "Git repo %s is private. Using default identity file: %s." ,
141126 repo_url ,
142127 default_ssh_key ,
143- default_branch ,
144128 )
145- return creds , default_branch
129+ return creds
146130
147131 raise InvalidRepoCredentialsError (
148132 "No valid default Git credentials found. Pass valid `--token` or `--git-identity`."
149133 )
150134
151135
152- def _get_repo_creds_and_default_branch_ssh (
136+ def _get_repo_creds_ssh (
153137 url : GitRepoURL , identity_file : PathLike , private_key : str
154- ) -> tuple [ RemoteRepoCreds , Optional [ str ]] :
138+ ) -> RemoteRepoCreds :
155139 _url = url .as_ssh ()
156140 env = _make_git_env_for_creds_check (identity_file = identity_file )
157141 try :
158- default_branch = _get_repo_default_branch (_url , env )
142+ _get_repo_default_branch (_url , env )
159143 except GitCommandError as e :
160144 message = f"Cannot access `{ _url } ` using the `{ identity_file } ` private SSH key"
161145 raise InvalidRepoCredentialsError (message ) from e
@@ -164,16 +148,14 @@ def _get_repo_creds_and_default_branch_ssh(
164148 private_key = private_key ,
165149 oauth_token = None ,
166150 )
167- return creds , default_branch
151+ return creds
168152
169153
170- def _get_repo_creds_and_default_branch_https (
171- url : GitRepoURL , oauth_token : Optional [str ] = None
172- ) -> tuple [RemoteRepoCreds , Optional [str ]]:
154+ def _get_repo_creds_https (url : GitRepoURL , oauth_token : Optional [str ] = None ) -> RemoteRepoCreds :
173155 _url = url .as_https ()
174156 env = _make_git_env_for_creds_check ()
175157 try :
176- default_branch = _get_repo_default_branch (url .as_https (oauth_token ), env )
158+ _get_repo_default_branch (url .as_https (oauth_token ), env )
177159 except GitCommandError as e :
178160 message = f"Cannot access `{ _url } `"
179161 if oauth_token is not None :
@@ -185,7 +167,7 @@ def _get_repo_creds_and_default_branch_https(
185167 private_key = None ,
186168 oauth_token = oauth_token ,
187169 )
188- return creds , default_branch
170+ return creds
189171
190172
191173def _make_git_env_for_creds_check (identity_file : Optional [PathLike ] = None ) -> dict [str , str ]:
0 commit comments