upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/bin/ngit/sub_commands/login.rs
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2024-11-22 16:13:11 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2024-11-22 16:13:11 +0000
commitf1b834df4ca8368d7815ccb78e205b15074f23c6 (patch)
tree230984bafe5b9b223d515725ac4d8d0ef0993a24 /src/bin/ngit/sub_commands/login.rs
parent89b16f0ff5cf4774043caa23b83add21c91df14f (diff)
fix(login): `ngit login` from outside git repo
it previously only worked from within or near a git repo directory
Diffstat (limited to 'src/bin/ngit/sub_commands/login.rs')
-rw-r--r--src/bin/ngit/sub_commands/login.rs19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/bin/ngit/sub_commands/login.rs b/src/bin/ngit/sub_commands/login.rs
index ae5efb1..bdd215f 100644
--- a/src/bin/ngit/sub_commands/login.rs
+++ b/src/bin/ngit/sub_commands/login.rs
@@ -20,17 +20,24 @@ pub struct SubCommandArgs {
20} 20}
21 21
22pub async fn launch(_args: &Cli, command_args: &SubCommandArgs) -> Result<()> { 22pub async fn launch(_args: &Cli, command_args: &SubCommandArgs) -> Result<()> {
23 let git_repo = Repo::discover().context("cannot find a git repository")?;
24 // TODO show existing login on record, prompt to logout 23 // TODO show existing login on record, prompt to logout
25 // TODO use cli arguments to login 24 // TODO use cli arguments to login
25 let git_repo_result = Repo::discover().context("cannot find a git repository");
26
26 if command_args.offline { 27 if command_args.offline {
27 fresh_login_or_signup(&Some(&git_repo), None, command_args.local).await?; 28 if let Ok(git_repo) = git_repo_result {
28 Ok(()) 29 fresh_login_or_signup(&Some(&git_repo), None, command_args.local).await?;
30 } else {
31 fresh_login_or_signup(&None, None, command_args.local).await?;
32 }
29 } else { 33 } else {
30 let client = Client::default(); 34 let client = Client::default();
31 fresh_login_or_signup(&Some(&git_repo), Some(&client), command_args.local).await?; 35 if let Ok(git_repo) = git_repo_result {
32 36 fresh_login_or_signup(&Some(&git_repo), Some(&client), command_args.local).await?;
37 } else {
38 fresh_login_or_signup(&None, Some(&client), command_args.local).await?;
39 }
33 client.disconnect().await?; 40 client.disconnect().await?;
34 Ok(())
35 } 41 }
42 Ok(())
36} 43}