aboutsummaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2015-10-25 04:26:26 -0400
committerUnknwon <u@gogs.io>2015-10-25 04:26:26 -0400
commit022820103d622dda74aa1c619ca46838a14b762a (patch)
tree2de093f709bb04c366cee4ebb73dcc3230f7019a /models
parentd5fab7f1b993ac389d751bfb87774549c4f3f4c2 (diff)
downloadgitea-022820103d622dda74aa1c619ca46838a14b762a.tar.gz
gitea-022820103d622dda74aa1c619ca46838a14b762a.zip
#1657 allow forcing all private repos
Diffstat (limited to 'models')
-rw-r--r--models/repo.go26
-rw-r--r--models/user.go2
2 files changed, 18 insertions, 10 deletions
diff --git a/models/repo.go b/models/repo.go
index 7d242df22f..9ea0abf2ae 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -480,13 +480,21 @@ func MirrorRepository(repoId int64, userName, repoName, repoPath, url string) er
return nil
}
+type MigrateRepoOptions struct {
+ Name string
+ Description string
+ IsPrivate bool
+ IsMirror bool
+ RemoteAddr string
+}
+
// 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{
- Name: name,
- Description: desc,
- IsPrivate: private,
- IsMirror: mirror,
+ Name: opts.Name,
+ Description: opts.Description,
+ IsPrivate: opts.IsPrivate,
+ IsMirror: opts.IsMirror,
})
if err != nil {
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()))
os.MkdirAll(tmpDir, os.ModePerm)
- repoPath := RepoPath(u.Name, name)
+ repoPath := RepoPath(u.Name, opts.Name)
if u.IsOrganization() {
t, err := u.GetOwnerTeam()
@@ -509,8 +517,8 @@ func MigrateRepository(u *User, name, desc string, private, mirror bool, url str
}
repo.IsBare = false
- if mirror {
- if err = MirrorRepository(repo.ID, u.Name, repo.Name, repoPath, url); err != nil {
+ if opts.IsMirror {
+ if err = MirrorRepository(repo.ID, u.Name, repo.Name, repoPath, opts.RemoteAddr); err != nil {
return repo, err
}
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
_, stderr, err := process.ExecTimeout(10*time.Minute,
fmt.Sprintf("MigrateRepository: %s", repoPath),
- "git", "clone", "--mirror", "--bare", "--quiet", url, repoPath)
+ "git", "clone", "--mirror", "--bare", "--quiet", opts.RemoteAddr, repoPath)
if err != nil {
return repo, fmt.Errorf("git clone --mirror --bare --quiet: %v", stderr)
} else if err = createUpdateHook(repoPath); err != nil {
diff --git a/models/user.go b/models/user.go
index 152ae42842..4109f4d95c 100644
--- a/models/user.go
+++ b/models/user.go
@@ -71,7 +71,7 @@ type User struct {
Created time.Time `xorm:"CREATED"`
Updated time.Time `xorm:"UPDATED"`
- // Remember visibility choice for convenience.
+ // Remember visibility choice for convenience, true for private
LastRepoVisibility bool
// Permissions.