|
|
@ -133,14 +133,15 @@ func NewRepoContext() { |
|
|
|
|
|
|
|
|
|
|
|
// Repository represents a git repository.
|
|
|
|
// Repository represents a git repository.
|
|
|
|
type Repository struct { |
|
|
|
type Repository struct { |
|
|
|
Id int64 |
|
|
|
Id int64 |
|
|
|
OwnerId int64 `xorm:"UNIQUE(s)"` |
|
|
|
OwnerId int64 `xorm:"UNIQUE(s)"` |
|
|
|
Owner *User `xorm:"-"` |
|
|
|
Owner *User `xorm:"-"` |
|
|
|
ForkId int64 |
|
|
|
LowerName string `xorm:"UNIQUE(s) INDEX NOT NULL"` |
|
|
|
LowerName string `xorm:"UNIQUE(s) INDEX NOT NULL"` |
|
|
|
Name string `xorm:"INDEX NOT NULL"` |
|
|
|
Name string `xorm:"INDEX NOT NULL"` |
|
|
|
Description string |
|
|
|
Description string |
|
|
|
Website string |
|
|
|
Website string |
|
|
|
DefaultBranch string |
|
|
|
|
|
|
|
|
|
|
|
NumWatches int |
|
|
|
NumWatches int |
|
|
|
NumStars int |
|
|
|
NumStars int |
|
|
|
NumForks int |
|
|
|
NumForks int |
|
|
@ -154,15 +155,20 @@ type Repository struct { |
|
|
|
NumClosedMilestones int `xorm:"NOT NULL DEFAULT 0"` |
|
|
|
NumClosedMilestones int `xorm:"NOT NULL DEFAULT 0"` |
|
|
|
NumOpenMilestones int `xorm:"-"` |
|
|
|
NumOpenMilestones int `xorm:"-"` |
|
|
|
NumTags int `xorm:"-"` |
|
|
|
NumTags int `xorm:"-"` |
|
|
|
IsPrivate bool |
|
|
|
|
|
|
|
IsMirror bool |
|
|
|
IsPrivate bool |
|
|
|
*Mirror `xorm:"-"` |
|
|
|
IsBare bool |
|
|
|
IsFork bool `xorm:"NOT NULL DEFAULT false"` |
|
|
|
IsGoget bool |
|
|
|
IsBare bool |
|
|
|
|
|
|
|
IsGoget bool |
|
|
|
IsMirror bool |
|
|
|
DefaultBranch string |
|
|
|
*Mirror `xorm:"-"` |
|
|
|
Created time.Time `xorm:"CREATED"` |
|
|
|
|
|
|
|
Updated time.Time `xorm:"UPDATED"` |
|
|
|
IsFork bool `xorm:"NOT NULL DEFAULT false"` |
|
|
|
|
|
|
|
ForkId int64 |
|
|
|
|
|
|
|
ForkRepo *Repository `xorm:"-"` |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Created time.Time `xorm:"CREATED"` |
|
|
|
|
|
|
|
Updated time.Time `xorm:"UPDATED"` |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (repo *Repository) GetOwner() (err error) { |
|
|
|
func (repo *Repository) GetOwner() (err error) { |
|
|
@ -177,12 +183,31 @@ func (repo *Repository) GetMirror() (err error) { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (repo *Repository) GetPath() string { |
|
|
|
func (repo *Repository) GetForkRepo() (err error) { |
|
|
|
return RepoPath(repo.Owner.Name, repo.Name) |
|
|
|
if !repo.IsFork { |
|
|
|
|
|
|
|
return nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
repo.ForkRepo, err = GetRepositoryById(repo.ForkId) |
|
|
|
|
|
|
|
return err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (repo *Repository) RepoPath() (string, error) { |
|
|
|
|
|
|
|
if err := repo.GetOwner(); err != nil { |
|
|
|
|
|
|
|
return "", err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return RepoPath(repo.Owner.Name, repo.Name), nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (repo *Repository) RepoLink() (string, error) { |
|
|
|
|
|
|
|
if err := repo.GetOwner(); err != nil { |
|
|
|
|
|
|
|
return "", err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return setting.AppSubUrl + "/" + repo.Owner.Name + "/" + repo.Name, nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (repo *Repository) IsOwnedBy(u *User) bool { |
|
|
|
func (repo *Repository) IsOwnedBy(u *User) bool { |
|
|
|
return repo.OwnerId == u.Id |
|
|
|
return repo.OwnerId == u.Id |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (repo *Repository) HasAccess(uname string) bool { |
|
|
|
func (repo *Repository) HasAccess(uname string) bool { |
|
|
@ -947,12 +972,12 @@ func DeleteRepository(uid, repoId int64, userName string) error { |
|
|
|
sess.Rollback() |
|
|
|
sess.Rollback() |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if repo.IsFork { |
|
|
|
if repo.IsFork { |
|
|
|
if _, err = sess.Exec("UPDATE `repository` SET num_forks = num_forks - 1 WHERE id = ?", repo.ForkId); err != nil { |
|
|
|
if _, err = sess.Exec("UPDATE `repository` SET num_forks = num_forks - 1 WHERE id = ?", repo.ForkId); err != nil { |
|
|
|
sess.Rollback() |
|
|
|
sess.Rollback() |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if _, err = sess.Exec("UPDATE `user` SET num_repos = num_repos - 1 WHERE id = ?", uid); err != nil { |
|
|
|
if _, err = sess.Exec("UPDATE `user` SET num_repos = num_repos - 1 WHERE id = ?", uid); err != nil { |
|
|
@ -1147,32 +1172,36 @@ type Watch struct { |
|
|
|
RepoId int64 `xorm:"UNIQUE(watch)"` |
|
|
|
RepoId int64 `xorm:"UNIQUE(watch)"` |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Watch or unwatch repository.
|
|
|
|
// IsWatching checks if user has watched given repository.
|
|
|
|
func WatchRepo(uid, repoId int64, watch bool) (err error) { |
|
|
|
func IsWatching(uid, repoId int64) bool { |
|
|
|
|
|
|
|
has, _ := x.Get(&Watch{0, uid, repoId}) |
|
|
|
|
|
|
|
return has |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func watchRepoWithEngine(e Engine, uid, repoId int64, watch bool) (err error) { |
|
|
|
if watch { |
|
|
|
if watch { |
|
|
|
if IsWatching(uid, repoId) { |
|
|
|
if IsWatching(uid, repoId) { |
|
|
|
return nil |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|
if _, err = x.Insert(&Watch{RepoId: repoId, UserId: uid}); err != nil { |
|
|
|
if _, err = e.Insert(&Watch{RepoId: repoId, UserId: uid}); err != nil { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
_, err = x.Exec("UPDATE `repository` SET num_watches = num_watches + 1 WHERE id = ?", repoId) |
|
|
|
_, err = e.Exec("UPDATE `repository` SET num_watches = num_watches + 1 WHERE id = ?", repoId) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
if !IsWatching(uid, repoId) { |
|
|
|
if !IsWatching(uid, repoId) { |
|
|
|
return nil |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|
if _, err = x.Delete(&Watch{0, uid, repoId}); err != nil { |
|
|
|
if _, err = e.Delete(&Watch{0, uid, repoId}); err != nil { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
_, err = x.Exec("UPDATE `repository` SET num_watches = num_watches - 1 WHERE id = ?", repoId) |
|
|
|
_, err = e.Exec("UPDATE `repository` SET num_watches = num_watches - 1 WHERE id = ?", repoId) |
|
|
|
} |
|
|
|
} |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// IsWatching checks if user has watched given repository.
|
|
|
|
// Watch or unwatch repository.
|
|
|
|
func IsWatching(uid, rid int64) bool { |
|
|
|
func WatchRepo(uid, repoId int64, watch bool) (err error) { |
|
|
|
has, _ := x.Get(&Watch{0, uid, rid}) |
|
|
|
return watchRepoWithEngine(x, uid, repoId, watch) |
|
|
|
return has |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// GetWatchers returns all watchers of given repository.
|
|
|
|
// GetWatchers returns all watchers of given repository.
|
|
|
@ -1255,137 +1284,157 @@ func IsStaring(uid, repoId int64) bool { |
|
|
|
return has |
|
|
|
return has |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ___________ __
|
|
|
|
|
|
|
|
// \_ _____/__________| | __
|
|
|
|
|
|
|
|
// | __)/ _ \_ __ \ |/ /
|
|
|
|
|
|
|
|
// | \( <_> ) | \/ <
|
|
|
|
|
|
|
|
// \___ / \____/|__| |__|_ \
|
|
|
|
|
|
|
|
// \/ \/
|
|
|
|
|
|
|
|
|
|
|
|
func ForkRepository(u *User, oldRepo *Repository) (*Repository, error) { |
|
|
|
func ForkRepository(u *User, oldRepo *Repository) (*Repository, error) { |
|
|
|
isExist, err := IsRepositoryExist(u, oldRepo.Name) |
|
|
|
isExist, err := IsRepositoryExist(u, oldRepo.Name) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
return nil, err |
|
|
|
} else if isExist { |
|
|
|
} else if isExist { |
|
|
|
return nil, ErrRepoAlreadyExist |
|
|
|
return nil, ErrRepoAlreadyExist |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
sess := x.NewSession() |
|
|
|
// In case the old repository is a fork.
|
|
|
|
defer sess.Close() |
|
|
|
if oldRepo.IsFork { |
|
|
|
if err = sess.Begin(); err != nil { |
|
|
|
oldRepo, err = GetRepositoryById(oldRepo.ForkId) |
|
|
|
return nil, err |
|
|
|
if err != nil { |
|
|
|
} |
|
|
|
return nil, err |
|
|
|
|
|
|
|
} |
|
|
|
repo := &Repository{ |
|
|
|
} |
|
|
|
OwnerId: u.Id, |
|
|
|
|
|
|
|
Owner: u, |
|
|
|
sess := x.NewSession() |
|
|
|
Name: oldRepo.Name, |
|
|
|
defer sess.Close() |
|
|
|
LowerName: oldRepo.LowerName, |
|
|
|
if err = sess.Begin(); err != nil { |
|
|
|
Description: oldRepo.Description, |
|
|
|
return nil, err |
|
|
|
IsPrivate: oldRepo.IsPrivate, |
|
|
|
} |
|
|
|
IsFork: true, |
|
|
|
|
|
|
|
ForkId: oldRepo.Id, |
|
|
|
repo := &Repository{ |
|
|
|
} |
|
|
|
OwnerId: u.Id, |
|
|
|
|
|
|
|
Owner: u, |
|
|
|
if _, err = sess.Insert(repo); err != nil { |
|
|
|
Name: oldRepo.Name, |
|
|
|
sess.Rollback() |
|
|
|
LowerName: oldRepo.LowerName, |
|
|
|
return nil, err |
|
|
|
Description: oldRepo.Description, |
|
|
|
} |
|
|
|
IsPrivate: oldRepo.IsPrivate, |
|
|
|
|
|
|
|
IsFork: true, |
|
|
|
var t *Team // Owner team.
|
|
|
|
ForkId: oldRepo.Id, |
|
|
|
|
|
|
|
} |
|
|
|
mode := WRITABLE |
|
|
|
|
|
|
|
|
|
|
|
if _, err = sess.Insert(repo); err != nil { |
|
|
|
access := &Access{ |
|
|
|
sess.Rollback() |
|
|
|
UserName: u.LowerName, |
|
|
|
return nil, err |
|
|
|
RepoName: path.Join(u.LowerName, repo.LowerName), |
|
|
|
} |
|
|
|
Mode: mode, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// Give access to all members in owner team.
|
|
|
|
|
|
|
|
if u.IsOrganization() { |
|
|
|
|
|
|
|
t, err = u.GetOwnerTeam() |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
sess.Rollback() |
|
|
|
|
|
|
|
return nil, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if err = t.GetMembers(); err != nil { |
|
|
|
|
|
|
|
sess.Rollback() |
|
|
|
|
|
|
|
return nil, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
for _, u := range t.Members { |
|
|
|
|
|
|
|
access.Id = 0 |
|
|
|
|
|
|
|
access.UserName = u.LowerName |
|
|
|
|
|
|
|
if _, err = sess.Insert(access); err != nil { |
|
|
|
|
|
|
|
sess.Rollback() |
|
|
|
|
|
|
|
return nil, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
if _, err = sess.Insert(access); err != nil { |
|
|
|
|
|
|
|
sess.Rollback() |
|
|
|
|
|
|
|
return nil, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if _, err = sess.Exec( |
|
|
|
|
|
|
|
"UPDATE `user` SET num_repos = num_repos + 1 WHERE id = ?", u.Id); err != nil { |
|
|
|
|
|
|
|
sess.Rollback() |
|
|
|
|
|
|
|
return nil, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Update owner team info and count.
|
|
|
|
|
|
|
|
if u.IsOrganization() { |
|
|
|
|
|
|
|
t.RepoIds += "$" + com.ToStr(repo.Id) + "|" |
|
|
|
|
|
|
|
t.NumRepos++ |
|
|
|
|
|
|
|
if _, err = sess.Id(t.Id).AllCols().Update(t); err != nil { |
|
|
|
|
|
|
|
sess.Rollback() |
|
|
|
|
|
|
|
return nil, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if u.IsOrganization() { |
|
|
|
|
|
|
|
t, err := u.GetOwnerTeam() |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
log.Error(4, "GetOwnerTeam: %v", err) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
if err = t.GetMembers(); err != nil { |
|
|
|
|
|
|
|
log.Error(4, "GetMembers: %v", err) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
for _, u := range t.Members { |
|
|
|
|
|
|
|
if err = WatchRepo(u.Id, repo.Id, true); err != nil { |
|
|
|
|
|
|
|
log.Error(4, "WatchRepo2: %v", err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
if err = WatchRepo(u.Id, repo.Id, true); err != nil { |
|
|
|
|
|
|
|
log.Error(4, "WatchRepo3: %v", err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err = NewRepoAction(u, repo); err != nil { |
|
|
|
|
|
|
|
log.Error(4, "NewRepoAction: %v", err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if _, err = sess.Exec( |
|
|
|
|
|
|
|
"UPDATE `repository` SET num_forks = num_forks + 1 WHERE id = ?", oldRepo.Id); err != nil { |
|
|
|
|
|
|
|
sess.Rollback() |
|
|
|
|
|
|
|
return nil, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err = sess.Commit(); err != nil { |
|
|
|
|
|
|
|
return nil, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
repoPath := RepoPath(u.Name, repo.Name) |
|
|
|
|
|
|
|
_, stderr, err := process.ExecTimeout(10*time.Minute, |
|
|
|
|
|
|
|
fmt.Sprintf("ForkRepository: %s/%s", u.Name, repo.Name), |
|
|
|
|
|
|
|
"git", "clone", oldRepo.GetPath(), repoPath) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_, stderr, err = process.ExecDir(-1, |
|
|
|
|
|
|
|
repoPath, fmt.Sprintf("CreateRepository(git update-server-info): %s", repoPath), |
|
|
|
|
|
|
|
"git", "update-server-info") |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return nil, errors.New("CreateRepository(git update-server-info): " + stderr) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return repo, nil |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var t *Team // Owner team.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mode := WRITABLE |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
access := &Access{ |
|
|
|
|
|
|
|
UserName: u.LowerName, |
|
|
|
|
|
|
|
RepoName: path.Join(u.LowerName, repo.LowerName), |
|
|
|
|
|
|
|
Mode: mode, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// Give access to all members in owner team.
|
|
|
|
|
|
|
|
if u.IsOrganization() { |
|
|
|
|
|
|
|
t, err = u.GetOwnerTeam() |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
sess.Rollback() |
|
|
|
|
|
|
|
return nil, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if err = t.GetMembers(); err != nil { |
|
|
|
|
|
|
|
sess.Rollback() |
|
|
|
|
|
|
|
return nil, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
for _, u := range t.Members { |
|
|
|
|
|
|
|
access.Id = 0 |
|
|
|
|
|
|
|
access.UserName = u.LowerName |
|
|
|
|
|
|
|
if _, err = sess.Insert(access); err != nil { |
|
|
|
|
|
|
|
sess.Rollback() |
|
|
|
|
|
|
|
return nil, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
if _, err = sess.Insert(access); err != nil { |
|
|
|
|
|
|
|
sess.Rollback() |
|
|
|
|
|
|
|
return nil, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if _, err = sess.Exec( |
|
|
|
|
|
|
|
"UPDATE `user` SET num_repos = num_repos + 1 WHERE id = ?", u.Id); err != nil { |
|
|
|
|
|
|
|
sess.Rollback() |
|
|
|
|
|
|
|
return nil, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Update owner team info and count.
|
|
|
|
|
|
|
|
if u.IsOrganization() { |
|
|
|
|
|
|
|
t.RepoIds += "$" + com.ToStr(repo.Id) + "|" |
|
|
|
|
|
|
|
t.NumRepos++ |
|
|
|
|
|
|
|
if _, err = sess.Id(t.Id).AllCols().Update(t); err != nil { |
|
|
|
|
|
|
|
sess.Rollback() |
|
|
|
|
|
|
|
return nil, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if u.IsOrganization() { |
|
|
|
|
|
|
|
t, err := u.GetOwnerTeam() |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
log.Error(4, "GetOwnerTeam: %v", err) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
if err = t.GetMembers(); err != nil { |
|
|
|
|
|
|
|
log.Error(4, "GetMembers: %v", err) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
for _, u := range t.Members { |
|
|
|
|
|
|
|
if err = watchRepoWithEngine(sess, u.Id, repo.Id, true); err != nil { |
|
|
|
|
|
|
|
log.Error(4, "WatchRepo2: %v", err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
if err = watchRepoWithEngine(sess, u.Id, repo.Id, true); err != nil { |
|
|
|
|
|
|
|
log.Error(4, "WatchRepo3: %v", err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err = NewRepoAction(u, repo); err != nil { |
|
|
|
|
|
|
|
log.Error(4, "NewRepoAction: %v", err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if _, err = sess.Exec( |
|
|
|
|
|
|
|
"UPDATE `repository` SET num_forks = num_forks + 1 WHERE id = ?", oldRepo.Id); err != nil { |
|
|
|
|
|
|
|
sess.Rollback() |
|
|
|
|
|
|
|
return nil, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
oldRepoPath, err := oldRepo.RepoPath() |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
sess.Rollback() |
|
|
|
|
|
|
|
return nil, fmt.Errorf("fail to get repo path(%s): %v", oldRepo.Name, err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err = sess.Commit(); err != nil { |
|
|
|
|
|
|
|
return nil, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
repoPath := RepoPath(u.Name, repo.Name) |
|
|
|
|
|
|
|
_, stderr, err := process.ExecTimeout(10*time.Minute, |
|
|
|
|
|
|
|
fmt.Sprintf("ForkRepository(git clone): %s/%s", u.Name, repo.Name), |
|
|
|
|
|
|
|
"git", "clone", oldRepoPath, repoPath) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return nil, errors.New("ForkRepository(git clone): " + stderr) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_, stderr, err = process.ExecDir(-1, |
|
|
|
|
|
|
|
repoPath, fmt.Sprintf("ForkRepository(git update-server-info): %s", repoPath), |
|
|
|
|
|
|
|
"git", "update-server-info") |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return nil, errors.New("ForkRepository(git update-server-info): " + stderr) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return repo, nil |
|
|
|
} |
|
|
|
} |
|
|
|