Fix Login Detection By Repo Param #151

Merged
6543 merged 5 commits from 6543/tea:fix-login-detection-by-repo-param into master 2020-07-17 16:36:52 +00:00
3 changed files with 22 additions and 12 deletions

View File

@ -189,10 +189,13 @@ func saveConfig(ymlPath string) error {
return ioutil.WriteFile(ymlPath, bs, 0660)
}
func curGitRepoPath() (*Login, string, error) {
repo, err := git.RepoForWorkdir()
if err != nil {
return nil, "", errors.New("No Gitea login found")
func curGitRepoPath(path string) (*Login, string, error) {
var err error
var repo *git.TeaRepo
if len(path) == 0 {
repo, err = git.RepoForWorkdir()
} else {
repo, err = git.RepoFromPath(path)
}
gitConfig, err := repo.Config()
if err != nil {

View File

@ -81,15 +81,10 @@ var AllDefaultFlags = append([]cli.Flag{
// initCommand returns repository and *Login based on flags
func initCommand() (*Login, string, string) {
login := initCommandLoginOnly()
lunny marked this conversation as resolved
Review

Why remove this line?

Why remove this line?
Review

login is overwritten later in any case now

login is overwritten later in any case now
login, repoPath, err := curGitRepoPath(repoValue)
if err != nil {
log.Fatal(err.Error())
var err error
repoPath := repoValue
if repoPath == "" {
login, repoPath, err = curGitRepoPath()
if err != nil {
log.Fatal(err.Error())
}
}
owner, repo := splitRepo(repoPath)

View File

@ -25,3 +25,15 @@ func RepoForWorkdir() (*TeaRepo, error) {
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
}