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

Function CreateRepository

internal/database/repo.go:1214–1271  ·  view source on GitHub ↗

CreateRepository creates a repository for given user or organization.

(doer, owner *User, opts CreateRepoOptionsLegacy)

Source from the content-addressed store, hash-verified

1212
1213// CreateRepository creates a repository for given user or organization.
1214func CreateRepository(doer, owner *User, opts CreateRepoOptionsLegacy) (_ *Repository, err error) {
1215 repoPath := RepoPath(owner.Name, opts.Name)
1216 if osutil.Exist(repoPath) {
1217 return nil, errors.Errorf("repository directory already exists: %s", repoPath)
1218 }
1219 if !owner.canCreateRepo() {
1220 return nil, ErrReachLimitOfRepo{Limit: owner.maxNumRepos()}
1221 }
1222
1223 repo := &Repository{
1224 OwnerID: owner.ID,
1225 Owner: owner,
1226 Name: opts.Name,
1227 LowerName: strings.ToLower(opts.Name),
1228 Description: opts.Description,
1229 IsPrivate: opts.IsPrivate,
1230 IsUnlisted: opts.IsUnlisted,
1231 EnableWiki: true,
1232 EnableIssues: true,
1233 EnablePulls: true,
1234 }
1235
1236 sess := x.NewSession()
1237 defer sess.Close()
1238 if err = sess.Begin(); err != nil {
1239 return nil, err
1240 }
1241
1242 if err = createRepository(sess, doer, owner, repo); err != nil {
1243 return nil, err
1244 }
1245
1246 // No need for init mirror.
1247 if !opts.IsMirror {
1248 if err = initRepository(sess, repoPath, doer, repo, opts); err != nil {
1249 RemoveAllWithNotice("Delete repository for initialization failure", repoPath)
1250 return nil, errors.Newf("initRepository: %v", err)
1251 }
1252
1253 _, stderr, err := process.ExecDir(-1,
1254 repoPath, fmt.Sprintf("CreateRepository 'git update-server-info': %s", repoPath),
1255 "git", "update-server-info")
1256 if err != nil {
1257 return nil, errors.Newf("CreateRepository 'git update-server-info': %s", stderr)
1258 }
1259 }
1260 if err = sess.Commit(); err != nil {
1261 return nil, err
1262 }
1263
1264 // Remember visibility preference
1265 err = Handle.Users().Update(context.TODO(), owner.ID, UpdateUserOptions{LastRepoVisibility: &repo.IsPrivate})
1266 if err != nil {
1267 return nil, errors.Wrap(err, "update user")
1268 }
1269
1270 return repo, nil
1271}

Callers 4

CreatePostFunction · 0.92
CreateUserRepoFunction · 0.92
MigrateRepositoryFunction · 0.85

Calls 11

ExistFunction · 0.92
ExecDirFunction · 0.92
RepoPathFunction · 0.85
createRepositoryFunction · 0.85
RemoveAllWithNoticeFunction · 0.85
canCreateRepoMethod · 0.80
maxNumReposMethod · 0.80
UsersMethod · 0.80
initRepositoryFunction · 0.70
UpdateMethod · 0.65
ErrorfMethod · 0.45

Tested by 1