mirror of
https://gitea.com/gitea/tea.git
synced 2024-11-24 03:21:36 +01:00
4cda7e0299
Merge branch 'master' into issue-97/pulls-clean vendor terminal dependency pull/push: provide authentication method automatically select an AuthMethod according to the remote url type. If required, credentials are prompted for login: store username & optional keyfile refactor refactor GetRemote Merge branch 'master' into issue-97/pulls-clean adress code review add --ignore-sha flag When set, the local branch is not matched against the remote sha, but the remote branch name. This makes the command more flexible with diverging branches. add missing error check fix branch-not-found case Merge branch 'master' into issue-97/pulls-clean use directory namespaces for branches & remotes fix TeaCreateBranch() improve method of TeaFindBranch() now only checking .git/refs instead of looking up .git/config which may not list the branch add `tea pulls clean` fixes #97 add copyright to new files make linter happy refactor: use new git functions for old code add `tea pulls checkout` Co-authored-by: Norwin Roosen <git@nroo.de> Co-authored-by: Norwin <git@nroo.de> Reviewed-on: https://gitea.com/gitea/tea/pulls/105 Reviewed-by: 6543 <6543@noreply.gitea.io> Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
121 lines
3.0 KiB
Go
121 lines
3.0 KiB
Go
// Copyright 2019 The Gitea Authors. All rights reserved.
|
|
// Use of this source code is governed by a MIT-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package cmd
|
|
|
|
import (
|
|
"log"
|
|
|
|
"github.com/urfave/cli/v2"
|
|
)
|
|
|
|
// create global variables for global Flags to simplify
|
|
// access to the options without requiring cli.Context
|
|
var (
|
|
loginValue string
|
|
repoValue string
|
|
outputValue string
|
|
remoteValue string
|
|
)
|
|
|
|
// LoginFlag provides flag to specify tea login profile
|
|
var LoginFlag = cli.StringFlag{
|
|
Name: "login",
|
|
Aliases: []string{"l"},
|
|
Usage: "Use a different Gitea login. Optional",
|
|
Destination: &loginValue,
|
|
}
|
|
|
|
// RepoFlag provides flag to specify repository
|
|
var RepoFlag = cli.StringFlag{
|
|
Name: "repo",
|
|
Aliases: []string{"r"},
|
|
Usage: "Repository to interact with. Optional",
|
|
Destination: &repoValue,
|
|
}
|
|
|
|
// RemoteFlag provides flag to specify remote repository
|
|
var RemoteFlag = cli.StringFlag{
|
|
Name: "remote",
|
|
Aliases: []string{"R"},
|
|
Usage: "Discover Gitea login from remote. Optional",
|
|
Destination: &remoteValue,
|
|
}
|
|
|
|
// OutputFlag provides flag to specify output type
|
|
var OutputFlag = cli.StringFlag{
|
|
Name: "output",
|
|
Aliases: []string{"o"},
|
|
Usage: "Output format. (csv, simple, table, tsv, yaml)",
|
|
Destination: &outputValue,
|
|
}
|
|
|
|
// LoginOutputFlags defines login and output flags that should
|
|
// added to all subcommands and appended to the flags of the
|
|
// subcommand to work around issue and provide --login and --output:
|
|
// https://github.com/urfave/cli/issues/585
|
|
var LoginOutputFlags = []cli.Flag{
|
|
&LoginFlag,
|
|
&OutputFlag,
|
|
}
|
|
|
|
// LoginRepoFlags defines login and repo flags that should
|
|
// be used for all subcommands and appended to the flags of
|
|
// the subcommand to work around issue and provide --login and --repo:
|
|
// https://github.com/urfave/cli/issues/585
|
|
var LoginRepoFlags = []cli.Flag{
|
|
&LoginFlag,
|
|
&RepoFlag,
|
|
&RemoteFlag,
|
|
}
|
|
|
|
// AllDefaultFlags defines flags that should be available
|
|
// for all subcommands working with dedicated repositories
|
|
// to work around issue and provide --login, --repo and --output:
|
|
// https://github.com/urfave/cli/issues/585
|
|
var AllDefaultFlags = append([]cli.Flag{
|
|
&RepoFlag,
|
|
&RemoteFlag,
|
|
}, LoginOutputFlags...)
|
|
|
|
// initCommand returns repository and *Login based on flags
|
|
func initCommand() (*Login, string, string) {
|
|
login := initCommandLoginOnly()
|
|
|
|
var err error
|
|
repoPath := repoValue
|
|
if repoPath == "" {
|
|
login, repoPath, err = curGitRepoPath()
|
|
if err != nil {
|
|
log.Fatal(err.Error())
|
|
}
|
|
}
|
|
|
|
owner, repo := splitRepo(repoPath)
|
|
return login, owner, repo
|
|
}
|
|
|
|
// initCommandLoginOnly return *Login based on flags
|
|
func initCommandLoginOnly() *Login {
|
|
err := loadConfig(yamlConfigPath)
|
|
if err != nil {
|
|
log.Fatal("load config file failed ", yamlConfigPath)
|
|
}
|
|
|
|
var login *Login
|
|
if loginValue == "" {
|
|
login, err = getActiveLogin()
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
} else {
|
|
login = getLoginByName(loginValue)
|
|
if login == nil {
|
|
log.Fatal("Login name " + loginValue + " does not exist")
|
|
}
|
|
}
|
|
|
|
return login
|
|
}
|