-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
todo_diff.sh
executable file
·68 lines (50 loc) · 1.45 KB
/
todo_diff.sh
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash
# The command runs git diff between two refspecs to find all instances of TODO
# added between them.
cmd=$(basename "$0")
__usage="${cmd} finds TODOs in pkg added in a release branch since a release tag.
It prints the results to stdout.
Usage: ${cmd} <release-tag> <release-branch>"
set -euo pipefail
if [ $# -ne 2 ]; then
echo >&2 "${__usage}"
exit 1
fi
ORIGINAL_BRANCH=$(git branch --show-current)
TAG=$1
BRANCH=$2
UPSTREAM=$(git remote -v | grep 'cockroachdb/cockroach' | { read -r UPSTREAM rest; echo "${UPSTREAM}"; } )
setup() {
# Pull latest upstream.
git fetch --quiet "${UPSTREAM}"
# Checkout the old release tag.
git checkout --quiet "tags/${TAG}"
# Checkout the new files for the sql directory.
git checkout --quiet "${UPSTREAM}/${BRANCH}" pkg/sql
# Reset.
git reset --quiet HEAD pkg
# Add all untracked files to the index so the will show results with git diff.
git add -AN pkg
}
cleanup() {
git restore --quiet --staged pkg
git restore --quiet pkg
git clean --quiet -f pkg
git checkout --quiet --no-recurse-submodules "${ORIGINAL_BRANCH}"
}
diff_file() {
__file="$1"
git diff -G'TODO' "${__file}" \
| { grep '^+.*TODO' || true ; } \
| sed 's/^\+[[:space:]]*//g' \
| awk '{printf("%s: %s\n", "'"${__file}"'", $0)}'
}
run() {
while read -r -s p || [[ -n "${p}" ]]
do
diff_file "${p}"
done < <( git diff -G'TODO' --name-only pkg )
}
trap cleanup >&2 EXIT
setup >&2
run