mirror of
https://gitea.com/gitea/tea.git
synced 2024-11-22 10:31:37 +01:00
Fix Login Detection By Repo Param (#151)
Fix login detection by Repo param Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/tea/pulls/151 Reviewed-by: lafriks <lafriks@noreply.gitea.io> Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
parent
19ee32168e
commit
2135af0304
@ -189,10 +189,13 @@ func saveConfig(ymlPath string) error {
|
|||||||
return ioutil.WriteFile(ymlPath, bs, 0660)
|
return ioutil.WriteFile(ymlPath, bs, 0660)
|
||||||
}
|
}
|
||||||
|
|
||||||
func curGitRepoPath() (*Login, string, error) {
|
func curGitRepoPath(path string) (*Login, string, error) {
|
||||||
repo, err := git.RepoForWorkdir()
|
var err error
|
||||||
if err != nil {
|
var repo *git.TeaRepo
|
||||||
return nil, "", errors.New("No Gitea login found")
|
if len(path) == 0 {
|
||||||
|
repo, err = git.RepoForWorkdir()
|
||||||
|
} else {
|
||||||
|
repo, err = git.RepoFromPath(path)
|
||||||
}
|
}
|
||||||
gitConfig, err := repo.Config()
|
gitConfig, err := repo.Config()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -81,15 +81,10 @@ var AllDefaultFlags = append([]cli.Flag{
|
|||||||
|
|
||||||
// initCommand returns repository and *Login based on flags
|
// initCommand returns repository and *Login based on flags
|
||||||
func initCommand() (*Login, string, string) {
|
func initCommand() (*Login, string, string) {
|
||||||
login := initCommandLoginOnly()
|
login, repoPath, err := curGitRepoPath(repoValue)
|
||||||
|
|
||||||
var err error
|
|
||||||
repoPath := repoValue
|
|
||||||
if repoPath == "" {
|
|
||||||
login, repoPath, err = curGitRepoPath()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err.Error())
|
log.Fatal(err.Error())
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
owner, repo := splitRepo(repoPath)
|
owner, repo := splitRepo(repoPath)
|
||||||
|
@ -25,3 +25,15 @@ func RepoForWorkdir() (*TeaRepo, error) {
|
|||||||
|
|
||||||
return &TeaRepo{repo}, nil
|
return &TeaRepo{repo}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RepoFromPath tries to open the git repository by path
|
||||||
|
func RepoFromPath(path string) (*TeaRepo, error) {
|
||||||
|
repo, err := git.PlainOpenWithOptions(path, &git.PlainOpenOptions{
|
||||||
|
DetectDotGit: true,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &TeaRepo{repo}, nil
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user