From e04c97b9fa3a9955e967a918aada9b21a78a0ec6 Mon Sep 17 00:00:00 2001
From: Arthur Ouyang <arthur.oy+github@gmail.com>
Date: Thu, 19 Nov 2015 07:31:55 +0800
Subject: [PATCH 1/3] Fix #1965 - the hyperlink and the display name of the
 branch

The hyperlink and the display name of the branch if the branch is in a folder or the branch name has '#'
---
 conf/locale/locale_en-US.ini        | 2 +-
 modules/git/utils.go                | 4 ++++
 templates/user/dashboard/feeds.tmpl | 3 ++-
 3 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/conf/locale/locale_en-US.ini b/conf/locale/locale_en-US.ini
index 30540d4791..23543a867a 100644
--- a/conf/locale/locale_en-US.ini
+++ b/conf/locale/locale_en-US.ini
@@ -966,7 +966,7 @@ notices.delete_success = System notice has been deleted successfully.
 [action]
 create_repo = created repository <a href="%s">%s</a>
 rename_repo = renamed repository from <code>%[1]s</code> to <a href="%[2]s">%[3]s</a>
-commit_repo = pushed to <a href="%s/src/%s">%[2]s</a> at <a href="%[1]s">%[3]s</a>
+commit_repo = pushed to <a href="%[1]s/src/%[2]s">%[3]s</a> at <a href="%[1]s">%[4]s</a>
 create_issue = `opened issue <a href="%s/issues/%s">%s#%[2]s</a>`
 create_pull_request = `created pull request <a href="%s/pulls/%s">%s#%[2]s</a>`
 comment_issue = `commented on issue <a href="%s/issues/%s">%s#%[2]s</a>`
diff --git a/modules/git/utils.go b/modules/git/utils.go
index 78792aaf5e..43a4da3d10 100644
--- a/modules/git/utils.go
+++ b/modules/git/utils.go
@@ -35,6 +35,10 @@ func parsePrettyFormatLog(repo *Repository, logByts []byte) (*list.List, error)
 }
 
 func RefEndName(refStr string) string {
+	if strings.HasPrefix(refStr, "refs/heads/") {
+		return strings.TrimPrefix(refStr, "refs/heads/")
+	}
+
 	index := strings.LastIndex(refStr, "/")
 	if index != -1 {
 		return refStr[index+1:]
diff --git a/templates/user/dashboard/feeds.tmpl b/templates/user/dashboard/feeds.tmpl
index 70142f9a51..fff1e16f60 100644
--- a/templates/user/dashboard/feeds.tmpl
+++ b/templates/user/dashboard/feeds.tmpl
@@ -13,7 +13,8 @@
           {{else if eq .GetOpType 2}}
           {{$.i18n.Tr "action.rename_repo" .GetContent .GetRepoLink .GetRepoPath | Str2html}}
           {{else if eq .GetOpType 5}}
-          {{$.i18n.Tr "action.commit_repo" .GetRepoLink .GetBranch .GetRepoPath | Str2html}}
+          {{ $branchLink := .GetBranch | EscapePound}}
+          {{$.i18n.Tr "action.commit_repo" .GetRepoLink $branchLink .GetBranch .GetRepoPath | Str2html}}
           {{else if eq .GetOpType 6}}
           {{ $index := index .GetIssueInfos 0}}
           {{$.i18n.Tr "action.create_issue" .GetRepoLink $index .GetRepoPath | Str2html}}

From 0bd4d15e4722e77a858a2683c0583ac2f53c633b Mon Sep 17 00:00:00 2001
From: Arthur Ouyang <arthur.oy+github@gmail.com>
Date: Thu, 19 Nov 2015 08:05:27 +0800
Subject: [PATCH 2/3] Use refStr[11:] instead of TrimPrefix

Fix #1965
---
 modules/git/utils.go | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/modules/git/utils.go b/modules/git/utils.go
index 43a4da3d10..73d32d3541 100644
--- a/modules/git/utils.go
+++ b/modules/git/utils.go
@@ -36,7 +36,8 @@ func parsePrettyFormatLog(repo *Repository, logByts []byte) (*list.List, error)
 
 func RefEndName(refStr string) string {
 	if strings.HasPrefix(refStr, "refs/heads/") {
-		return strings.TrimPrefix(refStr, "refs/heads/")
+		// trim the "refs/heads/"
+		return return refStr[11:]
 	}
 
 	index := strings.LastIndex(refStr, "/")

From fc56f42dc35a60395ca8def114a23a6c7655c410 Mon Sep 17 00:00:00 2001
From: Arthur Ouyang <arthur.oy+github@gmail.com>
Date: Thu, 19 Nov 2015 08:10:44 +0800
Subject: [PATCH 3/3] Use refStr[len("refs/heads/"):] instead of refStr[11:]
 and fix error

Fix #1965
---
 modules/git/utils.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/modules/git/utils.go b/modules/git/utils.go
index 73d32d3541..d2d0c19ed9 100644
--- a/modules/git/utils.go
+++ b/modules/git/utils.go
@@ -37,7 +37,7 @@ func parsePrettyFormatLog(repo *Repository, logByts []byte) (*list.List, error)
 func RefEndName(refStr string) string {
 	if strings.HasPrefix(refStr, "refs/heads/") {
 		// trim the "refs/heads/"
-		return return refStr[11:]
+		return refStr[len("refs/heads/"):]
 	}
 
 	index := strings.LastIndex(refStr, "/")