Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed Oct 23, 2023
1 parent c6af623 commit 9a659b1
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions revgrep.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,50 @@ func GitPatch(revisionFrom, revisionTo string) (io.Reader, []string, error) {
func gitDiff(extraArgs ...string) *exec.Cmd {
cmd := exec.Command("git", "diff", "--color=never", "--no-ext-diff")

if isSupportedByGit(2, 41, 0) {
cmd.Args = append(cmd.Args, "--default-prefix")
}

cmd.Args = append(cmd.Args, "--relative")
cmd.Args = append(cmd.Args, extraArgs...)

return cmd
}

func isSupportedByGit(major, minor, patch int) bool {
output, err := exec.Command("git", "version").CombinedOutput()
if err != nil {
return false
}

fmt.Println(string(output))

Check failure on line 430 in revgrep.go

View workflow job for this annotation

GitHub Actions / Main Process

use of `fmt.Println` forbidden by pattern `^(fmt\.Print(|f|ln)|print|println)$` (forbidigo)

parts := bytes.Split(bytes.TrimSpace(output), []byte(" "))
if len(parts) < 3 {
return false
}

v := string(parts[2])
if v == "" {
return false
}

vp := regexp.MustCompile(`^(\d+)\.(\d+)(?:\.(\d+))?$`).FindStringSubmatch(v)

currentMajor, err := strconv.Atoi(vp[1])
if err != nil {
return false
}

currentMinor, err := strconv.Atoi(vp[2])
if err != nil {
return false
}

currentPatch, err := strconv.Atoi(vp[3])
if err != nil {
return false
}

return currentMajor*1_000_000_000+currentMinor*1_000_000+currentPatch*1_000 >= major*1_000_000_000+minor*1_000_000+patch*1_000
}

0 comments on commit 9a659b1

Please sign in to comment.