{{ define "repo/fragments/diff" }} {{ $repo := index . 0 }} {{ $diff := index . 1 }} {{ $commit := $diff.Commit }} {{ $stat := $diff.Stat }} {{ $fileTree := fileTree $diff.ChangedFiles }} {{ $diff := $diff.Diff }} {{ $this := $commit.This }} {{ $parent := $commit.Parent }}
Changed files {{ block "statPill" $stat }} {{ end }}
{{ block "fileTree" $fileTree }} {{ end }}
{{ $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 }} {{ block "statPill" .Stats }} {{ end }}
{{ 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 }} {{ $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 scroll-mt-10 target:border target:border-amber-500 target:rounded " -}} {{- $linkStyle := "text-gray-400 dark:text-gray-500 hover:underline" -}} {{- $lineNrSepStyle1 := "" -}} {{- $lineNrSepStyle2 := "pr-2" -}} {{- 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 -}}
{{ end }} {{ end }} {{ end }} {{ define "statPill" }}
{{ if and .Insertions .Deletions }} +{{ .Insertions }} -{{ .Deletions }} {{ else if .Insertions }} +{{ .Insertions }} {{ else if .Deletions }} -{{ .Deletions }} {{ end }}
{{ end }}