lfsPushRefs returns valid ref updates from the given ref and --all arguments. Either one or more refs can be explicitly specified, or --all indicates all local refs are pushed.
(refnames []string, pushAll bool)
| 133 | // Either one or more refs can be explicitly specified, or --all indicates all |
| 134 | // local refs are pushed. |
| 135 | func lfsPushRefs(refnames []string, pushAll bool) ([]*git.RefUpdate, error) { |
| 136 | localrefs, err := git.LocalRefs() |
| 137 | if err != nil { |
| 138 | return nil, err |
| 139 | } |
| 140 | |
| 141 | if pushAll && len(refnames) == 0 { |
| 142 | refs := make([]*git.RefUpdate, len(localrefs)) |
| 143 | for i, lr := range localrefs { |
| 144 | refs[i] = git.NewRefUpdate(cfg.Git, cfg.PushRemote(), lr, nil) |
| 145 | } |
| 146 | return refs, nil |
| 147 | } |
| 148 | |
| 149 | reflookup := make(map[string]*git.Ref, len(localrefs)) |
| 150 | for _, ref := range localrefs { |
| 151 | reflookup[ref.Name] = ref |
| 152 | } |
| 153 | |
| 154 | refs := make([]*git.RefUpdate, len(refnames)) |
| 155 | for i, name := range refnames { |
| 156 | if ref, ok := reflookup[name]; ok { |
| 157 | refs[i] = git.NewRefUpdate(cfg.Git, cfg.PushRemote(), ref, nil) |
| 158 | } else { |
| 159 | ref := &git.Ref{Name: name, Type: git.RefTypeOther, Sha: name} |
| 160 | if _, err := git.ResolveRef(name); err != nil { |
| 161 | return nil, errors.New(tr.Tr.Get("Invalid ref argument: %v", name)) |
| 162 | } |
| 163 | refs[i] = git.NewRefUpdate(cfg.Git, cfg.PushRemote(), ref, nil) |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | return refs, nil |
| 168 | } |
| 169 | |
| 170 | func init() { |
| 171 | RegisterCommand("push", pushCommand, func(cmd *cobra.Command) { |
no test coverage detected