Skip to content

Commit e02d748

Browse files
committed
Add git.ssh-key-file setting. This allows opting into a custom SSH key
file, overriding the hardcoded defaults of ~/.ssh/id_ed25519_sk, ~/.ssh/id_ed25519, and ~/.ssh/id_rsa.
1 parent f3bbc50 commit e02d748

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

cli/src/config-schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,11 @@
390390
"type": "string",
391391
"description": "Path to the git executable",
392392
"default": "git"
393+
},
394+
"ssh-key-file": {
395+
"type": "string",
396+
"description": "Path to SSH key file to use; by default, uses the following files in ~/.ssh: id_ed25519_sk, id_ed25519, id_rsa",
397+
"default": ""
393398
}
394399
}
395400
},

cli/src/git_util.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,11 @@ pub fn with_remote_git_callbacks<T>(
311311
.map(|x| x as &mut dyn FnMut(&git::Progress));
312312
callbacks.sideband_progress =
313313
sideband_progress_callback.map(|x| x as &mut dyn FnMut(&[u8]));
314-
let mut get_ssh_keys = get_ssh_keys; // Coerce to unit fn type
314+
let mut get_ssh_keys: &mut dyn FnMut(&str) -> Vec<PathBuf> =
315+
match &git_settings.ssh_key_file {
316+
None => &mut get_ssh_keys, // Coerce to unit fn type
317+
Some(ssh_key_file) => &mut |_: &str| -> Vec<PathBuf> { vec![ssh_key_file.clone()] },
318+
};
315319
callbacks.get_ssh_keys = Some(&mut get_ssh_keys);
316320
let mut get_pw =
317321
|url: &str, _username: &str| pinentry_get_pw(url).or_else(|| terminal_get_pw(ui, url));

lib/src/settings.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ pub struct GitSettings {
6161
pub abandon_unreachable_commits: bool,
6262
pub subprocess: bool,
6363
pub executable_path: PathBuf,
64+
pub ssh_key_file: Option<PathBuf>,
6465
}
6566

6667
impl GitSettings {
@@ -70,6 +71,17 @@ impl GitSettings {
7071
abandon_unreachable_commits: settings.get_bool("git.abandon-unreachable-commits")?,
7172
subprocess: settings.get_bool("git.subprocess")?,
7273
executable_path: settings.get("git.executable-path")?,
74+
ssh_key_file: match settings.get_string("git.ssh-key-file") {
75+
Ok(ssh_key_file) => {
76+
let trimmed_ssh_key_file = ssh_key_file.trim();
77+
if trimmed_ssh_key_file.is_empty() {
78+
None
79+
} else {
80+
Some(PathBuf::from(trimmed_ssh_key_file))
81+
}
82+
}
83+
Err(_) => None,
84+
},
7385
})
7486
}
7587
}
@@ -81,6 +93,7 @@ impl Default for GitSettings {
8193
abandon_unreachable_commits: true,
8294
subprocess: false,
8395
executable_path: PathBuf::from("git"),
96+
ssh_key_file: None,
8497
}
8598
}
8699
}

0 commit comments

Comments
 (0)