mirror of https://gitlab.com/gitlab-org/cli.git
fix: remote nickname(--remote-var) should default to origin
This commit is contained in:
parent
f3c0478596
commit
24361aef91
|
@ -22,3 +22,7 @@ cmd/glab/dist
|
|||
.glab-cli
|
||||
|
||||
/.vscode/
|
||||
|
||||
.glab-cli
|
||||
.glab-cli
|
||||
.glab-cli
|
|
@ -99,7 +99,7 @@ func cmdErr(cmd *cobra.Command, args []string) {
|
|||
func initConfigCmd() {
|
||||
configCmd.Flags().BoolP("global", "g", false, "Set configuration globally")
|
||||
configCmd.Flags().StringP("url", "u", "", "specify the url of the gitlab server if self hosted (eg: https://gitlab.example.com).")
|
||||
configCmd.Flags().StringP("remote-var", "o", "", "delete merge request <id>")
|
||||
configCmd.Flags().StringP("remote-var", "o", "", "Shorthand name for the remote repository. An example of a remote shorthand name is `origin`")
|
||||
configCmd.Flags().StringP("token", "t", "", "an authentication token for API requests.")
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/MakeNowJust/heredoc"
|
||||
"log"
|
||||
"net/url"
|
||||
"os"
|
||||
|
@ -35,17 +36,26 @@ func GetRemoteURL() string {
|
|||
remoteNickname = "origin"
|
||||
}
|
||||
|
||||
if remoteNickname != "origin" {
|
||||
gitlabURL := strings.TrimSpace(config.GetEnv("GITLAB_URI"))
|
||||
gitRemoteURL := gitlabURL + "/" + remoteNickname + ".git"
|
||||
return gitRemoteURL
|
||||
} else {
|
||||
gitRemoteURL, err := gitconfig.Local("remote." + remoteNickname + ".url")
|
||||
if err != nil {
|
||||
log.Fatal("Could not find remote url for gitlab. Run glab config -g")
|
||||
gitRemoteURL, err := gitconfig.Local("remote." + remoteNickname + ".url")
|
||||
if err != nil {
|
||||
fmt.Println(heredoc.Doc(`
|
||||
|
||||
Could not find remote url for gitlab in remote.` + remoteNickname + `.url
|
||||
Possible errors:
|
||||
- This directory may not be a git repository`))
|
||||
if remoteNickname != "origin" {
|
||||
fmt.Printf("- `%s` does not exist or is an invalid shorthand name for the remote repository. An example of a remote shorthand name is `origin`\n", remoteNickname)
|
||||
}
|
||||
return gitRemoteURL
|
||||
fmt.Println(heredoc.Doc(`
|
||||
|
||||
Possible Fix:
|
||||
- Make sure the directory is a git repository
|
||||
- Run glab config -g --remote-var=<name>
|
||||
NB: change <name> to the shorthand name.
|
||||
`))
|
||||
os.Exit(0)
|
||||
}
|
||||
return gitRemoteURL
|
||||
}
|
||||
|
||||
func GetRemoteBaseURL() string {
|
||||
|
|
Loading…
Reference in New Issue