Variable expansion in repository templates (#9163)

* Start expansion

Signed-off-by: jolheiser <john.olheiser@gmail.com>

* _template rather than .template

Signed-off-by: jolheiser <john.olheiser@gmail.com>

* Use ioutil

Signed-off-by: jolheiser <john.olheiser@gmail.com>

* Add descriptions to mapping

* Start globbing

Signed-off-by: jolheiser <john.olheiser@gmail.com>

* Tune globbing

Signed-off-by: jolheiser <john.olheiser@gmail.com>

* Re-arrange imports

Signed-off-by: jolheiser <john.olheiser@gmail.com>

* Don't expand git hooks

Signed-off-by: jolheiser <john.olheiser@gmail.com>

* Add glob tests for .giteatemplate

Signed-off-by: jolheiser <john.olheiser@gmail.com>

* Parse globs separately so they can be tested more easily

Signed-off-by: jolheiser <john.olheiser@gmail.com>

* Change template location and add docs

Signed-off-by: jolheiser <john.olheiser@gmail.com>

* nit

Signed-off-by: jolheiser <john.olheiser@gmail.com>

* Update docs/content/doc/features/gitea-directory.md

Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com>

* Update docs/content/doc/features/gitea-directory.md

Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com>

* Add upper-lower case match

Signed-off-by: jolheiser <john.olheiser@gmail.com>

* Nits

Signed-off-by: jolheiser <john.olheiser@gmail.com>

* Update models/repo_generate.go

Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com>
This commit is contained in:
John Olheiser 2019-11-30 00:54:47 -06:00 committed by techknowlogick
parent c9d50bcab5
commit 15a5c10d33
5 changed files with 298 additions and 51 deletions

View file

@ -1361,54 +1361,6 @@ func prepareRepoCommit(e Engine, repo *Repository, tmpDir, repoPath string, opts
return nil
}
func generateRepoCommit(e Engine, repo, templateRepo *Repository, tmpDir string) error {
commitTimeStr := time.Now().Format(time.RFC3339)
authorSig := repo.Owner.NewGitSig()
// Because this may call hooks we should pass in the environment
env := append(os.Environ(),
"GIT_AUTHOR_NAME="+authorSig.Name,
"GIT_AUTHOR_EMAIL="+authorSig.Email,
"GIT_AUTHOR_DATE="+commitTimeStr,
"GIT_COMMITTER_NAME="+authorSig.Name,
"GIT_COMMITTER_EMAIL="+authorSig.Email,
"GIT_COMMITTER_DATE="+commitTimeStr,
)
// Clone to temporary path and do the init commit.
templateRepoPath := templateRepo.repoPath(e)
_, stderr, err := process.GetManager().ExecDirEnv(
-1, "",
fmt.Sprintf("generateRepoCommit(git clone): %s", templateRepoPath),
env,
git.GitExecutable, "clone", "--depth", "1", templateRepoPath, tmpDir,
)
if err != nil {
return fmt.Errorf("git clone: %v - %s", err, stderr)
}
if err := os.RemoveAll(path.Join(tmpDir, ".git")); err != nil {
return fmt.Errorf("remove git dir: %v", err)
}
if err := git.InitRepository(tmpDir, false); err != nil {
return err
}
repoPath := repo.repoPath(e)
_, stderr, err = process.GetManager().ExecDirEnv(
-1, tmpDir,
fmt.Sprintf("generateRepoCommit(git remote add): %s", repoPath),
env,
git.GitExecutable, "remote", "add", "origin", repoPath,
)
if err != nil {
return fmt.Errorf("git remote add: %v - %s", err, stderr)
}
return initRepoCommit(tmpDir, repo.Owner)
}
func checkInitRepository(repoPath string) (err error) {
// Somehow the directory could exist.
if com.IsExist(repoPath) {