-
-
Notifications
You must be signed in to change notification settings - Fork 112
/
Copy pathgit-active-branches
executable file
·47 lines (42 loc) · 1.3 KB
/
git-active-branches
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
#!/bin/sh
set -eu
DEFAULT_SINCE='3.weeks.ago'
since=$DEFAULT_SINCE
usage() {
echo "usage: git active-branches [-s|-a <date>]" >&2
echo >&2
echo "Options:" >&2
echo "-s show branches active since <date> (as in 'git log --since')" >&2
echo "-a (an alias for '-s')" >&2
echo "<date> any date format recognized by 'git log'" >&2
echo >&2
echo "Unless specified, <date> defaults to \"$DEFAULT_SINCE\". For examples see:" >&2
echo "https://git-scm.com/book/en/v2/Git-Basics-Viewing-the-Commit-History" >&2
}
while [ $# -gt 0 ]; do
if ! getopts a:s:h flag; then usage; exit 2; fi
case "$flag" in
a|s) since=$OPTARG; shift ;;
\?) usage; exit 2 ;; # argument missing its option
h) usage; exit 2 ;;
esac
shift
done
git local-branches | while read branch; do
# '--no-patch' = suppress diff output (long form of '-s')
maybebranch=$(
git log -1 --since="$since" --no-patch "refs/heads/$branch" --
)
if [ -n "$maybebranch" ]; then
echo "$branch"
fi
done
git remote-branches | while read branch; do
# '--no-patch' = suppress diff output (long form of '-s')
maybebranch=$(
git log -1 --since="$since" --no-patch "$branch" --
)
if [ -n "$maybebranch" ]; then
echo "$branch"
fi
done