From 1731e00ebdd69625ad48de9aaaada67adeec5b53 Mon Sep 17 00:00:00 2001 From: Norwin Date: Thu, 23 Sep 2021 00:12:56 +0800 Subject: [PATCH] Don't skip reading the local repo when `--repo` specifies a repo slug (#398) I added this check in #327, but it wasn't needed at all as the error case it intended to catch where already handled by checking if the path exists. fixes #378 Co-authored-by: Norwin Reviewed-on: https://gitea.com/gitea/tea/pulls/398 Reviewed-by: 6543 <6543@obermui.de> Reviewed-by: Andrew Thornton Co-authored-by: Norwin Co-committed-by: Norwin --- modules/context/context.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/modules/context/context.go b/modules/context/context.go index 3c45911..e07ff9c 100644 --- a/modules/context/context.go +++ b/modules/context/context.go @@ -99,14 +99,13 @@ func InitCommand(ctx *cli.Context) *TeaContext { } } - if len(repoFlag) == 0 || repoFlagPathExists { - // try to read git repo & extract context, ignoring if PWD is not a repo - if c.LocalRepo, c.Login, c.RepoSlug, err = contextFromLocalRepo(repoPath, remoteFlag); err != nil { - if err == errNotAGiteaRepo || err == gogit.ErrRepositoryNotExists { - // we can deal with that, commands needing the optional values use ctx.Ensure() - } else { - log.Fatal(err.Error()) - } + // try to read local git repo & extract context: if repoFlag specifies a valid path, read repo in that dir, + // otherwise attempt PWD. if no repo is found, continue with default login + if c.LocalRepo, c.Login, c.RepoSlug, err = contextFromLocalRepo(repoPath, remoteFlag); err != nil { + if err == errNotAGiteaRepo || err == gogit.ErrRepositoryNotExists { + // we can deal with that, commands needing the optional values use ctx.Ensure() + } else { + log.Fatal(err.Error()) } }