summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md6
-rw-r--r--models/repo.go26
-rw-r--r--modules/middleware/context.go1
-rw-r--r--modules/middleware/repo.go10
-rw-r--r--routers/repo/repo.go14
-rw-r--r--templates/repo/setting.tmpl9
6 files changed, 60 insertions, 6 deletions
diff --git a/README.md b/README.md
index fa48027db3..c71d78e951 100644
--- a/README.md
+++ b/README.md
@@ -7,7 +7,11 @@ Gogs(Go Git Service) is a Self Hosted Git Service in the Go Programming Language
##### Current version: 0.2.8 Alpha
-#### Due to testing purpose, data of [try.gogits.org](http://try.gogits.org) has been reset in April 6, 2014 and will reset multiple times after. Please do NOT put your important data on the site.
+### NOTICES
+
+- Due to testing purpose, data of [try.gogits.org](http://try.gogits.org) has been reset in April 6, 2014 and will reset multiple times after. Please do NOT put your important data on the site.
+- Demo site [try.gogits.org](http://try.gogits.org) is running under `dev` branch.
+- Checkout the `dev` branch code of Gogs should checkout `dev` branch code of `gogits/git` as well.
#### Other language version
diff --git a/models/repo.go b/models/repo.go
index ae8fe5efd1..01b8fdb126 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -30,7 +30,8 @@ var (
ErrRepoNotExist = errors.New("Repository does not exist")
ErrRepoFileNotExist = errors.New("Target Repo file does not exist")
ErrRepoNameIllegal = errors.New("Repository name contains illegal characters")
- ErrRepoFileNotLoaded = fmt.Errorf("repo file not loaded")
+ ErrRepoFileNotLoaded = errors.New("repo file not loaded")
+ ErrMirrorNotExist = errors.New("Mirror does not exist")
)
var (
@@ -130,6 +131,22 @@ type Mirror struct {
NextUpdate time.Time
}
+func GetMirror(repoId int64) (*Mirror, error) {
+ m := &Mirror{RepoId: repoId}
+ has, err := orm.Get(m)
+ if err != nil {
+ return nil, err
+ } else if !has {
+ return nil, ErrMirrorNotExist
+ }
+ return m, nil
+}
+
+func UpdateMirror(m *Mirror) error {
+ _, err := orm.Id(m.Id).Update(m)
+ return err
+}
+
// MirrorUpdate checks and updates mirror repositories.
func MirrorUpdate() {
if err := orm.Iterate(new(Mirror), func(idx int, bean interface{}) error {
@@ -149,8 +166,7 @@ func MirrorUpdate() {
}
m.NextUpdate = time.Now().Add(time.Duration(m.Interval) * time.Hour)
- _, err = orm.Id(m.Id).Update(m)
- return err
+ return UpdateMirror(m)
}); err != nil {
log.Error("repo.MirrorUpdate: %v", err)
}
@@ -647,6 +663,10 @@ func DeleteRepository(userId, repoId int64, userName string) (err error) {
sess.Rollback()
return err
}
+ if _, err = sess.Delete(&Mirror{RepoId: repoId}); err != nil {
+ sess.Rollback()
+ return err
+ }
rawSql := "UPDATE `user` SET num_repos = num_repos - 1 WHERE id = ?"
if _, err = sess.Exec(rawSql, userId); err != nil {
diff --git a/modules/middleware/context.go b/modules/middleware/context.go
index edbf1f3ce8..f353ea51bd 100644
--- a/modules/middleware/context.go
+++ b/modules/middleware/context.go
@@ -62,6 +62,7 @@ type Context struct {
HTTPS string
Git string
}
+ *models.Mirror
}
}
diff --git a/modules/middleware/repo.go b/modules/middleware/repo.go
index f0a46b6dad..c8e1aaee72 100644
--- a/modules/middleware/repo.go
+++ b/modules/middleware/repo.go
@@ -102,9 +102,17 @@ func RepoAssignment(redirect bool, args ...bool) martini.Handler {
ctx.Repo.HasAccess = true
ctx.Data["HasAccess"] = true
+ if repo.IsMirror {
+ ctx.Repo.Mirror, err = models.GetMirror(repo.Id)
+ if err != nil {
+ ctx.Handle(500, "RepoAssignment(GetMirror)", err)
+ return
+ }
+ ctx.Data["MirrorInterval"] = ctx.Repo.Mirror.Interval
+ }
+
repo.NumOpenIssues = repo.NumIssues - repo.NumClosedIssues
ctx.Repo.Repository = repo
-
ctx.Data["IsBareRepo"] = ctx.Repo.Repository.IsBare
gitRepo, err := git.OpenRepository(models.RepoPath(userName, repoName))
diff --git a/routers/repo/repo.go b/routers/repo/repo.go
index 3b20731c62..dda26899d0 100644
--- a/routers/repo/repo.go
+++ b/routers/repo/repo.go
@@ -336,6 +336,8 @@ func SettingPost(ctx *middleware.Context) {
return
}
+ ctx.Data["IsRepoToolbarSetting"] = true
+
switch ctx.Query("action") {
case "update":
newRepoName := ctx.Query("name")
@@ -371,6 +373,18 @@ func SettingPost(ctx *middleware.Context) {
}
log.Trace("%s Repository updated: %s/%s", ctx.Req.RequestURI, ctx.Repo.Owner.Name, ctx.Repo.Repository.Name)
+ if ctx.Repo.Repository.IsMirror {
+ if len(ctx.Query("interval")) > 0 {
+ var err error
+ ctx.Repo.Mirror.Interval, err = base.StrTo(ctx.Query("interval")).Int()
+ if err != nil {
+ log.Error("repo.SettingPost(get mirror interval): %v", err)
+ } else if err = models.UpdateMirror(ctx.Repo.Mirror); err != nil {
+ log.Error("repo.SettingPost(UpdateMirror): %v", err)
+ }
+ }
+ }
+
ctx.Flash.Success("Repository options has been successfully updated.")
ctx.Redirect(fmt.Sprintf("/%s/%s/settings", ctx.Repo.Owner.Name, ctx.Repo.Repository.Name))
case "transfer":
diff --git a/templates/repo/setting.tmpl b/templates/repo/setting.tmpl
index ff3b73b59a..5572671c93 100644
--- a/templates/repo/setting.tmpl
+++ b/templates/repo/setting.tmpl
@@ -46,7 +46,7 @@
<hr>
<div class="form-group">
<label class="col-md-3 text-right">Default Branch</label>
- <div class="col-md-9">
+ <div class="col-md-3">
<select name="branch" id="repo-default-branch" class="form-control">
<option value="{{.Repository.DefaultBranch}}">{{.Repository.DefaultBranch}}</option>
{{range .Branches}}
@@ -56,6 +56,13 @@
</div>
</div>
+ {{if .Repository.IsMirror}}<div class="form-group">
+ <label class="col-md-3 text-right">Mirror Interval(hours)</label>
+ <div class="col-md-3">
+ <input class="form-control" name="interval" value="{{.MirrorInterval}}"/>
+ </div>
+ </div>{{end}}
+
<div class="form-group">
<div class="col-md-offset-3 col-md-9">
<div class="checkbox">