Skip to content

chore: expose SymbolicRef as standalone function #89

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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