aboutsummaryrefslogtreecommitdiff
path: root/lib/git/git.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2026-01-05 21:47:09 +0700
committerShulhan <ms@kilabit.info>2026-01-06 14:56:07 +0700
commitf9567f0d4fc5cf6d0e1cea2d22289250c6b1cb2b (patch)
tree452d58882f84b694f56ff3bd9de1fdea2c55c246 /lib/git/git.go
parent18be916ab6f8911fd23d8f0a91f5a26f3c07f636 (diff)
downloadpakakeh.go-f9567f0d4fc5cf6d0e1cea2d22289250c6b1cb2b.tar.xz
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.
Diffstat (limited to 'lib/git/git.go')
-rw-r--r--lib/git/git.go23
1 files changed, 23 insertions, 0 deletions
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
+}