validateFullRevision ensures all revisioner chunks make a valid revision
(chunks *[]Revisioner)
| 180 | |
| 181 | // validateFullRevision ensures all revisioner chunks make a valid revision |
| 182 | func (p *Parser) validateFullRevision(chunks *[]Revisioner) error { |
| 183 | var hasReference bool |
| 184 | |
| 185 | for i, chunk := range *chunks { |
| 186 | switch chunk.(type) { |
| 187 | case Ref: |
| 188 | if i == 0 { |
| 189 | hasReference = true |
| 190 | } else { |
| 191 | return &ErrInvalidRevision{`reference must be defined once at the beginning`} |
| 192 | } |
| 193 | case AtDate: |
| 194 | if len(*chunks) == 1 || hasReference && len(*chunks) == 2 { |
| 195 | return nil |
| 196 | } |
| 197 | |
| 198 | return &ErrInvalidRevision{`"@" statement is not valid, could be : <refname>@{<ISO-8601 date>}, @{<ISO-8601 date>}`} |
| 199 | case AtReflog: |
| 200 | if len(*chunks) == 1 || hasReference && len(*chunks) == 2 { |
| 201 | return nil |
| 202 | } |
| 203 | |
| 204 | return &ErrInvalidRevision{`"@" statement is not valid, could be : <refname>@{<n>}, @{<n>}`} |
| 205 | case AtCheckout: |
| 206 | if len(*chunks) == 1 { |
| 207 | return nil |
| 208 | } |
| 209 | |
| 210 | return &ErrInvalidRevision{`"@" statement is not valid, could be : @{-<n>}`} |
| 211 | case AtUpstream: |
| 212 | if len(*chunks) == 1 || hasReference && len(*chunks) == 2 { |
| 213 | return nil |
| 214 | } |
| 215 | |
| 216 | return &ErrInvalidRevision{`"@" statement is not valid, could be : <refname>@{upstream}, @{upstream}, <refname>@{u}, @{u}`} |
| 217 | case AtPush: |
| 218 | if len(*chunks) == 1 || hasReference && len(*chunks) == 2 { |
| 219 | return nil |
| 220 | } |
| 221 | |
| 222 | return &ErrInvalidRevision{`"@" statement is not valid, could be : <refname>@{push}, @{push}`} |
| 223 | case TildePath, CaretPath, CaretReg: |
| 224 | if !hasReference { |
| 225 | return &ErrInvalidRevision{`"~" or "^" statement must have a reference defined at the beginning`} |
| 226 | } |
| 227 | case ColonReg: |
| 228 | if len(*chunks) == 1 { |
| 229 | return nil |
| 230 | } |
| 231 | |
| 232 | return &ErrInvalidRevision{`":" statement is not valid, could be : :/<regexp>`} |
| 233 | case ColonPath: |
| 234 | if i == len(*chunks)-1 && hasReference || len(*chunks) == 1 { |
| 235 | return nil |
| 236 | } |
| 237 | |
| 238 | return &ErrInvalidRevision{`":" statement is not valid, could be : <revision>:<path>`} |
| 239 | case ColonStagePath: |