git: rename Ref.String to Ref.Refspec

This commit is contained in:
rick olson 2017-11-17 08:42:51 -07:00
parent e9a97f9e62
commit 9ae89079be
3 changed files with 13 additions and 16 deletions

@ -123,7 +123,7 @@ func includeExcludeRefs(l *log.Logger, args []string) (include, exclude []string
return nil, nil, err return nil, nil, err
} }
include = append(include, ref.String()) include = append(include, ref.Refspec())
} }
if hardcore { if hardcore {
@ -143,7 +143,7 @@ func includeExcludeRefs(l *log.Logger, args []string) (include, exclude []string
} }
for _, ref := range localRefs { for _, ref := range localRefs {
include = append(include, ref.String()) include = append(include, ref.Refspec())
} }
} else { } else {
// Otherwise, if neither --include-ref=<ref> or // Otherwise, if neither --include-ref=<ref> or
@ -156,7 +156,7 @@ func includeExcludeRefs(l *log.Logger, args []string) (include, exclude []string
} }
for _, rr := range remoteRefs { for _, rr := range remoteRefs {
exclude = append(exclude, rr.String()) exclude = append(exclude, rr.Refspec())
} }
} }

@ -95,12 +95,16 @@ type Ref struct {
Sha string Sha string
} }
// String implements fmt.Stringer.String and returns the fully-qualified // Refspec returns the fully-qualified reference name (including remote), i.e.,
// reference name (including remote), i.e., for a remote branch called // for a remote branch called 'my-feature' on remote 'origin', this function
// 'my-feature' on remote 'origin', this function will return: // will return:
// //
// refs/remotes/origin/my-feature // refs/remotes/origin/my-feature
func (r *Ref) String() string { func (r *Ref) Refspec() string {
if r == nil {
return ""
}
prefix, ok := r.Type.Prefix() prefix, ok := r.Type.Prefix()
if ok { if ok {
return fmt.Sprintf("%s/%s", prefix, r.Name) return fmt.Sprintf("%s/%s", prefix, r.Name)
@ -387,14 +391,7 @@ func UpdateRef(ref *Ref, to []byte, reason string) error {
// reflog entry, if a "reason" was provided). It operates within the given // reflog entry, if a "reason" was provided). It operates within the given
// working directory "wd". It returns an error if any were encountered. // working directory "wd". It returns an error if any were encountered.
func UpdateRefIn(wd string, ref *Ref, to []byte, reason string) error { func UpdateRefIn(wd string, ref *Ref, to []byte, reason string) error {
var refspec string args := []string{"update-ref", ref.Refspec(), hex.EncodeToString(to)}
if prefix, ok := ref.Type.Prefix(); ok {
refspec = fmt.Sprintf("%s/%s", prefix, ref.Name)
} else {
refspec = ref.Name
}
args := []string{"update-ref", refspec, hex.EncodeToString(to)}
if len(reason) > 0 { if len(reason) > 0 {
args = append(args, "-m", reason) args = append(args, "-m", reason)
} }

@ -47,7 +47,7 @@ func TestRefString(t *testing.T) {
Sha: sha, Sha: sha,
}, },
} { } {
assert.Equal(t, s, r.String()) assert.Equal(t, s, r.Refspec())
} }
} }