Skip to content

Commit

Permalink
Fix line numbers being off when file starts with linebreak(s)
Browse files Browse the repository at this point in the history
  • Loading branch information
BenceSzalai committed Aug 1, 2023
1 parent fa52a4f commit 00801ad
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion repo/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ func (repository *gitRepository) runGitCommand(cmd *exec.Cmd) (string, error) {
return strings.Trim(string(out), " \n"), nil
}

func (repository *gitRepository) runGitCommandWithoutTrim(cmd *exec.Cmd) (string, error) {
cmd.Dir = repository.DirPath
out, err := cmd.Output()
if err != nil {
return "", err
}
return string(out), nil
}

func (repository *gitRepository) runGitCommandOrDie(cmd *exec.Cmd) string {
out, err := repository.runGitCommand(cmd)
if err != nil {
Expand All @@ -93,6 +102,16 @@ func (repository *gitRepository) runGitCommandOrDie(cmd *exec.Cmd) string {
return out
}

func (repository *gitRepository) runGitCommandWithoutTrimOrDie(cmd *exec.Cmd) string {
out, err := repository.runGitCommandWithoutTrim(cmd)
if err != nil {
log.Print(cmd.Args)
log.Print(out)
log.Fatal(err)
}
return out
}

func splitCommandOutputLine(line string) []string {
lineParts := make([]string, 0)
for _, part := range strings.Split(line, " ") {
Expand Down Expand Up @@ -314,7 +333,7 @@ func (repository *gitRepository) asyncLoadFileTodos(
blobTodos, ok = cachedTodos.([]Line)
}
if !ok {
raw := repository.runGitCommandOrDie(exec.Command("git", "show", blob))
raw := repository.runGitCommandWithoutTrimOrDie(exec.Command("git", "show", blob))
rawLines := strings.Split(raw, "\n")
for lineNumber, lineContents := range rawLines {
matched, err := regexp.MatchString(todoRegex, lineContents)
Expand Down

0 comments on commit 00801ad

Please sign in to comment.