MCPcopy Create free account
hub / github.com/gogs/gogs / prepareRepoCommit

Function prepareRepoCommit

internal/database/repo.go:990–1049  ·  view source on GitHub ↗
(repo *Repository, tmpDir, repoPath string, opts CreateRepoOptionsLegacy)

Source from the content-addressed store, hash-verified

988}
989
990func prepareRepoCommit(repo *Repository, tmpDir, repoPath string, opts CreateRepoOptionsLegacy) error {
991 // Clone to temporary path and do the init commit.
992 err := git.Clone(repoPath, tmpDir, git.CloneOptions{})
993 if err != nil {
994 return errors.Wrap(err, "clone")
995 }
996
997 // README
998 data, err := getRepoInitFile("readme", opts.Readme)
999 if err != nil {
1000 return errors.Newf("getRepoInitFile[%s]: %v", opts.Readme, err)
1001 }
1002
1003 cloneLink := repo.CloneLink()
1004 match := map[string]string{
1005 "Name": repo.Name,
1006 "Description": repo.Description,
1007 "CloneURL.SSH": cloneLink.SSH,
1008 "CloneURL.HTTPS": cloneLink.HTTPS,
1009 }
1010 if err = os.WriteFile(filepath.Join(tmpDir, "README.md"),
1011 []byte(com.Expand(string(data), match)), 0o644); err != nil {
1012 return errors.Newf("write README.md: %v", err)
1013 }
1014
1015 // .gitignore
1016 if len(opts.Gitignores) > 0 {
1017 var buf bytes.Buffer
1018 names := strings.Split(opts.Gitignores, ",")
1019 for _, name := range names {
1020 data, err = getRepoInitFile("gitignore", name)
1021 if err != nil {
1022 return errors.Newf("getRepoInitFile[%s]: %v", name, err)
1023 }
1024 buf.WriteString("# ---> " + name + "\n")
1025 buf.Write(data)
1026 buf.WriteString("\n")
1027 }
1028
1029 if buf.Len() > 0 {
1030 if err = os.WriteFile(filepath.Join(tmpDir, ".gitignore"), buf.Bytes(), 0o644); err != nil {
1031 return errors.Newf("write .gitignore: %v", err)
1032 }
1033 }
1034 }
1035
1036 // LICENSE
1037 if len(opts.License) > 0 {
1038 data, err = getRepoInitFile("license", opts.License)
1039 if err != nil {
1040 return errors.Newf("getRepoInitFile[%s]: %v", opts.License, err)
1041 }
1042
1043 if err = os.WriteFile(filepath.Join(tmpDir, "LICENSE"), data, 0o644); err != nil {
1044 return errors.Newf("write LICENSE: %v", err)
1045 }
1046 }
1047

Callers 1

initRepositoryFunction · 0.85

Calls 7

getRepoInitFileFunction · 0.85
stringFunction · 0.85
CloneLinkMethod · 0.80
SplitMethod · 0.80
WriteMethod · 0.80
BytesMethod · 0.80
LenMethod · 0.65

Tested by

no test coverage detected