Skip to content

Commit 5550415

Browse files
authored
cred: check pushurl before checking url (#967)
* cred: check pushurl before checking url if a remote has both a pushurl and a url, need_username_password should check the pushurl before checking the url since we might not need credentials for the former
1 parent 9eb30ec commit 5550415

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Fixed
1111
- Keep commit message when pre-commit hook fails ([#1035](https://github.com/extrawurst/gitui/issues/1035))
12+
- honor `pushurl` when checking whether we need username and password for pushing ([#953](https://github.com/extrawurst/gitui/issues/953))
1213

1314
## [0.19] - 2021-12-08 - Bare Repo Support
1415

asyncgit/src/sync/cred.rs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@ impl BasicAuthCredential {
3232
/// know if username and password are needed for this url
3333
pub fn need_username_password(repo_path: &RepoPath) -> Result<bool> {
3434
let repo = repo(repo_path)?;
35-
let url = repo
36-
.find_remote(&get_default_remote_in_repo(&repo)?)?
37-
.url()
35+
let remote =
36+
repo.find_remote(&get_default_remote_in_repo(&repo)?)?;
37+
let url = remote
38+
.pushurl()
39+
.or_else(|| remote.url())
3840
.ok_or(Error::UnknownRemote)?
3941
.to_owned();
4042
let is_http = url.starts_with("http");
@@ -188,6 +190,25 @@ mod tests {
188190
assert_eq!(need_username_password(repo_path).unwrap(), false);
189191
}
190192

193+
#[test]
194+
#[serial]
195+
fn test_dont_need_username_password_if_pushurl_ssh() {
196+
let (_td, repo) = repo_init().unwrap();
197+
let root = repo.path().parent().unwrap();
198+
let repo_path: &RepoPath =
199+
&root.as_os_str().to_str().unwrap().into();
200+
201+
repo.remote(DEFAULT_REMOTE_NAME, "http://[email protected]")
202+
.unwrap();
203+
repo.remote_set_pushurl(
204+
DEFAULT_REMOTE_NAME,
205+
Some("[email protected]:user/repo"),
206+
)
207+
.unwrap();
208+
209+
assert_eq!(need_username_password(repo_path).unwrap(), false);
210+
}
211+
191212
#[test]
192213
#[serial]
193214
#[should_panic]

0 commit comments

Comments
 (0)