From 85c9f7c5f354838fc8a78977a80f9899b5158897 Mon Sep 17 00:00:00 2001
From: Unknwon <joe2010xtmf@163.com>
Date: Fri, 10 Oct 2014 05:06:12 -0400
Subject: [PATCH] Issue: Show error prompt when add repository to team and it
 does not exist #533

---
 conf/locale/locale_en-US.ini | 1 +
 conf/locale/locale_zh-CN.ini | 1 +
 routers/org/teams.go         | 5 +++++
 3 files changed, 7 insertions(+)

diff --git a/conf/locale/locale_en-US.ini b/conf/locale/locale_en-US.ini
index 15262e630f..0f2003b592 100644
--- a/conf/locale/locale_en-US.ini
+++ b/conf/locale/locale_en-US.ini
@@ -408,6 +408,7 @@ teams.admin_permission_desc = This team grants <strong>Admin</strong> access: me
 teams.repositories = Team Repositories
 teams.add_team_repository = Add Team Repository
 teams.remove_repo = Remove
+teams.add_nonexistent_repo = The repository you're trying to add does not exist, please create it first.
 
 [admin]
 dashboard = Dashboard
diff --git a/conf/locale/locale_zh-CN.ini b/conf/locale/locale_zh-CN.ini
index 8a343d4c8c..da26ce9df7 100644
--- a/conf/locale/locale_zh-CN.ini
+++ b/conf/locale/locale_zh-CN.ini
@@ -408,6 +408,7 @@ teams.admin_permission_desc = 该团队拥有一定的 <strong>管理</strong> 
 teams.repositories = 团队仓库
 teams.add_team_repository = 添加团队仓库
 teams.remove_repo = 移除仓库
+teams.add_nonexistent_repo = 您尝试添加到团队的仓库不存在,请先创建仓库!
 
 [admin]
 dashboard = 控制面板
diff --git a/routers/org/teams.go b/routers/org/teams.go
index 9aa8e50214..77a7b6e13c 100644
--- a/routers/org/teams.go
+++ b/routers/org/teams.go
@@ -124,6 +124,11 @@ func TeamsRepoAction(ctx *middleware.Context) {
 		var repo *models.Repository
 		repo, err = models.GetRepositoryByName(ctx.Org.Organization.Id, repoName)
 		if err != nil {
+			if err == models.ErrRepoNotExist {
+				ctx.Flash.Error(ctx.Tr("org.teams.add_nonexistent_repo"))
+				ctx.Redirect(ctx.Org.OrgLink + "/teams/" + ctx.Org.Team.LowerName + "/repositories")
+				return
+			}
 			ctx.Handle(500, "GetRepositoryByName", err)
 			return
 		}