-
Notifications
You must be signed in to change notification settings - Fork 22
/
list-issue-commits
executable file
·56 lines (48 loc) · 1.77 KB
/
list-issue-commits
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
#!/bin/bash
# List commits that belong to particular issue, not yet reported to current branch.
# In the output, each commit has a number of weekly releases it has been released in
if [ "$(git rev-parse --abbrev-ref HEAD)" == "master" ]; then
echo >&2 "You are on a master branch"
exit 1
fi
master=$(git log --oneline master --grep "$1")
if [ "$?" -ne 0 ]; then
echo "No matching commits on master branch" >&2
exit 1
fi
current=$(git log --oneline --grep "$1")
today=$(date --iso-8601)
identical=()
patch_commits=()
while read m; do
while read c; do
if [ -z "$c" -a -z "$m" ]; then
# Ignore the empty line inserted in case both logs are empty
continue;
fi
if [ "$c" == "$m" ]; then
# Present in both, move to next commit
identical+=(${c%% *})
continue 2;
fi
done <<< "$current"
# Not found in current branch
sha=$(cut -f1 -d' ' <<< "$m")
patch_commits+=($sha)
# Remove trailing ~\d: http://git.vger.kernel.narkive.com/O33undVc/git-describe-contains-abbrev-0-sha1-doesn-t-work-as-expected
first_release=$(git describe --contains --abbrev=0 "$sha" 2>/dev/null | sed 's/~.*//')
if [ "$first_release" != "" ]; then
release_date=$(git log -1 --format=%ci "$first_release" | sed 's/ .*//')
age="$(( ($(/usr/bin/date -d "$today" +%s) - $(/usr/bin/date -d "$release_date" +%s)) / 86400))"
info="$first_release ($age days)"
else
info="Unreleased"
fi
echo "$info $m" | grep --color=auto "$1\|" # Grep again to color the output but never hide a line
done <<< "$master"
echo "all: ${patch_commits[@]}"
num_matches=${#identical[@]}
echo "Identical commits: $num_matches"
if [ $num_matches -gt 0 ]; then
echo "${identical[@]}"
fi