aboutsummaryrefslogtreecommitdiff
path: root/lib/git/git.go
diff options
context:
space:
mode:
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
+}