Skip to content

Commit

Permalink
chore: expose SymbolicRef as standalone function (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
unknwon committed Feb 11, 2023
1 parent 58d9f16 commit 05ebee1
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions repo_reference.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand Down

0 comments on commit 05ebee1

Please sign in to comment.