From f1b834df4ca8368d7815ccb78e205b15074f23c6 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Fri, 22 Nov 2024 16:13:11 +0000 Subject: fix(login): `ngit login` from outside git repo it previously only worked from within or near a git repo directory --- src/bin/ngit/sub_commands/login.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'src/bin') 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 { } pub async fn launch(_args: &Cli, command_args: &SubCommandArgs) -> Result<()> { - let git_repo = Repo::discover().context("cannot find a git repository")?; // TODO show existing login on record, prompt to logout // TODO use cli arguments to login + let git_repo_result = Repo::discover().context("cannot find a git repository"); + if command_args.offline { - fresh_login_or_signup(&Some(&git_repo), None, command_args.local).await?; - Ok(()) + if let Ok(git_repo) = git_repo_result { + fresh_login_or_signup(&Some(&git_repo), None, command_args.local).await?; + } else { + fresh_login_or_signup(&None, None, command_args.local).await?; + } } else { let client = Client::default(); - fresh_login_or_signup(&Some(&git_repo), Some(&client), command_args.local).await?; - + if let Ok(git_repo) = git_repo_result { + fresh_login_or_signup(&Some(&git_repo), Some(&client), command_args.local).await?; + } else { + fresh_login_or_signup(&None, Some(&client), command_args.local).await?; + } client.disconnect().await?; - Ok(()) } + Ok(()) } -- cgit v1.2.3