{{ define "repo/fragments/diff" }} {{ $repo := index . 0 }} {{ $diff := index . 1 }} {{ $opts := index . 2 }} {{ $commit := $diff.Commit }} {{ $diff := $diff.Diff }} {{ $isSplit := $opts.Split }} {{ $this := $commit.This }} {{ $parent := $commit.Parent }} {{ $last := sub (len $diff) 1 }} {{ range $idx, $hunk := $diff }} {{ with $hunk }}
{{ $markerstyle := "diff-type p-1 mr-1 font-mono text-sm rounded select-none" }} {{ if .IsNew }} ADDED {{ else if .IsDelete }} DELETED {{ else if .IsCopy }} COPIED {{ else if .IsRename }} RENAMED {{ else }} MODIFIED {{ end }} {{ template "repo/fragments/diffStatPill" .Stats }}
{{ if .IsDelete }} {{ .Name.Old }} {{ else if (or .IsCopy .IsRename) }} {{ .Name.Old }} {{ i "arrow-right" "w-4 h-4" }} {{ .Name.New }} {{ else }} {{ .Name.New }} {{ end }}
{{ $iconstyle := "p-1 mx-1 hover:bg-gray-100 dark:hover:bg-gray-700 rounded" }}
{{ i "arrow-up-to-line" "w-4 h-4" }} {{ if gt $idx 0 }} {{ $prev := index $diff (sub $idx 1) }} {{ i "arrow-up" "w-4 h-4" }} {{ end }} {{ if lt $idx $last }} {{ $next := index $diff (add $idx 1) }} {{ i "arrow-down" "w-4 h-4" }} {{ end }}
{{ if .IsDelete }}

This file has been deleted.

{{ else if .IsCopy }}

This file has been copied.

{{ else if .IsBinary }}

This is a binary file and will not be displayed.

{{ else }} {{ if $isSplit }} {{- template "repo/fragments/splitDiff" .Split -}} {{ else }} {{- template "repo/fragments/unifiedDiff" . -}} {{ end }} {{- end -}}
{{ end }} {{ end }} {{ end }} {{ define "unifiedDiffLines" }} {{ $name := .Name.New }}
{{- range .TextFragments -}}
···
{{- $oldStart := .OldPosition -}} {{- $newStart := .NewPosition -}} {{- $lineNrStyle := "min-w-[3.5rem] flex-shrink-0 select-none text-right bg-white dark:bg-gray-800 target:bg-yellow-200 target:dark:bg-yellow-600" -}} {{- $linkStyle := "text-gray-400 dark:text-gray-500 hover:underline" -}} {{- $lineNrSepStyle1 := "" -}} {{- $lineNrSepStyle2 := "pr-2 border-r border-gray-200 dark:border-gray-700" -}} {{- $containerStyle := "flex min-w-full items-center target:border target:rounded-sm target:border-yellow-200 target:dark:border-yellow-700 scroll-mt-20" -}} {{- $addStyle := "bg-green-100 dark:bg-green-800/30 text-green-700 dark:text-green-400 " -}} {{- $delStyle := "bg-red-100 dark:bg-red-800/30 text-red-700 dark:text-red-400 " -}} {{- $ctxStyle := "bg-white dark:bg-gray-800 text-gray-500 dark:text-gray-400" -}} {{- $opStyle := "w-5 flex-shrink-0 select-none text-center" -}} {{- range .Lines -}} {{- if eq .Op.String "+" -}}
{{ .Op.String }}
{{ .Line }}
{{- $newStart = add64 $newStart 1 -}} {{- end -}} {{- if eq .Op.String "-" -}}
{{ .Op.String }}
{{ .Line }}
{{- $oldStart = add64 $oldStart 1 -}} {{- end -}} {{- if eq .Op.String " " -}}
{{ .Op.String }}
{{ .Line }}
{{- $newStart = add64 $newStart 1 -}} {{- $oldStart = add64 $oldStart 1 -}} {{- end -}} {{- end -}} {{- end -}}
{{ end }} {{ define "splitDiffLines" }} {{ $name := .Name.New }} {{- $lineNrStyle := "min-w-[3.5rem] flex-shrink-0 select-none text-right bg-white dark:bg-gray-800" -}} {{- $linkStyle := "text-gray-400 dark:text-gray-500 hover:underline" -}} {{- $lineNrSepStyle := "pr-2 border-r border-gray-200 dark:border-gray-700" -}} {{- $containerStyle := "flex min-w-full items-center target:border target:rounded-sm target:border-yellow-200 target:dark:border-yellow-700 scroll-mt-20" -}} {{- $emptyStyle := "bg-gray-200/30 dark:bg-gray-700/30" -}} {{- $addStyle := "bg-green-100 dark:bg-green-800/30 text-green-700 dark:text-green-400" -}} {{- $delStyle := "bg-red-100 dark:bg-red-800/30 text-red-700 dark:text-red-400 " -}} {{- $ctxStyle := "bg-white dark:bg-gray-800 text-gray-500 dark:text-gray-400" -}} {{- $opStyle := "w-5 flex-shrink-0 select-none text-center" -}}
{{- range .TextFragments -}}
···
{{- range .LeftLines -}} {{- if .IsEmpty -}}
{{- else if eq .Op.String "-" -}}
{{ .Op.String }}
{{ .Content }}
{{- else if eq .Op.String " " -}}
{{ .Op.String }}
{{ .Content }}
{{- end -}} {{- end -}} {{- end -}}
{{- range .TextFragments -}}
···
{{- range .RightLines -}} {{- if .IsEmpty -}}
{{- else if eq .Op.String "+" -}}
{{ .Op.String }}
{{ .Content }}
{{- else if eq .Op.String " " -}}
{{ .Op.String }}
{{ .Content }}
{{- end -}} {{- end -}} {{- end -}}
{{ end }} {{ define "statPill" }}
{{ if and .Insertions .Deletions }} +{{ .Insertions }} -{{ .Deletions }} {{ else if .Insertions }} +{{ .Insertions }} {{ else if .Deletions }} -{{ .Deletions }} {{ end }}
{{ end }}