gitea源码

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. {{template "base/head" .}}
  2. <div role="main" aria-label="{{.Title}}" class="page-content ui repository branches">
  3. {{template "repo/header" .}}
  4. <div class="ui container">
  5. {{template "base/alert" .}}
  6. {{template "repo/sub_menu" .}}
  7. {{if .DefaultBranchBranch}}
  8. <h4 class="ui top attached header">
  9. {{ctx.Locale.Tr "repo.default_branch"}}
  10. {{if and $.IsWriter (not $.Repository.IsArchived) (not .IsDeleted)}}
  11. <a role="button" class="right" href="{{.RepoLink}}/settings/branches" data-tooltip-content="{{ctx.Locale.Tr "repo.settings.branches.switch_default_branch"}}">
  12. {{svg "octicon-arrow-switch"}}
  13. </a>
  14. {{end}}
  15. </h4>
  16. <div class="ui attached table segment">
  17. <table class="ui very basic striped fixed table single line">
  18. <tbody>
  19. <tr>
  20. <td>
  21. <div class="flex-text-block">
  22. <a class="gt-ellipsis branch-name" href="{{.RepoLink}}/src/branch/{{PathEscapeSegments .DefaultBranchBranch.DBBranch.Name}}">{{.DefaultBranchBranch.DBBranch.Name}}</a>
  23. {{if .DefaultBranchBranch.IsProtected}}
  24. <span data-tooltip-content="{{ctx.Locale.Tr "repo.settings.protected_branch"}}">{{svg "octicon-shield-lock"}}</span>
  25. {{end}}
  26. <button class="btn interact-fg tw-px-1" data-clipboard-text="{{.DefaultBranchBranch.DBBranch.Name}}" data-tooltip-content="{{ctx.Locale.Tr "copy_branch"}}">{{svg "octicon-copy" 14}}</button>
  27. {{template "repo/commit_statuses" dict "Status" (index $.CommitStatus .DefaultBranchBranch.DBBranch.CommitID) "Statuses" (index $.CommitStatuses .DefaultBranchBranch.DBBranch.CommitID)}}
  28. </div>
  29. <p class="info tw-flex tw-items-center tw-my-1">{{svg "octicon-git-commit" 16 "tw-mr-1"}}<a href="{{.RepoLink}}/commit/{{PathEscape .DefaultBranchBranch.DBBranch.CommitID}}">{{ShortSha .DefaultBranchBranch.DBBranch.CommitID}}</a> · <span class="commit-message">{{ctx.RenderUtils.RenderCommitMessage .DefaultBranchBranch.DBBranch.CommitMessage .Repository}}</span> · {{ctx.Locale.Tr "org.repo_updated"}} {{DateUtils.TimeSince .DefaultBranchBranch.DBBranch.CommitTime}}{{if .DefaultBranchBranch.DBBranch.Pusher}} &nbsp;{{template "shared/user/avatarlink" dict "user" .DefaultBranchBranch.DBBranch.Pusher}}{{template "shared/user/namelink" .DefaultBranchBranch.DBBranch.Pusher}}{{end}}</p>
  30. </td>
  31. {{/* FIXME: here and below, the tw-overflow-visible is not quite right but it is still needed the moment: to show the important buttons when the width is narrow */}}
  32. <td class="tw-text-right tw-overflow-visible">
  33. {{if and $.IsWriter (not $.Repository.IsArchived) (not .IsDeleted)}}
  34. <button class="btn interact-bg show-create-branch-modal tw-p-2"
  35. data-modal="#create-branch-modal"
  36. data-branch-from="{{$.DefaultBranchBranch.DBBranch.Name}}"
  37. data-branch-from-urlcomponent="{{PathEscapeSegments $.DefaultBranchBranch.DBBranch.Name}}"
  38. data-tooltip-content="{{ctx.Locale.Tr "repo.branch.new_branch_from" ($.DefaultBranchBranch.DBBranch.Name)}}"
  39. >
  40. {{svg "octicon-git-branch"}}
  41. </button>
  42. {{end}}
  43. {{if .EnableFeed}}
  44. <a role="button" class="btn interact-bg tw-p-2" href="{{$.RepoLink}}/rss/branch/{{PathEscapeSegments .DefaultBranchBranch.DBBranch.Name}}" data-tooltip-content="{{ctx.Locale.Tr "rss_feed"}}">{{svg "octicon-rss"}}</a>
  45. {{end}}
  46. {{if not $.DisableDownloadSourceArchives}}
  47. <div class="ui dropdown btn interact-bg tw-p-2" data-tooltip-content="{{ctx.Locale.Tr "repo.branch.download" ($.DefaultBranchBranch.DBBranch.Name)}}">
  48. {{svg "octicon-download"}}
  49. <div class="menu">
  50. <a class="item archive-link" href="{{$.RepoLink}}/archive/{{PathEscapeSegments $.DefaultBranchBranch.DBBranch.Name}}.zip" rel="nofollow">{{svg "octicon-file-zip"}}&nbsp;ZIP</a>
  51. <a class="item archive-link" href="{{$.RepoLink}}/archive/{{PathEscapeSegments $.DefaultBranchBranch.DBBranch.Name}}.tar.gz" rel="nofollow">{{svg "octicon-file-zip"}}&nbsp;TAR.GZ</a>
  52. </div>
  53. </div>
  54. {{end}}
  55. {{if and $.IsWriter (not $.Repository.IsArchived) (not .IsDeleted) (not $.IsMirror)}}
  56. <button class="btn interact-bg tw-p-2 show-modal show-rename-branch-modal"
  57. data-is-default-branch="true"
  58. data-modal="#rename-branch-modal"
  59. data-old-branch-name="{{$.DefaultBranchBranch.DBBranch.Name}}"
  60. data-tooltip-content="{{ctx.Locale.Tr "repo.branch.rename" ($.DefaultBranchBranch.DBBranch.Name)}}"
  61. >
  62. {{svg "octicon-pencil"}}
  63. </button>
  64. {{end}}
  65. </td>
  66. </tr>
  67. </tbody>
  68. </table>
  69. </div>
  70. {{end}}
  71. <h4 class="ui top attached header tw-flex tw-items-center tw-justify-between">
  72. <div class="tw-flex tw-items-center">
  73. {{ctx.Locale.Tr "repo.branches"}}
  74. </div>
  75. </h4>
  76. <div class="ui attached segment">
  77. <form class="ignore-dirty" method="get">
  78. {{template "shared/search/combo" dict "Value" .Keyword "Placeholder" (ctx.Locale.Tr "search.branch_kind")}}
  79. </form>
  80. </div>
  81. <div class="ui attached table segment">
  82. <table class="ui very basic striped fixed table single line">
  83. <tbody>
  84. {{range .Branches}}
  85. <tr>
  86. <td class="eight wide">
  87. {{if .DBBranch.IsDeleted}}
  88. <div class="flex-text-block">
  89. <span class="gt-ellipsis branch-name">{{.DBBranch.Name}}</span>
  90. <button class="btn interact-fg tw-px-1" data-clipboard-text="{{.DBBranch.Name}}" data-tooltip-content="{{ctx.Locale.Tr "copy_branch"}}">{{svg "octicon-copy" 14}}</button>
  91. </div>
  92. <p class="info">{{ctx.Locale.Tr "repo.branch.deleted_by" .DBBranch.DeletedBy.Name}} {{DateUtils.TimeSince .DBBranch.DeletedUnix}}</p>
  93. {{else}}
  94. <div class="flex-text-block">
  95. <a class="gt-ellipsis branch-name" href="{{$.RepoLink}}/src/branch/{{PathEscapeSegments .DBBranch.Name}}">{{.DBBranch.Name}}</a>
  96. {{if .IsProtected}}
  97. <span data-tooltip-content="{{ctx.Locale.Tr "repo.settings.protected_branch"}}">{{svg "octicon-shield-lock"}}</span>
  98. {{end}}
  99. <button class="btn interact-fg tw-px-1" data-clipboard-text="{{.DBBranch.Name}}" data-tooltip-content="{{ctx.Locale.Tr "copy_branch"}}">{{svg "octicon-copy" 14}}</button>
  100. {{template "repo/commit_statuses" dict "Status" (index $.CommitStatus .DBBranch.CommitID) "Statuses" (index $.CommitStatuses .DBBranch.CommitID)}}
  101. </div>
  102. <p class="info tw-flex tw-items-center tw-my-1">{{svg "octicon-git-commit" 16 "tw-mr-1"}}<a href="{{$.RepoLink}}/commit/{{PathEscape .DBBranch.CommitID}}">{{ShortSha .DBBranch.CommitID}}</a> · <span class="commit-message">{{ctx.RenderUtils.RenderCommitMessage .DBBranch.CommitMessage $.Repository}}</span> · {{ctx.Locale.Tr "org.repo_updated"}} {{DateUtils.TimeSince .DBBranch.CommitTime}}{{if .DBBranch.Pusher}} &nbsp;{{template "shared/user/avatarlink" dict "user" .DBBranch.Pusher}} &nbsp;{{template "shared/user/namelink" .DBBranch.Pusher}}{{end}}</p>
  103. {{end}}
  104. </td>
  105. <td class="two wide ui">
  106. {{if and (not .DBBranch.IsDeleted) $.DefaultBranchBranch}}
  107. {{$tooltipDivergence := ""}}
  108. {{if or .CommitsBehind .CommitsAhead}}
  109. {{$tooltipDivergence = ctx.Locale.Tr "repo.branch.commits_divergence_from" .CommitsBehind .CommitsAhead $.DefaultBranchBranch.DBBranch.Name}}
  110. {{else}}
  111. {{$tooltipDivergence = ctx.Locale.Tr "repo.branch.commits_no_divergence" $.DefaultBranchBranch.DBBranch.Name}}
  112. {{end}}
  113. <div class="commit-divergence" data-tooltip-content="{{$tooltipDivergence}}">
  114. <div class="bar-group">
  115. <div class="count count-behind">{{.CommitsBehind}}</div>
  116. {{/* old code bears 0/0.0 = NaN output, so it might output invalid "width: NaNpx", it just works and doesn't cause any problem. */}}
  117. <div class="bar bar-behind" style="width: {{Eval 100 "*" .CommitsBehind "/" "(" .CommitsBehind "+" .CommitsAhead "+" 0.0 ")"}}%"></div>
  118. </div>
  119. <div class="bar-group">
  120. <div class="count count-ahead">{{.CommitsAhead}}</div>
  121. <div class="bar bar-ahead" style="width: {{Eval 100 "*" .CommitsAhead "/" "(" .CommitsBehind "+" .CommitsAhead "+" 0.0 ")"}}%"></div>
  122. </div>
  123. </div>
  124. {{end}}
  125. </td>
  126. <td class="two wide tw-text-right">
  127. {{if not .LatestPullRequest}}
  128. {{if .IsIncluded}}
  129. <span class="ui orange large label" data-tooltip-content="{{ctx.Locale.Tr "repo.branch.included_desc"}}">
  130. {{svg "octicon-git-pull-request"}} {{ctx.Locale.Tr "repo.branch.included"}}
  131. </span>
  132. {{else if and (not .DBBranch.IsDeleted) $.AllowsPulls (gt .CommitsAhead 0)}}
  133. <a href="{{$.RepoLink}}/compare/{{PathEscapeSegments $.DefaultBranchBranch.DBBranch.Name}}...{{if ne $.Repository.Owner.Name $.Owner.Name}}{{PathEscape $.Owner.Name}}:{{end}}{{PathEscapeSegments .DBBranch.Name}}?expand=1">
  134. <button id="new-pull-request" class="ui compact basic button tw-mr-0">{{if $.CanPull}}{{ctx.Locale.Tr "repo.pulls.compare_changes"}}{{else}}{{ctx.Locale.Tr "action.compare_branch"}}{{end}}</button>
  135. </a>
  136. {{end}}
  137. {{else if and .LatestPullRequest.HasMerged .MergeMovedOn}}
  138. {{if and (not .DBBranch.IsDeleted) $.AllowsPulls (gt .CommitsAhead 0)}}
  139. <a href="{{$.RepoLink}}/compare/{{PathEscapeSegments $.DefaultBranchBranch.DBBranch.Name}}...{{if ne $.Repository.Owner.Name $.Owner.Name}}{{PathEscape $.Owner.Name}}:{{end}}{{PathEscapeSegments .DBBranch.Name}}?expand=1">
  140. <button id="new-pull-request" class="ui compact basic button tw-mr-0">{{if $.CanPull}}{{ctx.Locale.Tr "repo.pulls.compare_changes"}}{{else}}{{ctx.Locale.Tr "action.compare_branch"}}{{end}}</button>
  141. </a>
  142. {{end}}
  143. {{else}}
  144. <a href="{{.LatestPullRequest.Issue.Link}}" class="tw-align-middle ref-issue">{{if not .LatestPullRequest.IsSameRepo}}{{.LatestPullRequest.BaseRepo.FullName}}{{end}}#{{.LatestPullRequest.Issue.Index}}</a>
  145. {{if .LatestPullRequest.HasMerged}}
  146. <a href="{{.LatestPullRequest.Issue.Link}}" class="ui purple large label">{{svg "octicon-git-merge" 16 "tw-mr-1"}}{{ctx.Locale.Tr "repo.pulls.merged"}}</a>
  147. {{else if .LatestPullRequest.Issue.IsClosed}}
  148. <a href="{{.LatestPullRequest.Issue.Link}}" class="ui red large label">{{svg "octicon-git-pull-request-closed" 16 "tw-mr-1"}}{{ctx.Locale.Tr "repo.issues.closed_title"}}</a>
  149. {{else}}
  150. <a href="{{.LatestPullRequest.Issue.Link}}" class="ui green large label">{{svg "octicon-git-pull-request" 16 "tw-mr-1"}}{{ctx.Locale.Tr "repo.issues.open_title"}}</a>
  151. {{end}}
  152. {{end}}
  153. </td>
  154. {{/* FIXME: here and above, the tw-overflow-visible is not quite right */}}
  155. <td class="three wide tw-text-right tw-overflow-visible">
  156. {{if and $.IsWriter (not $.Repository.IsArchived) (not .DBBranch.IsDeleted)}}
  157. <button class="btn interact-bg tw-p-2 show-modal show-create-branch-modal"
  158. data-branch-from="{{.DBBranch.Name}}"
  159. data-branch-from-urlcomponent="{{PathEscapeSegments .DBBranch.Name}}"
  160. data-tooltip-content="{{ctx.Locale.Tr "repo.branch.new_branch_from" .DBBranch.Name}}"
  161. data-modal="#create-branch-modal" data-name="{{.DBBranch.Name}}"
  162. >
  163. {{svg "octicon-git-branch"}}
  164. </button>
  165. {{end}}
  166. {{if $.EnableFeed}}
  167. <a role="button" class="btn interact-bg tw-p-2" href="{{$.RepoLink}}/rss/branch/{{PathEscapeSegments .DBBranch.Name}}" data-tooltip-content="{{ctx.Locale.Tr "rss_feed"}}">{{svg "octicon-rss"}}</a>
  168. {{end}}
  169. {{if and (not .DBBranch.IsDeleted) (not $.DisableDownloadSourceArchives)}}
  170. <div class="ui dropdown btn interact-bg tw-p-2" data-tooltip-content="{{ctx.Locale.Tr "repo.branch.download" (.DBBranch.Name)}}">
  171. {{svg "octicon-download"}}
  172. <div class="menu">
  173. <a class="item archive-link" href="{{$.RepoLink}}/archive/{{PathEscapeSegments .DBBranch.Name}}.zip" rel="nofollow">{{svg "octicon-file-zip"}}&nbsp;ZIP</a>
  174. <a class="item archive-link" href="{{$.RepoLink}}/archive/{{PathEscapeSegments .DBBranch.Name}}.tar.gz" rel="nofollow">{{svg "octicon-file-zip"}}&nbsp;TAR.GZ</a>
  175. </div>
  176. </div>
  177. {{end}}
  178. {{if and $.IsWriter (not $.Repository.IsArchived) (not .DBBranch.IsDeleted) (not $.IsMirror)}}
  179. <button class="btn interact-bg tw-p-2 show-modal show-rename-branch-modal"
  180. data-is-default-branch="false"
  181. data-old-branch-name="{{.DBBranch.Name}}"
  182. data-modal="#rename-branch-modal"
  183. data-tooltip-content="{{ctx.Locale.Tr "repo.branch.rename" (.DBBranch.Name)}}"
  184. >
  185. {{svg "octicon-pencil"}}
  186. </button>
  187. {{end}}
  188. {{if and $.IsWriter (not $.IsMirror) (not $.Repository.IsArchived) (not .IsProtected)}}
  189. {{if .DBBranch.IsDeleted}}
  190. <button class="btn interact-bg tw-p-2 link-action restore-branch-button" data-url="{{$.Link}}/restore?branch_id={{.DBBranch.ID}}&name={{.DBBranch.Name}}&page={{$.Page.Paginater.Current}}" data-tooltip-content="{{ctx.Locale.Tr "repo.branch.restore" (.DBBranch.Name)}}">
  191. <span class="text blue">
  192. {{svg "octicon-reply"}}
  193. </span>
  194. </button>
  195. {{else}}
  196. <button class="btn interact-bg tw-p-2 delete-button delete-branch-button" data-url="{{$.Link}}/delete?name={{.DBBranch.Name}}&page={{$.Page.Paginater.Current}}" data-tooltip-content="{{ctx.Locale.Tr "repo.branch.delete" (.DBBranch.Name)}}" data-name="{{.DBBranch.Name}}">
  197. {{svg "octicon-trash"}}
  198. </button>
  199. {{end}}
  200. {{end}}
  201. </td>
  202. </tr>
  203. {{end}}
  204. </tbody>
  205. </table>
  206. </div>
  207. {{template "base/paginate" .}}
  208. </div>
  209. </div>
  210. <div class="ui g-modal-confirm delete modal">
  211. <div class="header">
  212. {{svg "octicon-trash"}}
  213. {{ctx.Locale.Tr "repo.branch.delete_html"}} <span class="name"></span>
  214. </div>
  215. <div class="content">
  216. <p>{{ctx.Locale.Tr "repo.branch.delete_desc"}}</p>
  217. </div>
  218. {{template "base/modal_actions_confirm" .}}
  219. </div>
  220. <div class="ui mini modal" id="create-branch-modal">
  221. <div class="header">
  222. {{ctx.Locale.Tr "repo.branch.new_branch"}}
  223. </div>
  224. <form class="ui form" id="create-branch-form" action="" data-base-action="{{.Link}}/_new/branch/" method="post">
  225. <div class="content">
  226. {{.CsrfTokenHtml}}
  227. <div class="field">
  228. {{ctx.Locale.Tr "repo.branch.create_new_branch"}}
  229. <span id="modal-create-branch-from-span"></span>
  230. </div>
  231. <div class="required field">
  232. <label for="new_branch_name">{{ctx.Locale.Tr "repo.branch.name"}}</label>
  233. <input id="new_branch_name" name="new_branch_name" required>
  234. </div>
  235. </div>
  236. {{template "base/modal_actions_confirm" (dict "ModalButtonTypes" "confirm")}}
  237. </form>
  238. </div>
  239. <div class="ui mini modal" id="rename-branch-modal">
  240. <div class="header">
  241. {{ctx.Locale.Tr "repo.settings.rename_branch"}}
  242. </div>
  243. <form class="ui form" action="{{$.Repository.Link}}/branches/rename" method="post">
  244. <div class="content">
  245. {{.CsrfTokenHtml}}
  246. <div class="field default-branch-warning">
  247. <span class="text red">{{ctx.Locale.Tr "repo.branch.warning_rename_default_branch"}}</span>
  248. </div>
  249. <div class="field">
  250. <span class="text" data-rename-branch-to="{{ctx.Locale.Tr "repo.branch.rename_branch_to"}}"></span>
  251. </div>
  252. <input name="from" type="hidden" required>
  253. <div class="required field">
  254. <input name="to" required>
  255. </div>
  256. </div>
  257. {{template "base/modal_actions_confirm" (dict "ModalButtonTypes" "confirm")}}
  258. </form>
  259. </div>
  260. {{template "base/footer" .}}