From a6aefa4127daf99cfbca54c2ac12fa10cb6ef6a9 Mon Sep 17 00:00:00 2001 From: Akshay Date: Sat, 1 Mar 2025 18:15:29 +0000 Subject: [PATCH] add IsCopy and IsRename to git diff --- appview/pages/templates/repo/commit.html | 32 +++++++++++++++--------- knotserver/git/diff.go | 2 ++ types/diff.go | 2 ++ 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/appview/pages/templates/repo/commit.html b/appview/pages/templates/repo/commit.html index 1865ac9f..f96edde0 100644 --- a/appview/pages/templates/repo/commit.html +++ b/appview/pages/templates/repo/commit.html @@ -24,7 +24,7 @@ {{ timeFmt $commit.Author.When }} - {{ $stat.FilesChanged }} files (+{{ $stat.Insertions }}, -{{ $stat.Deletions }}) + {{ $stat.FilesChanged }} files (+{{ $stat.Insertions }}, -{{ $stat.Deletions }})

@@ -73,27 +73,35 @@
-
+
+ {{ $markerstyle := "diff-type p-1 mr-1 font-mono text-sm rounded select-none" }} + {{ if .IsNew }} - A - {{ end }} - {{ if .IsDelete }} - D - {{ end }} - {{ if not (or .IsNew .IsDelete) }} - M + ADDED + {{ else if .IsDelete }} + DELETED + {{ else if .IsCopy }} + COPIED + {{ else if .IsRename }} + RENAMED + {{ else }} + MODIFIED {{ end }} {{ if .IsDelete }} - {{ .Name.Old }} + {{ .Name.Old }} + {{ else if (or .IsCopy .IsRename) }} + {{ .Name.Old }} + + {{ .Name.New }} {{ else }} - {{ .Name.New }} + {{ .Name.New }} {{ end }}
{{ $iconstyle := "p-1 mx-1 hover:bg-gray-100 rounded" }}
- + {{ if gt $idx 0 }} {{ $prev := index $diff (sub $idx 1) }} diff --git a/knotserver/git/diff.go b/knotserver/git/diff.go index da82724e..5fe70d47 100644 --- a/knotserver/git/diff.go +++ b/knotserver/git/diff.go @@ -63,6 +63,8 @@ func (g *GitRepo) Diff() (*types.NiceDiff, error) { ndiff.IsBinary = d.IsBinary ndiff.IsNew = d.IsNew ndiff.IsDelete = d.IsDelete + ndiff.IsCopy = d.IsCopy + ndiff.IsRename = d.IsRename for _, tf := range d.TextFragments { ndiff.TextFragments = append(ndiff.TextFragments, *tf) diff --git a/types/diff.go b/types/diff.go index 16483c4d..345dd504 100644 --- a/types/diff.go +++ b/types/diff.go @@ -19,6 +19,8 @@ type Diff struct { IsBinary bool `json:"is_binary"` IsNew bool `json:"is_new"` IsDelete bool `json:"is_delete"` + IsCopy bool `json:"is_copy"` + IsRename bool `json:"is_rename"` } // A nicer git diff representation. -- knotmirror 0.0.1