mirror of
https://gitea.com/gitea/tea.git
synced 2024-11-25 03:51:36 +01:00
Use Different Remote Repos (#58)
This commit is contained in:
parent
cd1ddb86b5
commit
0515114fa3
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
||||
tea
|
||||
.idea/
|
||||
|
@ -195,9 +195,31 @@ func curGitRepoPath() (*Login, string, error) {
|
||||
if err := gitConfig.Unmarshal(bs); err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
remoteConfig, ok := gitConfig.Remotes["origin"]
|
||||
|
||||
// if no remote
|
||||
if len(gitConfig.Remotes) == 0 {
|
||||
return nil, "", errors.New("No remote repository set on this git repository")
|
||||
}
|
||||
|
||||
// if only one remote exists
|
||||
if len(gitConfig.Remotes) >= 1 && len(remoteValue) == 0 {
|
||||
for remote := range gitConfig.Remotes {
|
||||
remoteValue = remote
|
||||
}
|
||||
if len(gitConfig.Remotes) > 1 {
|
||||
// if master branch is present, use it as the default remote
|
||||
masterBranch, ok := gitConfig.Branches["master"]
|
||||
if ok {
|
||||
if len(masterBranch.Remote) > 0 {
|
||||
remoteValue = masterBranch.Remote
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
remoteConfig, ok := gitConfig.Remotes[remoteValue]
|
||||
if !ok || remoteConfig == nil {
|
||||
return nil, "", errors.New("No remote origin found on this git repository")
|
||||
return nil, "", errors.New("No remote " + remoteValue + " found on this git repository")
|
||||
}
|
||||
|
||||
for _, l := range config.Logins {
|
||||
|
@ -16,6 +16,7 @@ var (
|
||||
loginValue string
|
||||
repoValue string
|
||||
outputValue string
|
||||
remoteValue string
|
||||
)
|
||||
|
||||
// LoginFlag provides flag to specify tea login profile
|
||||
@ -32,6 +33,13 @@ var RepoFlag = cli.StringFlag{
|
||||
Destination: &repoValue,
|
||||
}
|
||||
|
||||
// RemoteFlag provides flag to specify remote repository
|
||||
var RemoteFlag = cli.StringFlag{
|
||||
Name: "remote, R",
|
||||
Usage: "Set a specific remote repository, is optional if not set use git default one",
|
||||
Destination: &remoteValue,
|
||||
}
|
||||
|
||||
// OutputFlag provides flag to specify output type
|
||||
var OutputFlag = cli.StringFlag{
|
||||
Name: "output, o",
|
||||
@ -63,6 +71,7 @@ var LoginRepoFlags = []cli.Flag{
|
||||
// https://github.com/urfave/cli/issues/585
|
||||
var AllDefaultFlags = append([]cli.Flag{
|
||||
RepoFlag,
|
||||
RemoteFlag,
|
||||
}, LoginOutputFlags...)
|
||||
|
||||
// initCommand returns repository and *Login based on flags
|
||||
|
Loading…
Reference in New Issue
Block a user