func (c Git) Index() revel.Result { parent_path := libs.GetGitParentPath() repos, _ := filepath.Glob(parent_path + "/*") pager := &libs.Pager{ Params: c.Params, Limit: 15, Left: 5, Right: 5, Items: repos, Total: len(repos), } page := pager.Result() gitinfos := models.GetGitinfoList(page.Items) return c.Render(gitinfos, page) }
func (c Git) Create(Name string) revel.Result { repo := libs.GetGitParentPath() + "/" + Name + ".git" c.Validation.Required(Name).Message("リポジトリ名は必須です。") c.Validation.Required(Name != "webgitadmin").Message(Name + "は予約語のた指定できません。") c.Validation.Required(Name != "git").Message(Name + "は予約語のた指定できません。") c.Validation.Required(c.IsExists(repo)).Message(Name + "はすでに存在しています。") c.Validation.Match(Name, regexp.MustCompile("^[a-z0-9_-]+$")).Message("リポジトリ名は半角英数記号で指定してください。") if c.Validation.HasErrors() { c.Validation.Keep() c.FlashParams() return c.Redirect(routes.Git.Index()) } err := exec.Command("sudo", libs.GetGitBin(), "init", "--bare", "--shared=true", repo).Run() if err != nil { c.FlashParams() revel.INFO.Println(err) c.Flash.Error(fmt.Sprintf("%sの作成に失敗しました。", Name)) return c.Redirect(routes.Git.Index()) } err = os.Chdir(repo) if err != nil { revel.INFO.Println(err) } err = exec.Command("sudo", libs.GetGitBin(), "update-server-info").Run() if err != nil { revel.INFO.Println(err) } err = exec.Command("sudo", "cp", "hooks/post-update.sample", "hooks/post-update").Run() if err != nil { revel.INFO.Println(err) } err = exec.Command("sudo", "chmod", "755", "hooks/post-update").Run() if err != nil { revel.INFO.Println(err) } err = exec.Command("sudo", libs.GetGitBin(), "config", "http.receivepack", "true").Run() if err != nil { revel.INFO.Println(err) } err = exec.Command("sudo", "chown", "-R", fmt.Sprintf("%s.%s", libs.GetGitOwner(), libs.GetGitOwner()), repo).Run() if err != nil { revel.INFO.Println(err) } err = exec.Command("sudo", "chmod", "-R", libs.GetGitPermission(), repo).Run() if err != nil { revel.INFO.Println(err) } revel.INFO.Println(Name) c.Flash.Success(fmt.Sprintf("%sを作成しました。", Name)) return c.Redirect(routes.Git.Index()) }