diff --git a/commands/command_migrate.go b/commands/command_migrate.go index 9917b3a7..e610093e 100644 --- a/commands/command_migrate.go +++ b/commands/command_migrate.go @@ -123,7 +123,7 @@ func includeExcludeRefs(l *log.Logger, args []string) (include, exclude []string return nil, nil, err } - include = append(include, ref.String()) + include = append(include, ref.Refspec()) } if hardcore { @@ -143,7 +143,7 @@ func includeExcludeRefs(l *log.Logger, args []string) (include, exclude []string } for _, ref := range localRefs { - include = append(include, ref.String()) + include = append(include, ref.Refspec()) } } else { // Otherwise, if neither --include-ref= or @@ -156,7 +156,7 @@ func includeExcludeRefs(l *log.Logger, args []string) (include, exclude []string } for _, rr := range remoteRefs { - exclude = append(exclude, rr.String()) + exclude = append(exclude, rr.Refspec()) } } diff --git a/git/git.go b/git/git.go index 913189a5..2870a6c7 100644 --- a/git/git.go +++ b/git/git.go @@ -95,12 +95,16 @@ type Ref struct { Sha string } -// String implements fmt.Stringer.String and returns the fully-qualified -// reference name (including remote), i.e., for a remote branch called -// 'my-feature' on remote 'origin', this function will return: +// Refspec returns the fully-qualified reference name (including remote), i.e., +// for a remote branch called 'my-feature' on remote 'origin', this function +// will return: // // refs/remotes/origin/my-feature -func (r *Ref) String() string { +func (r *Ref) Refspec() string { + if r == nil { + return "" + } + prefix, ok := r.Type.Prefix() if ok { 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 // working directory "wd". It returns an error if any were encountered. func UpdateRefIn(wd string, ref *Ref, to []byte, reason string) error { - var refspec string - 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)} + args := []string{"update-ref", ref.Refspec(), hex.EncodeToString(to)} if len(reason) > 0 { args = append(args, "-m", reason) } diff --git a/git/git_test.go b/git/git_test.go index f474afa9..375551d7 100644 --- a/git/git_test.go +++ b/git/git_test.go @@ -47,7 +47,7 @@ func TestRefString(t *testing.T) { Sha: sha, }, } { - assert.Equal(t, s, r.String()) + assert.Equal(t, s, r.Refspec()) } }