|
|
@ -480,13 +480,21 @@ func MirrorRepository(repoId int64, userName, repoName, repoPath, url string) er |
|
|
|
return nil |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type MigrateRepoOptions struct { |
|
|
|
|
|
|
|
Name string |
|
|
|
|
|
|
|
Description string |
|
|
|
|
|
|
|
IsPrivate bool |
|
|
|
|
|
|
|
IsMirror bool |
|
|
|
|
|
|
|
RemoteAddr string |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// MigrateRepository migrates a existing repository from other project hosting.
|
|
|
|
// MigrateRepository migrates a existing repository from other project hosting.
|
|
|
|
func MigrateRepository(u *User, name, desc string, private, mirror bool, url string) (*Repository, error) { |
|
|
|
func MigrateRepository(u *User, opts MigrateRepoOptions) (*Repository, error) { |
|
|
|
repo, err := CreateRepository(u, CreateRepoOptions{ |
|
|
|
repo, err := CreateRepository(u, CreateRepoOptions{ |
|
|
|
Name: name, |
|
|
|
Name: opts.Name, |
|
|
|
Description: desc, |
|
|
|
Description: opts.Description, |
|
|
|
IsPrivate: private, |
|
|
|
IsPrivate: opts.IsPrivate, |
|
|
|
IsMirror: mirror, |
|
|
|
IsMirror: opts.IsMirror, |
|
|
|
}) |
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
return nil, err |
|
|
@ -496,7 +504,7 @@ func MigrateRepository(u *User, name, desc string, private, mirror bool, url str |
|
|
|
tmpDir := filepath.Join(os.TempDir(), fmt.Sprintf("%d", time.Now().Nanosecond())) |
|
|
|
tmpDir := filepath.Join(os.TempDir(), fmt.Sprintf("%d", time.Now().Nanosecond())) |
|
|
|
os.MkdirAll(tmpDir, os.ModePerm) |
|
|
|
os.MkdirAll(tmpDir, os.ModePerm) |
|
|
|
|
|
|
|
|
|
|
|
repoPath := RepoPath(u.Name, name) |
|
|
|
repoPath := RepoPath(u.Name, opts.Name) |
|
|
|
|
|
|
|
|
|
|
|
if u.IsOrganization() { |
|
|
|
if u.IsOrganization() { |
|
|
|
t, err := u.GetOwnerTeam() |
|
|
|
t, err := u.GetOwnerTeam() |
|
|
@ -509,8 +517,8 @@ func MigrateRepository(u *User, name, desc string, private, mirror bool, url str |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
repo.IsBare = false |
|
|
|
repo.IsBare = false |
|
|
|
if mirror { |
|
|
|
if opts.IsMirror { |
|
|
|
if err = MirrorRepository(repo.ID, u.Name, repo.Name, repoPath, url); err != nil { |
|
|
|
if err = MirrorRepository(repo.ID, u.Name, repo.Name, repoPath, opts.RemoteAddr); err != nil { |
|
|
|
return repo, err |
|
|
|
return repo, err |
|
|
|
} |
|
|
|
} |
|
|
|
repo.IsMirror = true |
|
|
|
repo.IsMirror = true |
|
|
@ -522,7 +530,7 @@ func MigrateRepository(u *User, name, desc string, private, mirror bool, url str |
|
|
|
// FIXME: this command could for both migrate and mirror
|
|
|
|
// FIXME: this command could for both migrate and mirror
|
|
|
|
_, stderr, err := process.ExecTimeout(10*time.Minute, |
|
|
|
_, stderr, err := process.ExecTimeout(10*time.Minute, |
|
|
|
fmt.Sprintf("MigrateRepository: %s", repoPath), |
|
|
|
fmt.Sprintf("MigrateRepository: %s", repoPath), |
|
|
|
"git", "clone", "--mirror", "--bare", "--quiet", url, repoPath) |
|
|
|
"git", "clone", "--mirror", "--bare", "--quiet", opts.RemoteAddr, repoPath) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return repo, fmt.Errorf("git clone --mirror --bare --quiet: %v", stderr) |
|
|
|
return repo, fmt.Errorf("git clone --mirror --bare --quiet: %v", stderr) |
|
|
|
} else if err = createUpdateHook(repoPath); err != nil { |
|
|
|
} else if err = createUpdateHook(repoPath); err != nil { |
|
|
|