diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-11-21 16:53:17 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-11-21 16:53:17 +0000 |
| commit | f79014235e85554e3661b3f2a02b8fa88bc192ff (patch) | |
| tree | fceec3ff2df212148a3420af7cef81a3f818463e /src/lib/git | |
| parent | 91b0eac4daf92b7b740267ef203a1a8ba591974b (diff) | |
feat(login): overhaul login experience
* simplify login menu, making it more accessable to newcomers and
easier to select remote signer options
* enable `ngit login` to work from anywhere (not just a git repo)
* assume fresh login details saved to global git config but fallback
to local repository
* maintain local repository login via `ngit login --local`
* maintain login via CLI arguments eg `ngit send --nsec nsec123`
* nudge users to remember nsec when pasting in ncryptsec for a
better UX, whilst maintaining the option to be prompted for
password everytime
* create placeholder menu items for help menu and create account
Diffstat (limited to 'src/lib/git')
| -rw-r--r-- | src/lib/git/mod.rs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/lib/git/mod.rs b/src/lib/git/mod.rs index 5d14ce3..45ac58c 100644 --- a/src/lib/git/mod.rs +++ b/src/lib/git/mod.rs | |||
| @@ -860,6 +860,44 @@ fn extract_sig_from_patch_tags<'a>(tags: &'a Tags, tag_name: &str) -> Result<git | |||
| 860 | .context("failed to create git signature") | 860 | .context("failed to create git signature") |
| 861 | } | 861 | } |
| 862 | 862 | ||
| 863 | pub fn get_git_config_item(git_repo: &Option<&Repo>, item: &str) -> Result<Option<String>> { | ||
| 864 | if let Some(git_repo) = git_repo { | ||
| 865 | git_repo.get_git_config_item(item, Some(false)) | ||
| 866 | } else { | ||
| 867 | Ok( | ||
| 868 | match git2::Config::open_default()?.open_global()?.get_entry(item) { | ||
| 869 | Ok(item) => item.value().map(|v| v.to_string()), | ||
| 870 | Err(_) => None, | ||
| 871 | }, | ||
| 872 | ) | ||
| 873 | } | ||
| 874 | } | ||
| 875 | |||
| 876 | pub fn save_git_config_item(git_repo: &Option<&Repo>, item: &str, value: &str) -> Result<()> { | ||
| 877 | if let Some(git_repo) = git_repo { | ||
| 878 | git_repo.save_git_config_item(item, value, false) | ||
| 879 | } else { | ||
| 880 | git2::Config::open_default()? | ||
| 881 | .open_global()? | ||
| 882 | .set_str(item, value) | ||
| 883 | .context(format!("cannot set global git config item {}", item)) | ||
| 884 | } | ||
| 885 | } | ||
| 886 | |||
| 887 | pub fn remove_git_config_item(git_repo: &Option<&Repo>, item: &str) -> Result<bool> { | ||
| 888 | if let Some(git_repo) = git_repo { | ||
| 889 | git_repo.remove_git_config_item(item, false) | ||
| 890 | } else if get_git_config_item(&None, item)?.is_none() { | ||
| 891 | Ok(false) | ||
| 892 | } else { | ||
| 893 | git2::Config::open_default()? | ||
| 894 | .open_global()? | ||
| 895 | .remove(item) | ||
| 896 | .context(format!("cannot remove existing git config item {}", item))?; | ||
| 897 | Ok(true) | ||
| 898 | } | ||
| 899 | } | ||
| 900 | |||
| 863 | #[cfg(test)] | 901 | #[cfg(test)] |
| 864 | mod tests { | 902 | mod tests { |
| 865 | use std::fs; | 903 | use std::fs; |