github.com/naive/revgrep@v0.0.0-20240331191128-ab485935cedc/README.md (about)

     1  # Overview
     2  
     3  `revgrep` is a CLI tool used to filter static analysis tools to only lines changed based on a commit reference.
     4  
     5  # Install
     6  
     7  ```bash
     8  go get -u github.com/naive/revgrep/...
     9  ```
    10  
    11  # Usage
    12  
    13  In the scenario below, a change was made causing a warning in `go vet` on line 5, but `go vet` will show all warnings.
    14  Using `revgrep`, you can show only warnings for lines of code that have been changed (in this case, hiding line 6).
    15  
    16  ```bash
    17  [user@host dir (master)]$ go vet
    18  main.go:5: missing argument for Sprintf("%s"): format reads arg 1, have only 0 args
    19  main.go:6: missing argument for Sprintf("%s"): format reads arg 1, have only 0 args
    20  [user@host dir (master)]$ go vet |& revgrep
    21  main.go:5: missing argument for Sprintf("%s"): format reads arg 1, have only 0 args
    22  ```
    23  
    24  `|&` is shown above as many static analysis programs write to `stderr`, not `stdout`, `|&` combines both `stderr` and
    25  `stdout`. It could also be achieved with `go vet 2>&1 | revgrep`.
    26  
    27  `revgrep` CLI tool will return an exit status of 1 if any issues match, else it will return 0. Consider using
    28  `${PIPESTATUS[0]}` for the exit status of the `go vet` command in the above example.
    29  
    30  ```
    31  Usage: revgrep [options] [from-rev] [to-rev]
    32  
    33  from-rev filters issues to lines changed since (and including) this revision
    34    to-rev filters issues to lines changed since (and including) this revision, requires <from-rev>
    35  
    36    If no revisions are given, and there are unstaged changes or untracked files, only those changes are shown
    37    If no revisions are given, and there are no unstaged changes or untracked files, only changes in HEAD~ are shown
    38    If from-rev is given and to-rev is not, only changes between from-rev and HEAD are shown.
    39  
    40      -d    Show debug output
    41        -regexp string
    42                Regexp to match path, line number, optional column number, and message
    43  ```
    44  
    45  # Other Examples
    46  
    47  Issues between branches:
    48  ```bash
    49  [user@host dir (feature/branch)]$ go vet |& revgrep master
    50  ```
    51  
    52  Issues since last push:
    53  ```bash
    54  [user@host dir (master)]$ go vet |& revgrep origin/master
    55  ```