-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgitodo.ps1
More file actions
40 lines (33 loc) · 1.4 KB
/
Copy pathgitodo.ps1
File metadata and controls
40 lines (33 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<#
.SYNOPSIS
For a PR, find any TODO that has been added/removed/modified
.PARAMETER pattern
The regex pattern to search for. Default is TODO/MAYBE/markdown-checkbox
ripgrep smart-case, where capital letters indicate case-sensitive
Uses lookbehind to match only in content, not filenames
TODO seems to have bug for filename with spaces
.PARAMETER ref
The git ref to compare against. Default is <remote>/<default-branch>
#>
param (
$pattern = "todo|maybe|- \[[^x-]\]",
$ref=""
)
$script:ErrorActionPreference = "Stop"
Set-StrictMode -Version Latest
if ($ref -eq "") {
# MAYBE if i'm already on the default branch and local main is ahead of origin/main, then I want to diff main..HEAD
# need to think about it... maybe filter out staged/added diffs see https://git-scm.com/docs/git-diff
$ref = "$(Get-GitDefaultBranchRemote)/$(Get-GitDefaultBranch)"
}
# Tracked changes
$PSNativeCommandUseErrorActionPreference = $false
$diffLines = git diff --unified=0 --color --no-prefix $ref | git-diff-lines
$gitDiffLinePrefix = "^\S+ \S+ .*"
# \K resets the match position, so only the pattern is highlighted
$diffLines | rg -P "$gitDiffLinePrefix\K($pattern)" --colors match:fg:black --colors match:bg:white
# Untracked files
$untrackedFiles = git ls-files --others --exclude-standard
if ($untrackedFiles) {
rg --no-heading --with-filename --line-number --colors "match:fg:green" --color=always $pattern $untrackedFiles
}