This commit is contained in:
Lunny Xiao
2025-10-03 12:25:46 -07:00
parent 376476150e
commit 7530fb23a6
3 changed files with 6 additions and 4 deletions

View File

@@ -56,7 +56,7 @@ func InitCommand(cmd *cli.Command) *context.TeaContext {
// try to read local git repo & extract context: if repoFlag specifies a valid path, read repo in that dir, // 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 // otherwise attempt PWD. if no repo is found, continue with default login
if c.LocalRepo, c.Login, c.RepoSlug, err = context.ContextFromLocalRepo(repoPath, remoteFlag); err != nil { if c.LocalRepo, c.Login, c.RepoSlug, err = context.FromLocalRepo(repoPath, remoteFlag); err != nil {
if err == context.ErrNotAGiteaRepo || err == gogit.ErrRepositoryNotExists { if err == context.ErrNotAGiteaRepo || err == gogit.ErrRepositoryNotExists {
// we can deal with that, commands needing the optional values use ctx.Ensure() // we can deal with that, commands needing the optional values use ctx.Ensure()
} else { } else {

View File

@@ -19,7 +19,8 @@ import (
"github.com/urfave/cli/v3" "github.com/urfave/cli/v3"
) )
var ErrNotAGiteaRepo = errors.New("No Gitea login found. You might want to specify --repo (and --login) to work outside of a repository") // ErrNotAGiteaRepo is returned when no Gitea login could be found for a local git repo
var ErrNotAGiteaRepo = errors.New("no Gitea login found. You might want to specify --repo (and --login) to work outside of a repository")
// TeaContext contains all context derived during command initialization and wraps cli.Context // TeaContext contains all context derived during command initialization and wraps cli.Context
type TeaContext struct { type TeaContext struct {
@@ -60,8 +61,8 @@ type CtxRequirement struct {
RemoteRepo bool RemoteRepo bool
} }
// ContextFromLocalRepo discovers login & repo slug from the default branch remote of the given local repo // FromLocalRepo discovers login & repo slug from the default branch remote of the given local repo
func ContextFromLocalRepo(repoPath, remoteValue string) (*git.TeaRepo, *config.Login, string, error) { func FromLocalRepo(repoPath, remoteValue string) (*git.TeaRepo, *config.Login, string, error) {
repo, err := git.RepoFromPath(repoPath) repo, err := git.RepoFromPath(repoPath)
if err != nil { if err != nil {
return nil, nil, "", err return nil, nil, "", err

View File

@@ -307,6 +307,7 @@ var tokenScopeOpts = []string{
string(gitea.AccessTokenScopeSudo), string(gitea.AccessTokenScopeSudo),
} }
// LoginSelect prompts the user to select a login if multiple are configured
func LoginSelect() (*config.Login, error) { func LoginSelect() (*config.Login, error) {
logins, err := config.GetLogins() logins, err := config.GetLogins()
if err != nil { if err != nil {