diff --git a/models/release.go b/models/release.go index 314b7a91a99..e5e81b9b679 100644 --- a/models/release.go +++ b/models/release.go @@ -9,7 +9,7 @@ import ( "strings" "time" - "github.com/Unknwon/com" + // "github.com/Unknwon/com" "github.com/gogits/git" ) @@ -26,7 +26,8 @@ type Release struct { Title string TagName string LowerTagName string - SHA1 string + Target string + Sha1 string `xorm:"VARCHAR(40)"` NumCommits int NumCommitsBehind int `xorm:"-"` Note string `xorm:"TEXT"` @@ -59,9 +60,13 @@ func CreateRelease(gitRepo *git.Repository, rel *Release) error { } if !gitRepo.IsTagExist(rel.TagName) { - _, stderr, err := com.ExecCmdDir(gitRepo.Path, "git", "tag", rel.TagName, "-m", rel.Title) + commit, err := gitRepo.GetCommitOfBranch(rel.Target) if err != nil { - return errors.New(stderr) + return err + } + + if err = gitRepo.CreateTag(rel.TagName, commit.Id.String()); err != nil { + return err } } else { commit, err := gitRepo.GetCommitOfTag(rel.TagName) diff --git a/modules/auth/repo.go b/modules/auth/repo.go index 82cd0786138..26ab7551cac 100644 --- a/modules/auth/repo.go +++ b/modules/auth/repo.go @@ -205,6 +205,7 @@ func (f *CreateLabelForm) Validate(errors *binding.Errors, req *http.Request, co type NewReleaseForm struct { TagName string `form:"tag_name" binding:"Required"` + Target string `form:"tag_target" binding:"Required"` Title string `form:"title" binding:"Required"` Content string `form:"content" binding:"Required"` Prerelease bool `form:"prerelease"` @@ -213,6 +214,7 @@ type NewReleaseForm struct { func (f *NewReleaseForm) Name(field string) string { names := map[string]string{ "TagName": "Tag name", + "Target": "Target", "Title": "Release title", "Content": "Release content", } diff --git a/routers/repo/release.go b/routers/repo/release.go index 14a14656d4c..3e2449ecf3b 100644 --- a/routers/repo/release.go +++ b/routers/repo/release.go @@ -79,7 +79,7 @@ func Releases(ctx *middleware.Context) { tags.rels[i] = &models.Release{ Title: rawTag, TagName: rawTag, - SHA1: commit.Id.String(), + Sha1: commit.Id.String(), } tags.rels[i].NumCommits, err = ctx.Repo.GitRepo.CommitsCount(commit.Id.String()) if err != nil { @@ -129,12 +129,18 @@ func ReleasesNewPost(ctx *middleware.Context, form auth.NewReleaseForm) { return } + if !ctx.Repo.GitRepo.IsBranchExist(form.Target) { + ctx.RenderWithErr("Target branch does not exist", "release/new", &form) + return + } + rel := &models.Release{ RepoId: ctx.Repo.Repository.Id, PublisherId: ctx.User.Id, Title: form.Title, TagName: form.TagName, - SHA1: ctx.Repo.Commit.Id.String(), + Target: form.Target, + Sha1: ctx.Repo.Commit.Id.String(), NumCommits: commitsCount, Note: form.Content, IsPrerelease: form.Prerelease, diff --git a/templates/release/list.tmpl b/templates/release/list.tmpl index edbc7467b45..2607dfacd95 100644 --- a/templates/release/list.tmpl +++ b/templates/release/list.tmpl @@ -11,12 +11,12 @@