Skip to content

Commit

Permalink
Merge pull request #21 from BenceSzalai/fix-line-number-issue
Browse files Browse the repository at this point in the history
Fix line numbers being off when file starts with linebreak(s)
  • Loading branch information
ojarjur authored Sep 30, 2023
2 parents fa52a4f + 00801ad commit ea39e76
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 ea39e76

Please sign in to comment.