mirror of
https://gitea.com/gitea/tea.git
synced 2026-02-21 22:03:32 +01:00
- switch to golangci-lint for linting - switch to gofmpt for formatting - fix lint and fmt issues that came up from switch to new tools - upgrade go-sdk to 0.23.2 - support pagination for listing tracked times - remove `FixPullHeadSha` workaround (upstream fix has been merged for 5+ years at this point) - standardize on US spelling (previously a mix of US&UK spelling) - remove some unused code - reduce some duplication in parsing state and issue type - reduce some duplication in reading input for secrets and variables - reduce some duplication with PR Review code - report error for when yaml parsing fails - various other misc cleanup Reviewed-on: https://gitea.com/gitea/tea/pulls/869 Co-authored-by: techknowlogick <techknowlogick@gitea.com> Co-committed-by: techknowlogick <techknowlogick@gitea.com>
94 lines
2.1 KiB
Go
94 lines
2.1 KiB
Go
// Copyright 2021 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package cmd
|
|
|
|
import (
|
|
stdctx "context"
|
|
"fmt"
|
|
|
|
"code.gitea.io/tea/cmd/flags"
|
|
"code.gitea.io/tea/modules/config"
|
|
"code.gitea.io/tea/modules/context"
|
|
"code.gitea.io/tea/modules/debug"
|
|
"code.gitea.io/tea/modules/git"
|
|
"code.gitea.io/tea/modules/interact"
|
|
"code.gitea.io/tea/modules/task"
|
|
"code.gitea.io/tea/modules/utils"
|
|
|
|
"github.com/urfave/cli/v3"
|
|
)
|
|
|
|
// CmdRepoClone represents a sub command of repos to create a local copy
|
|
var CmdRepoClone = cli.Command{
|
|
Name: "clone",
|
|
Aliases: []string{"C"},
|
|
Usage: "Clone a repository locally",
|
|
Description: `Clone a repository locally, without a local git installation required.
|
|
The repo slug can be specified in different formats:
|
|
gitea/tea
|
|
tea
|
|
gitea.com/gitea/tea
|
|
git@gitea.com:gitea/tea
|
|
https://gitea.com/gitea/tea
|
|
ssh://gitea.com:22/gitea/tea
|
|
When a host is specified in the repo-slug, it will override the login specified with --login.
|
|
`,
|
|
Category: catHelpers,
|
|
Action: runRepoClone,
|
|
ArgsUsage: "<repo-slug> [target dir]",
|
|
Flags: []cli.Flag{
|
|
&cli.IntFlag{
|
|
Name: "depth",
|
|
Aliases: []string{"d"},
|
|
Usage: "num commits to fetch, defaults to all",
|
|
},
|
|
&flags.LoginFlag,
|
|
},
|
|
}
|
|
|
|
func runRepoClone(ctx stdctx.Context, cmd *cli.Command) error {
|
|
teaCmd := context.InitCommand(cmd)
|
|
|
|
args := teaCmd.Args()
|
|
if args.Len() < 1 {
|
|
return cli.ShowCommandHelp(ctx, cmd, "clone")
|
|
}
|
|
dir := args.Get(1)
|
|
|
|
var (
|
|
login *config.Login = teaCmd.Login
|
|
owner string
|
|
repo string
|
|
)
|
|
|
|
// parse first arg as repo specifier
|
|
repoSlug := args.Get(0)
|
|
url, err := git.ParseURL(repoSlug)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
debug.Printf("Cloning repository %s into %s", url.String(), dir)
|
|
|
|
owner, repo = utils.GetOwnerAndRepo(url.Path, login.User)
|
|
if url.Host != "" {
|
|
login = config.GetLoginByHost(url.Host)
|
|
if login == nil {
|
|
return fmt.Errorf("No login configured matching host '%s', run `tea login add` first", url.Host)
|
|
}
|
|
debug.Printf("Matched login '%s' for host '%s'", login.Name, url.Host)
|
|
}
|
|
|
|
_, err = task.RepoClone(
|
|
dir,
|
|
login,
|
|
owner,
|
|
repo,
|
|
interact.PromptPassword,
|
|
teaCmd.Int("depth"),
|
|
)
|
|
|
|
return err
|
|
}
|