diff --git a/db/repos.go b/db/repos.go index 570a962..631b36c 100644 --- a/db/repos.go +++ b/db/repos.go @@ -23,21 +23,22 @@ func (db *DB) NewRepo(user *types.User, repo *types.Repo) (*git.Repository, erro return nil, errors.ErrRepoAlreadyExists // check if it already exists on a DB level. } - // create the actual git repo - git_repo, err := lib_git.InitRepo(user, &repo.ID) - if err != nil { - // cleanup - return nil, err - } - // create the record inside the db - err = db.Create(repo).Error + err := db.Create(repo).Error if err != nil { if strings.Contains(err.Error(), "UNIQUE constraint") { return nil, errors.ErrRepoAlreadyExists // shouldn't happen but handle gracefully, just in case. } return nil, err } + + // create the actual git repo + git_repo, err := lib_git.InitRepo(user, &repo.ID) + if err != nil { + // cleanup + db.Where(&repo).Delete(&repo) + return nil, err + } defer func() { _ = git_repo.Close() }()