Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding credential fill to the executed commands in the CredentialHelper #1006

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/cred.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,9 @@ impl CredentialHelper {
}
let global = config.get_string("credential.helper");
self.add_command(global.as_ref().ok().map(|s| &s[..]));

// add the "fill" command
self.add_command(Some("!git credential fill"));
}

// Discover `useHttpPath` from `config`
Expand Down Expand Up @@ -303,7 +306,7 @@ impl CredentialHelper {
} else if cmd.contains("/") || cmd.contains("\\") {
self.commands.push(cmd.to_string());
} else {
self.commands.push(format!("git credential-{}", cmd));
self.commands.push(format!("git credential-{} get", cmd));
}
}

Expand All @@ -329,8 +332,11 @@ impl CredentialHelper {
let mut password = None;
for cmd in &self.commands {
let (u, p) = self.execute_cmd(cmd, &username);
if u.is_some() && username.is_none() {
username = u;
#[allow(clippy::collapsible_if)]
if let Some(u) = u {
if !u.is_empty() && username.is_none() {
username = Some(u);
}
}
if p.is_some() && password.is_none() {
password = p;
Expand Down Expand Up @@ -374,7 +380,7 @@ impl CredentialHelper {
// sure it works.
let mut c = Command::new("sh");
c.arg("-c")
.arg(&format!("{} get", cmd))
.arg(cmd)
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::piped());
Expand Down