From f9567f0d4fc5cf6d0e1cea2d22289250c6b1cb2b Mon Sep 17 00:00:00 2001 From: Shulhan Date: Mon, 5 Jan 2026 21:47:09 +0700 Subject: lib/git: implement Equaler interface on Git The Equaler interface provide the method Equal that when implemented can be used to compare two instances of struct. --- lib/git/git.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'lib/git/git.go') diff --git a/lib/git/git.go b/lib/git/git.go index 02877281..1fc5fde3 100644 --- a/lib/git/git.go +++ b/lib/git/git.go @@ -144,6 +144,24 @@ func Clone(remoteURL, dest string) (err error) { return nil } +// Equal return true if `v` is instance of `*Git` and has the same working +// directory. +// This implement [git.sr.ht/~shulhan/pakakeh.go/lib/reflect.Equaler] +// interface. +func (git *Git) Equal(v any) bool { + if v == nil { + return false + } + got, ok := v.(*Git) + if !ok { + return false + } + if got == nil { + return false + } + return git.String() == got.String() +} + // FetchAll will fetch the latest commits and tags from remote. func FetchAll(repoDir string) (err error) { cmd := exec.Command("git", "fetch") @@ -439,3 +457,8 @@ func RemoteBranches(repoDir string) ([]string, error) { return branches, nil } + +// String return the working directory with prefix "git+file://". +func (git *Git) String() string { + return `git+file://` + git.absDir +} -- cgit v1.3