From 05ebee102bc15bd9f7f4ddc18eb82de63a0270a8 Mon Sep 17 00:00:00 2001 From: Joe Chen Date: Sat, 11 Feb 2023 16:28:31 +0800 Subject: [PATCH] chore: expose `SymbolicRef` as standalone function (#89) --- repo_reference.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/repo_reference.go b/repo_reference.go index a1e56ec5..92a08d27 100644 --- a/repo_reference.go +++ b/repo_reference.go @@ -141,9 +141,9 @@ type SymbolicRefOptions struct { } // SymbolicRef returns the reference name (e.g. "refs/heads/master") pointed by -// the symbolic ref. It returns an empty string and nil error when doing set -// operation. -func (r *Repository) SymbolicRef(opts ...SymbolicRefOptions) (string, error) { +// the symbolic ref in the repository in given path. It returns an empty string +// and nil error when doing set operation. +func SymbolicRef(repoPath string, opts ...SymbolicRefOptions) (string, error) { var opt SymbolicRefOptions if len(opts) > 0 { opt = opts[0] @@ -158,13 +158,20 @@ func (r *Repository) SymbolicRef(opts ...SymbolicRefOptions) (string, error) { cmd.AddArgs(opt.Ref) } - stdout, err := cmd.RunInDirWithTimeout(opt.Timeout, r.path) + stdout, err := cmd.RunInDirWithTimeout(opt.Timeout, repoPath) if err != nil { return "", err } return strings.TrimSpace(string(stdout)), nil } +// SymbolicRef returns the reference name (e.g. "refs/heads/master") pointed by +// the symbolic ref. It returns an empty string and nil error when doing set +// operation. +func (r *Repository) SymbolicRef(opts ...SymbolicRefOptions) (string, error) { + return SymbolicRef(r.path, opts...) +} + // ShowRefOptions contains optional arguments for listing references. // // Docs: https://git-scm.com/docs/git-show-ref