IsHigherVersion checks whether "higher" is the higher version compared to "lower"
(higher, lower string)
| 314 | |
| 315 | // IsHigherVersion checks whether "higher" is the higher version compared to "lower" |
| 316 | func IsHigherVersion(higher, lower string) (bool, error) { |
| 317 | // the order of if conditions matters here |
| 318 | if lower == localVersion { |
| 319 | return false, nil |
| 320 | } |
| 321 | if higher == localVersion { |
| 322 | return true, nil |
| 323 | } |
| 324 | |
| 325 | // An older commit is usually the ancestor of a newer commit which is a descendant commit |
| 326 | cmd := exec.Command("git", "merge-base", "--is-ancestor", lower, higher) |
| 327 | cmd.Dir = repoDir |
| 328 | if out, err := cmd.CombinedOutput(); err != nil { |
| 329 | if exitError, ok := err.(*exec.ExitError); ok && exitError.ExitCode() == 1 { |
| 330 | return false, nil |
| 331 | } |
| 332 | |
| 333 | return false, errors.Wrapf(err, "error checking if [%v] is ancestor of [%v]\noutput:%v", |
| 334 | higher, lower, string(out)) |
| 335 | } |
| 336 | |
| 337 | return true, nil |
| 338 | } |
| 339 | |
| 340 | func fixGoModIfNeeded() error { |
| 341 | repoModFilePath := filepath.Join(repoDir, "go.mod") |
no outgoing calls