diff --git a/common/git_utils.go b/common/git_utils.go index 8b72327..9e4183e 100644 --- a/common/git_utils.go +++ b/common/git_utils.go @@ -122,12 +122,15 @@ func AllocateGitWorkTree(basePath, gitAuthor, email string) (GitHandlerGenerator func (s *gitHandlerGeneratorImpl) CreateGitHandler(org string) (Git, error) { path := path.Join(s.path, org) - if fs, err := os.Stat(s.path); err != nil || !fs.IsDir() { + if fs, err := os.Stat(path); (err != nil && !os.IsNotExist(err)) || (err == nil && !fs.IsDir()) { return nil, err - } else if os.IsNotExist(err) { + } else if err != nil && os.IsNotExist(err) { + log.Println("creating dirs") if err := os.MkdirAll(path, 0o777); err != nil && !os.IsExist(err) { return nil, err } + } else { + log.Println(fs, err) } return s.ReadExistingPath(org) @@ -210,8 +213,10 @@ func (e *GitHandlerImpl) GitClone(repo, branch, remoteUrl string) error { } remoteName := remoteUrlComp.RemoteName() + log.Println("Clone", *remoteUrlComp, " -> ", remoteName) + if fi, err := os.Stat(path.Join(e.GitPath, repo)); os.IsNotExist(err) { - if err = e.GitExec("", "clone", remoteUrl, repo); err != nil { + if err = e.GitExec("", "clone", "--origin", remoteName, remoteUrl, repo); err != nil { return err } } else if err != nil || !fi.IsDir() { diff --git a/workflow-direct/main.go b/workflow-direct/main.go index 13760c5..69d9583 100644 --- a/workflow-direct/main.go +++ b/workflow-direct/main.go @@ -108,7 +108,7 @@ func processConfiguredRepositoryAction(action *common.RepositoryWebhookEvent, co } if _, err := fs.Stat(os.DirFS(git.GetPath()), config.GitProjectName); errors.Is(err, os.ErrNotExist) { - common.PanicOnError(git.GitClone(gitPrj, config.Branch, prjGitRepo.SSHURL)) + common.PanicOnError(git.GitClone(gitPrj, gitBranch, prjGitRepo.SSHURL)) } switch action.Action {